diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index e150159d4..33b1d34b2 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -305,7 +305,7 @@ class DialogController extends AbstractController $fileData['thumb'] = Base::unFillUrl($fileData['thumb']); $fileData['size'] *= 1024; // - if ($dialog->type === 'group' && $dialog->group_type === 'task') { // 任务群聊保存文件 + if ($dialog->type === 'group' && $dialog->group_type === 'task') { // 任务群组保存文件 if ($image_attachment || !in_array($fileData['ext'], File::imageExt)) { // 如果是图片不保存 $task = ProjectTask::whereDialogId($dialog->id)->first(); if ($task) { @@ -552,15 +552,15 @@ class DialogController extends AbstractController } /** - * @api {get} api/dialog/group/add 15. 新增群聊 + * @api {get} api/dialog/group/add 15. 新增群组 * * @apiDescription 需要token身份 * @apiVersion 1.0.0 * @apiGroup dialog * @apiName group__add * - * @apiParam {String} chat_name 群名 * @apiParam {Array} userids 群成员,格式: [userid1, userid2, userid3] + * @apiParam {String} chat_name 群名称 * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -570,8 +570,8 @@ class DialogController extends AbstractController { $user = User::auth(); // - $chatName = trim(Request::input('chat_name')); $userids = Request::input('userids'); + $chatName = trim(Request::input('chat_name')); // if (!is_array($userids)) { return Base::retError('请选择群成员'); @@ -586,7 +586,7 @@ class DialogController extends AbstractController $array = []; foreach ($userids as $userid) { $array[] = User::userid2nickname($userid); - if (count($array) >= 8 || strlen(implode(", ", $array)) > 200) { + if (count($array) >= 8 || strlen(implode(", ", $array)) > 100) { $array[] = "..."; break; } @@ -595,11 +595,53 @@ class DialogController extends AbstractController } $dialog = WebSocketDialog::createGroup($chatName, $userids, 'user', $user->userid); if (empty($dialog)) { - return Base::retError('创建群聊失败'); + return Base::retError('创建群组失败'); } return Base::retSuccess('创建成功', $dialog); } + /** + * @api {get} api/dialog/group/edit 16. 修改群组 + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup dialog + * @apiName group__edit + * + * @apiParam {Number} dialog_id 会话ID + * @apiParam {String} chat_name 群名称 + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + */ + public function group__edit() + { + $user = User::auth(); + // + $dialog_id = intval(Request::input('dialog_id')); + $chatName = trim(Request::input('chat_name')); + // + if (mb_strlen($chatName) < 2) { + return Base::retError('群名称至少2个字'); + } + if (mb_strlen($chatName) > 100) { + return Base::retError('群名称最长限制100个字'); + } + // + $dialog = WebSocketDialog::checkDialog($dialog_id); + if ($dialog->owner_id != $user->userid) { + return Base::retError('仅限群主操作'); + } + // + $dialog->name = $chatName; + $dialog->save(); + return Base::retSuccess('修改成功', [ + 'id' => $dialog->id, + 'name' => $dialog->name, + ]); + } + /** * @api {get} api/dialog/group/user 16. 获取群成员 * @@ -702,4 +744,33 @@ class DialogController extends AbstractController $dialog->exitGroup($userids); return Base::retSuccess($type === 'remove' ? '移出成功' : '退出成功'); } + + /** + * @api {get} api/dialog/group/disband 16. 解散群组 + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup dialog + * @apiName group__disband + * + * @apiParam {Number} dialog_id 会话ID + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + */ + public function group__disband() + { + $user = User::auth(); + // + $dialog_id = intval(Request::input('dialog_id')); + // + $dialog = WebSocketDialog::checkDialog($dialog_id); + if ($dialog->owner_id != $user->userid) { + return Base::retError('仅限群主操作'); + } + // + $dialog->disbandGroup(); + return Base::retSuccess('解散成功'); + } } diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index 522a38f41..90398fa8f 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -84,7 +84,10 @@ class WebSocketDialog extends AbstractModel public function joinGroup($userid) { if ($this->type !== 'group') { - return false; + throw new ApiException('此操作仅限群组'); + } + if ($this->group_type !== 'user') { + throw new ApiException('此操作仅限个人群组'); } AbstractModel::transaction(function () use ($userid) { foreach (is_array($userid) ? $userid : [$userid] as $value) { @@ -106,6 +109,12 @@ class WebSocketDialog extends AbstractModel */ public function exitGroup($userid) { + if ($this->type !== 'group') { + throw new ApiException('此操作仅限群组'); + } + if ($this->group_type !== 'user') { + throw new ApiException('此操作仅限个人群组'); + } $builder = WebSocketDialogUser::whereDialogId($this->id); if (is_array($userid)) { $builder->whereIn('userid', $userid); @@ -125,6 +134,29 @@ class WebSocketDialog extends AbstractModel return true; } + /** + * 解散群组 + * @return bool + */ + public function disbandGroup() + { + if ($this->type !== 'group') { + throw new ApiException('此操作仅限群组'); + } + if ($this->group_type !== 'user') { + throw new ApiException('此操作仅限个人群组'); + } + return AbstractModel::transaction(function() { + WebSocketDialogUser::whereDialogId($this->id)->chunkById(100, function($list) { + /** @var WebSocketDialogUser $item */ + foreach ($list as $item) { + $item->delete(); + } + }); + return $this->delete(); + }); + } + /** * 获取对话(同时检验对话身份) * @param $dialog_id @@ -148,7 +180,7 @@ class WebSocketDialog extends AbstractModel } } if (!WebSocketDialogUser::whereDialogId($dialog->id)->whereUserid($userid)->exists()) { - throw new ApiException('不在成员列表内'); + throw new ApiException('不在成员列表内', ['dialog_id' => $dialog_id], -4003); } return $dialog; } diff --git a/resources/assets/js/pages/manage/components/DialogGroupInfo.vue b/resources/assets/js/pages/manage/components/DialogGroupInfo.vue index db1a216b1..2b787fd91 100644 --- a/resources/assets/js/pages/manage/components/DialogGroupInfo.vue +++ b/resources/assets/js/pages/manage/components/DialogGroupInfo.vue @@ -16,20 +16,11 @@ clearable/> -
- - {{ $L("添加成员") }} -
-
- - {{ $L("退出群聊") }} -
-
+
+ + +
+
+ +
+ { + this.$store.dispatch("saveDialog", data); + cb() + }).catch(({msg}) => { + $A.modalError(msg); + cb() + }); }, getDialogUser() { @@ -193,10 +208,10 @@ export default { }, onExit(item) { - let content = "你确定要退出群聊吗?" + let content = "你确定要退出群组吗?" let userids = []; if ($A.isJson(item)) { - content = `你确定要将【${item.nickname}】移出群聊吗?` + content = `你确定要将【${item.nickname}】移出群组吗?` userids = [item.userid]; } $A.modalConfirm({ @@ -212,7 +227,7 @@ export default { }).then(({msg}) => { this.$Modal.remove(); $A.messageSuccess(msg); - if (userids === "my") { + if (userids.length > 0) { this.getDialogUser(); } else { this.$store.dispatch("forgetDialog", this.dialogId); @@ -224,7 +239,31 @@ export default { }); }, }); - } + }, + + onDisband() { + $A.modalConfirm({ + content: `你确定要解散【${this.dialogData.name}】群组吗?`, + loading: true, + okText: '解散', + onOk: () => { + this.$store.dispatch("call", { + url: 'dialog/group/disband', + data: { + dialog_id: this.dialogId, + } + }).then(({msg}) => { + this.$Modal.remove(); + $A.messageSuccess(msg); + this.$store.dispatch("forgetDialog", this.dialogId); + this.goForward({name: 'manage-messenger'}); + }).catch(({msg}) => { + $A.modalError(msg, 301); + this.$Modal.remove(); + }); + }, + }); + }, } } diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 56f5a8820..14257903b 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -35,7 +35,7 @@ @@ -127,10 +127,10 @@ - +
diff --git a/resources/assets/sass/dark.scss b/resources/assets/sass/dark.scss index f484c9233..3cd842e8c 100644 --- a/resources/assets/sass/dark.scss +++ b/resources/assets/sass/dark.scss @@ -191,6 +191,18 @@ body.dark-mode-reverse { } } + .dialog-group-info { + .group-info-user { + > ul { + > li { + .user-tag { + color: $primary-title-color; + } + } + } + } + } + .file-icon { &:before { background-image: url("../images/file/dark/other.svg"); diff --git a/resources/assets/sass/pages/components/dialog-group-info.scss b/resources/assets/sass/pages/components/dialog-group-info.scss index d9d53e28c..b58d8ff75 100644 --- a/resources/assets/sass/pages/components/dialog-group-info.scss +++ b/resources/assets/sass/pages/components/dialog-group-info.scss @@ -24,29 +24,25 @@ overflow: visible; white-space: normal; } + + .quick-input { + display: flex; + flex-direction: column; + } } .group-info-search { - margin: 18px 24px 0; + margin: 24px 24px 0; } .group-info-button { display: flex; align-items: center; - margin: 18px 24px 0; + justify-content: center; + margin: 18px 24px; cursor: pointer; - - > i { - display: flex; - align-items: center; - justify-content: center; - height: 32px; - width: 32px; - font-size: 18px; - margin-right: 8px; - border-radius: 50%; - color: #777; - border: 1px solid #ddd; + > button { + margin: 0 8px; } } @@ -87,14 +83,26 @@ } } + .user-tag { + margin-left: 4px; + height: 22px; + line-height: 22px; + padding: 0 6px; + border-radius: 3px; + transform: scale(0.9); + transform-origin: right center; + color: #ffffff; + background-color: $primary-color; + } + .user-exit { display: flex; align-items: center; justify-content: center; cursor: pointer; margin-left: 4px; - width: 20px; - height: 20px; + width: 22px; + height: 22px; font-size: 12px; color: #999999; border: 1px solid #dddddd; @@ -103,15 +111,6 @@ transform: translateX(50%); transition: all 0.2s; } - - .ivu-tag { - margin-left: 4px; - height: 20px; - line-height: 20px; - padding: 0 5px; - transform: scale(0.9); - transform-origin: right center; - } } } }