Skip to content

Commit

Permalink
perf: 消息内容支持待办列表
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Apr 20, 2024
1 parent 182e5a6 commit a46ffa1
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 6 deletions.
66 changes: 66 additions & 0 deletions app/Http/Controllers/Api/DialogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,72 @@ public function msg__unread()
]);
}

/**
* @api {get} api/dialog/msg/checked 16. 设置消息checked
*
* @apiDescription 需要token身份
* @apiVersion 1.0.0
* @apiGroup dialog
* @apiName msg__checked
*
* @apiParam {Number} dialog_id 对话ID
* @apiParam {Number} msg_id 消息ID
* @apiParam {Number} index li 位置
* @apiParam {Number} checked 标记、取消标记
*
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
* @apiSuccessExample {json} data:
{
"id": 43,
"msg": {
// ....
},
}
*/
public function msg__checked()
{
$user = User::auth();
//
$dialog_id = intval(Request::input('dialog_id'));
$msg_id = intval(Request::input('msg_id'));
$index = intval(Request::input('index'));
$checked = intval(Request::input('checked'));
//
$dialogMsg = WebSocketDialogMsg::whereId($msg_id)->whereDialogId($dialog_id)->first();
if (empty($dialogMsg)) {
return Base::retError('消息不存在');
}
if ($dialogMsg->userid != $user->userid) {
return Base::retError('仅支持修改自己的消息');
}
if ($dialogMsg->type !== 'text') {
return Base::retError('仅支持文本消息');
}
//
$oldMsg = Base::json2array($dialogMsg->getRawOriginal('msg'));
$oldText = $oldMsg['text'] ?? '';
$newText = preg_replace_callback('/<li[^>]*>/i', function ($matches) use ($index, $checked) {
static $i = 0;
if ($i++ == $index) {
$checked = $checked ? 'checked' : 'unchecked';
return '<li data-list="' . $checked . '">';
}
return $matches[0];
}, $oldText);
//
$dialogMsg->updateInstance([
'msg' => array_merge($oldMsg, ['text' => $newText]),
]);
$dialogMsg->save();
//
return Base::retSuccess('success', [
'id' => $dialogMsg->id,
'msg' => $dialogMsg->msg,
]);
}

