From 500ed3a4d710af27e98ba7a78249e0a257bc102d Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 30 Jun 2022 15:56:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=A0=87=E6=B3=A8?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/DialogController.php | 31 ++++++++- app/Models/WebSocketDialogMsg.php | 62 ++++++++++++++++-- ..._145804_add_web_socket_dialog_msgs_tag.php | 34 ++++++++++ resources/assets/js/functions/utils.js | 6 +- .../js/pages/manage/components/DialogItem.vue | 49 +++++++++----- .../js/pages/manage/components/DialogView.vue | 4 ++ .../pages/manage/components/DialogWrapper.vue | 36 ++++++++++ .../sass/pages/components/dialog-wrapper.scss | 29 ++++++++ .../statics/public/css/fonts/taskfont.ttf | Bin 64028 -> 64304 bytes .../statics/public/css/fonts/taskfont.woff | Bin 34532 -> 34708 bytes .../statics/public/css/fonts/taskfont.woff2 | Bin 29304 -> 29496 bytes 11 files changed, 228 insertions(+), 23 deletions(-) create mode 100644 database/migrations/2022_06_30_145804_add_web_socket_dialog_msgs_tag.php diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index ab61ef9e2..e35cce563 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -851,7 +851,7 @@ class DialogController extends AbstractController * @apiDescription 需要token身份 * @apiVersion 1.0.0 * @apiGroup dialog - * @apiName msg__forward + * @apiName msg__emoji * * @apiParam {Number} msg_id 消息ID * @apiParam {String} symbol 回复或取消的emoji表情 @@ -881,6 +881,35 @@ class DialogController extends AbstractController return $msg->emojiMsg($symbol, $user->userid); } + /** + * @api {get} api/dialog/msg/tag 18. 标注/取消标注 + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup dialog + * @apiName msg__tag + * + * @apiParam {Number} msg_id 消息ID + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + */ + public function msg__tag() + { + $user = User::auth(); + // + $msg_id = intval(Request::input("msg_id")); + // + $msg = WebSocketDialogMsg::whereId($msg_id)->first(); + if (empty($msg)) { + return Base::retError("消息不存在或已被删除"); + } + WebSocketDialog::checkDialog($msg->dialog_id); + // + return $msg->toggleTagMsg($user->userid); + } + /** * @api {get} api/dialog/top 19. 会话置顶 * diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index 721e21bda..81e90d837 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -23,6 +23,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property string|null $key 搜索关键词 * @property int|null $read 已阅数量 * @property int|null $send 发送数量 + * @property int|null $tag 标注会员ID * @property int|null $reply_num 有多少条回复 * @property int|null $reply_id 回复ID * @property \Illuminate\Support\Carbon|null $created_at @@ -47,6 +48,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereReplyId($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereReplyNum($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereSend($value) + * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereTag($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereType($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereUserid($value) @@ -247,6 +249,44 @@ class WebSocketDialogMsg extends AbstractModel return Base::retSuccess('sucess', $resData); } + /** + * 标注、取消标注 + * @param int $sender 标注的会员ID + * @return mixed + */ + public function toggleTagMsg($sender) + { + if ($this->type === 'tag') { + return Base::retError('此消息不支持标注'); + } + $this->tag = $this->tag ? 0 : $sender; + $this->save(); + $resData = [ + 'id' => $this->id, + 'tag' => $this->tag, + ]; + // + $dialog = WebSocketDialog::find($this->dialog_id); + $dialog?->pushMsg('update', $resData); + // + $data = [ + 'update' => $resData + ]; + $res = self::sendMsg($this->dialog_id, 0, 'tag', [ + 'action' => $this->tag ? 'add' : 'remove', + 'data' => [ + 'id' => $this->id, + 'type' => $this->type, + 'msg' => $this->msg, + ] + ], $sender); + if (Base::isSuccess($res)) { + $data['add'] = $res['data']; + } + // + return Base::retSuccess('sucess', $data); + } + /** * 转发消息 * @param $userids @@ -323,22 +363,32 @@ class WebSocketDialogMsg extends AbstractModel /** * 预览消息 * @param bool $preserveHtml 保留html格式 + * @param null|array $data * @return string */ - public function previewMsg($preserveHtml = false) + public function previewMsg($preserveHtml = false, $data = null) { - switch ($this->type) { + if ($data === null) { + $data = [ + 'type' => $this->type, + 'msg' => $this->msg, + ]; + } + switch ($data['type']) { case 'text': - return $this->previewTextMsg($this->msg['text'], $preserveHtml); + return $this->previewTextMsg($data['msg']['text'], $preserveHtml); case 'record': return "[语音]"; case 'meeting': - return "[会议] ${$this->msg['name']}"; + return "[会议] ${$data['msg']['name']}"; case 'file': - if ($this->msg['type'] == 'img') { + if ($data['msg']['type'] == 'img') { return "[图片]"; } - return "[文件] {$this->msg['name']}"; + return "[文件] {$data['msg']['name']}"; + case 'tag': + $action = $data['msg']['action'] === 'remove' ? '取消标注' : '标注'; + return "[{$action}] {$this->previewMsg(false, $data['msg']['data'])}"; default: return "[未知的消息]"; } diff --git a/database/migrations/2022_06_30_145804_add_web_socket_dialog_msgs_tag.php b/database/migrations/2022_06_30_145804_add_web_socket_dialog_msgs_tag.php new file mode 100644 index 000000000..9ed9fe4d7 --- /dev/null +++ b/database/migrations/2022_06_30_145804_add_web_socket_dialog_msgs_tag.php @@ -0,0 +1,34 @@ +bigInteger('tag')->nullable()->default(0)->after('send')->comment('标注会员ID'); + } + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('web_socket_dialog_msgs', function (Blueprint $table) { + $table->dropColumn("tag"); + }); + } +} diff --git a/resources/assets/js/functions/utils.js b/resources/assets/js/functions/utils.js index bde360a6c..8faeb4182 100755 --- a/resources/assets/js/functions/utils.js +++ b/resources/assets/js/functions/utils.js @@ -1,4 +1,4 @@ -module.exports = { +const assetsFunctionUtils = { /** * 消息格式化处理 * @param text @@ -95,6 +95,8 @@ module.exports = { return `[${$A.L('图片')}]` } return `[${$A.L('文件')}] ${data.msg.name}` + case 'tag': + return `[${$A.L(data.msg.action === 'remove' ? '取消标注' : '标注')}] ${assetsFunctionUtils.msgSimpleDesc(data.msg.data)}` default: return `[${$A.L('未知的消息')}]` } @@ -135,3 +137,5 @@ module.exports = { }, false); }, } + +module.exports = assetsFunctionUtils diff --git a/resources/assets/js/pages/manage/components/DialogItem.vue b/resources/assets/js/pages/manage/components/DialogItem.vue index 9c45d0bad..1f7a7f3cf 100644 --- a/resources/assets/js/pages/manage/components/DialogItem.vue +++ b/resources/assets/js/pages/manage/components/DialogItem.vue @@ -1,27 +1,35 @@