From cd56e3ec6f7201f53220f1cdac68d493590e577b Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sat, 19 Nov 2022 20:25:03 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=B8=AA=E4=BA=BA=E7=BE=A4=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=BD=AC=E8=AE=A9=E7=BE=A4=E4=B8=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/DialogController.php | 46 ++++- app/Models/WebSocketDialog.php | 28 +-- .../manage/components/DialogGroupInfo.vue | 30 +-- .../pages/manage/components/DialogWrapper.vue | 173 ++++++++++++++++-- .../sass/pages/components/dialog-wrapper.scss | 24 ++- 5 files changed, 237 insertions(+), 64 deletions(-) diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index 1408304cc..dbabc024d 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -1314,7 +1314,7 @@ class DialogController extends AbstractController * @apiName group__adduser * * @apiParam {Number} dialog_id 会话ID - * @apiParam {Array} userids 移出的群成员,格式: [userid1, userid2, userid3] + * @apiParam {Array} [userids] 移出的群成员,格式: [userid1, userid2, userid3] * - 留空表示自己退出 * - 有值表示移出,仅限群主操作 * @@ -1347,6 +1347,50 @@ class DialogController extends AbstractController return Base::retSuccess($type === 'remove' ? '移出成功' : '退出成功'); } + /** + * @api {get} api/dialog/group/transfer 31. 转让群组 + * + * @apiDescription 需要token身份 + * - 只有群主且是个人类型群可以解散 + * @apiVersion 1.0.0 + * @apiGroup dialog + * @apiName group__transfer + * + * @apiParam {Number} dialog_id 会话ID + * @apiParam {Number} userid 新的群主 + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + */ + public function group__transfer() + { + $user = User::auth(); + // + $dialog_id = intval(Request::input('dialog_id')); + $userid = intval(Request::input('userid')); + // + if ($userid === $user->userid) { + return Base::retError('你已经是群主'); + } + if (!User::whereUserid($userid)->exists()) { + return Base::retError('请选择有效的新群主'); + } + // + $dialog = WebSocketDialog::checkDialog($dialog_id, true); + // + $dialog->checkGroup('user'); + $dialog->owner_id = $userid; + if ($dialog->save()) { + $dialog->joinGroup($userid, 0); + $dialog->pushMsg("groupUpdate", [ + 'id' => $dialog->id, + 'owner_id' => $dialog->owner_id, + ]); + } + return Base::retSuccess('转让成功'); + } + /** * @api {get} api/dialog/group/disband 31. 解散群组 * diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index 2de6044dc..364c2340f 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -142,26 +142,32 @@ class WebSocketDialog extends AbstractModel /** * 加入聊天室 - * @param int|array $userid 加入的会员ID或会员ID组 - * @param int $inviter 邀请人 - * @param bool $important 重要人员 + * @param int|array $userid 加入的会员ID或会员ID组 + * @param int $inviter 邀请人 + * @param bool|null $important 重要人员(null不修改、bool修改) * @return bool */ - public function joinGroup($userid, $inviter, $important = false) + public function joinGroup($userid, $inviter, $important = null) { AbstractModel::transaction(function () use ($important, $inviter, $userid) { foreach (is_array($userid) ? $userid : [$userid] as $value) { if ($value > 0) { + $updateData = [ + 'inviter' => $inviter, + ]; + if (is_bool($important)) { + $updateData['important'] = $important ? 1 : 0; + } + $isInsert = false; WebSocketDialogUser::updateInsert([ 'dialog_id' => $this->id, 'userid' => $value, - ], [ - 'inviter' => $inviter, - 'important' => $important ? 1 : 0, - ]); - WebSocketDialogMsg::sendMsg(null, $this->id, 'notice', [ - 'notice' => User::userid2nickname($value) . " 已加入群组" - ], $inviter, true, true); + ], $updateData, [], $isInsert); + if ($isInsert) { + WebSocketDialogMsg::sendMsg(null, $this->id, 'notice', [ + 'notice' => User::userid2nickname($value) . " 已加入群组" + ], $inviter, true, true); + } } } }); diff --git a/resources/assets/js/pages/manage/components/DialogGroupInfo.vue b/resources/assets/js/pages/manage/components/DialogGroupInfo.vue index 910fa56ec..17e2ae8f7 100644 --- a/resources/assets/js/pages/manage/components/DialogGroupInfo.vue +++ b/resources/assets/js/pages/manage/components/DialogGroupInfo.vue @@ -33,11 +33,7 @@
- - - +
@@ -247,30 +243,6 @@ export default { }); }, - onDisband() { - $A.modalConfirm({ - content: `你确定要解散【${this.dialogData.name}】群组吗?`, - loading: true, - okText: '解散', - onOk: () => { - return new Promise((resolve, reject) => { - this.$store.dispatch("call", { - url: 'dialog/group/disband', - data: { - dialog_id: this.dialogId, - } - }).then(({msg}) => { - resolve(msg); - this.$store.dispatch("forgetDialog", this.dialogId); - this.goForward({name: 'manage-messenger'}); - }).catch(({msg}) => { - reject(msg); - }); - }) - }, - }); - }, - openUser(userid) { if (this.openIng) { return diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index a7d2d275e..ef6fd4d65 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -65,18 +65,33 @@ - - - - + + + + +
{{$L('创建群组')}}
+
+ +
+
@@ -351,6 +366,22 @@ + + +
+ + + +
+
+ + +
+
+ {}) }, - openCreateGroup() { - this.createGroupData = { - userids: this.dialogData.dialog_user ? [this.userId, this.dialogData.dialog_user.userid] : [this.userId], - uncancelable: [this.userId] - }; - this.createGroupShow = true; + onDialogMenu(cmd) { + switch (cmd) { + case "openCreate": + const userids = [this.userId] + if (this.dialogData.dialog_user && this.userId != this.dialogData.dialog_user.userid) { + userids.push(this.dialogData.dialog_user.userid) + } + this.createGroupData = {userids, uncancelable: [this.userId]} + this.createGroupShow = true + break; + + case "groupInfo": + this.groupInfoShow = true + break; + + case "transfer": + this.groupTransferData = { + dialog_id: this.dialogId, + userid: [], + disabledChoice: [this.userId] + } + this.groupTransferShow = true + break; + + case "transferConfirm": + this.onTransferGroup() + break; + + case "disband": + this.onDisbandGroup() + break; + + case "exit": + this.onExitGroup() + break; + } + }, + + onTransferGroup() { + if (this.groupTransferData.userid.length === 0) { + $A.messageError("请选择新的群主"); + return + } + this.groupTransferLoad++; + this.$store.dispatch("call", { + url: 'dialog/group/transfer', + data: { + dialog_id: this.dialogId, + userid: this.groupTransferData.userid[0] + } + }).then(({data, msg}) => { + $A.messageSuccess(msg); + this.$store.dispatch("saveDialog", data); + }).catch(({msg}) => { + $A.modalError(msg); + }).finally(_ => { + this.groupTransferLoad--; + }); + }, + + onDisbandGroup() { + $A.modalConfirm({ + content: `你确定要解散【${this.dialogData.name}】群组吗?`, + loading: true, + okText: '解散', + onOk: () => { + return new Promise((resolve, reject) => { + this.$store.dispatch("call", { + url: 'dialog/group/disband', + data: { + dialog_id: this.dialogId, + } + }).then(({msg}) => { + resolve(msg); + this.$store.dispatch("forgetDialog", this.dialogId); + this.goForward({name: 'manage-messenger'}); + }).catch(({msg}) => { + reject(msg); + }); + }) + }, + }); + }, + + onExitGroup() { + $A.modalConfirm({ + content: "你确定要退出群组吗?", + loading: true, + onOk: () => { + return new Promise((resolve, reject) => { + this.$store.dispatch("call", { + url: 'dialog/group/deluser', + data: { + dialog_id: this.dialogId, + } + }).then(({msg}) => { + resolve(msg); + this.$store.dispatch("forgetDialog", this.dialogId); + this.goForward({name: 'manage-messenger'}); + }).catch(({msg}) => { + reject(msg); + }); + }) + }, + }); }, onCreateGroup() { diff --git a/resources/assets/sass/pages/components/dialog-wrapper.scss b/resources/assets/sass/pages/components/dialog-wrapper.scss index 4e1e38ba1..f229bb35e 100644 --- a/resources/assets/sass/pages/components/dialog-wrapper.scss +++ b/resources/assets/sass/pages/components/dialog-wrapper.scss @@ -296,15 +296,24 @@ } .dialog-back, - .dialog-create { - cursor: pointer; - margin-left: 24px; + .dialog-menu { font-size: 22px; color: $primary-text-color; } + .dialog-menu { + margin-right: -22px; + .dialog-menu-icon { + cursor: pointer; + margin: 0 22px; + font-size: 22px; + color: $primary-text-color; + } + } + .dialog-back { display: none; + cursor: pointer; } } } @@ -1500,17 +1509,22 @@ } .dialog-back, - .dialog-create { + .dialog-menu { position: absolute; top: 0; bottom: 0; right: 0; - margin: 0; width: 52px; display: flex; align-items: center; justify-content: center; } + .dialog-menu { + margin: 0; + .dialog-menu-icon { + margin: 0; + } + } .dialog-back { padding-right: 6px; right: auto;