/**
* @api {post} api/dialog/msg/stream 17. 通知成员监听消息
*
Expand Down
11 changes: 10 additions & 1 deletion app/Models/WebSocketDialogMsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,15 @@ public static function formatMsg($text, $dialog_id)
$text = str_replace($str, "[:QUICK:{$quickKey}:{$quickLabel}:]", $text);
}
}
// 处理 li 标签
preg_match_all("/<li[^>]*?>/i", $text, $matchs);
foreach ($matchs[0] as $str) {
if (preg_match("/data-list=['\"](bullet|ordered|checked|unchecked)['\"]/i", $str, $match)) {
$text = str_replace($str, '<li data-list="' . $match[1] . '">', $text);
} else {
$text = str_replace($str, '<li>', $text);
}
}
// 处理链接标签
preg_match_all("/<a[^>]*?href=([\"'])(.*?)\\1[^>]*?>(.*?)<\/a>/is", $text, $matchs);
foreach ($matchs[0] as $key => $str) {
Expand Down Expand Up @@ -785,7 +794,7 @@ public static function formatMsg($text, $dialog_id)
}
// 过滤标签
$text = strip_tags($text, '<blockquote> <strong> <pre> <ol> <ul> <li> <em> <p> <s> <u> <a>');
$text = preg_replace_callback("/\<(blockquote|strong|pre|ol|ul|li|em|p|s|u)(.*?)\>/is", function (array $match) { // 不用去除a标签,上面已经处理过了
$text = preg_replace_callback("/\<(blockquote|strong|pre|ol|ul|em|p|s|u)(.*?)\>/is", function (array $match) { // 不用去除 li 和 a 标签,上面已经处理过了
preg_match("/<[^>]*?style=([\"'])(.*?)\\1[^>]*?>/is", $match[0], $matchs);
$attach = '';
if ($matchs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export default {
toolbar: {
type: Array,
default: () => {
return ['bold', 'strike', 'italic', 'underline', 'blockquote', {'list': 'ordered'}, {'list': 'bullet'}]
return ['bold', 'strike', 'italic', 'underline', 'blockquote', {'list': 'ordered'}, {'list': 'bullet'}, {'list': 'check'}]
},
},
maxlength: {
Expand Down
52 changes: 48 additions & 4 deletions resources/assets/js/pages/manage/components/DialogWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3051,6 +3051,9 @@ export default {
// 打开审批详情
let approveElement = target;
while (approveElement) {
if (approveElement.classList.contains('dialog-scroller')) {
break;
}
if (approveElement.classList.contains('open-approve-details')) {
const dataId = approveElement.getAttribute("data-id")
if (window.innerWidth < 426) {
Expand All @@ -3061,15 +3064,13 @@ export default {
this.approveDetails = {id: dataId};
})
}
break;
}
if (approveElement.classList.contains('dialog-item')) {
break;
return;
}
approveElement = approveElement.parentElement;
}
switch (target.nodeName) {
// 打开图片
case "IMG":
if (target.classList.contains('browse')) {
this.onViewPicture(target.currentSrc);
Expand All @@ -3080,6 +3081,7 @@ export default {
}
break;
// 打开任务、打开OKR
case "SPAN":
if (target.classList.contains('mention') && target.classList.contains('task')) {
this.$store.dispatch("openTask", $A.runNum(target.getAttribute("data-id")));
Expand All @@ -3089,6 +3091,48 @@ export default {
}
break;
// 更新待办列表
case "LI":
const dataClass = target.getAttribute('data-list')
if (['checked', 'unchecked'].includes(dataClass)) {
let listElement = el.parentElement;
while (listElement) {
if (listElement.classList.contains('dialog-scroller')) {
break;
}
if (listElement.classList.contains('dialog-view')) {
const dataId = listElement.getAttribute("data-id")
const dataIndex = [].indexOf.call(el.querySelectorAll(target.tagName), target);
if (dataClass === 'checked') {
target.setAttribute('data-list', 'unchecked')
} else {
target.setAttribute('data-list', 'checked')
}
this.$store.dispatch("setLoad", {
key: `msg-${dataId}`,
delay: 600
})
this.$store.dispatch("call", {
url: 'dialog/msg/checked',
data: {
dialog_id: this.dialogId,
msg_id: dataId,
index: dataIndex,
checked: dataClass === 'checked' ? 0 : 1
},
}).then(({data}) => {
this.$store.dispatch("saveDialogMsg", data);
}).catch(({msg}) => {
$A.modalError(msg);
}).finally(_ => {
this.$store.dispatch("cancelLoad", `msg-${dataId}`)
});
break;
}
listElement = listElement.parentElement;
}
}
break;
}
},
Expand Down
16 changes: 16 additions & 0 deletions resources/assets/sass/pages/components/chat-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@
width: auto;
min-width: 1.2em;
}
&[data-list=checked],
&[data-list=unchecked] {
> .ql-ui:before {
font-family: "taskfont", "serif" !important;
font-size: 14px;
content: "\e6ed";
font-weight: normal;
transform: scale(1.12);
}
}

&[data-list=unchecked] {
> .ql-ui:before {
content: "\e6f1";
}
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions resources/assets/sass/pages/components/dialog-wrapper.scss
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,31 @@
min-width: 1.2em;
content: counter(list-0, decimal) '. ';
}

&[data-list=bullet] {
&:before {
content: '\2022';
font-weight: 900;
text-align: center;
}
}

&[data-list=checked],
&[data-list=unchecked] {
&:before {
font-family: "taskfont", "serif" !important;
font-size: 14px;
content: "\e6ed";
font-weight: normal;
transform: scale(1.12);
}
}

&[data-list=unchecked] {
&:before {
content: "\e6f1";
}
}
}
}

Expand Down

0 comments on commit a46ffa1

Please sign in to comment.