mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 18:42:54 +00:00
perf: 1. 强化接龙接口本地时间戳问题 2. 接龙消息点展开按钮后做缓存处理
This commit is contained in:
parent
7bfc43c85f
commit
d12c0c4207
@ -2175,12 +2175,12 @@ class DialogController extends AbstractController
|
||||
$dialog_id = intval(Request::input('dialog_id'));
|
||||
$uuid = trim(Request::input('uuid'));
|
||||
$text = trim(Request::input('text'));
|
||||
$list = Request::input('list');
|
||||
$list = Request::input('list') ?? [];
|
||||
//
|
||||
WebSocketDialog::checkDialog($dialog_id);
|
||||
$strlen = mb_strlen($text);
|
||||
$noimglen = mb_strlen(preg_replace("/<img[^>]*?>/i", "", $text));
|
||||
if ($strlen < 1) {
|
||||
if ($strlen < 1 || empty($list)) {
|
||||
return Base::retError('内容不能为空');
|
||||
}
|
||||
if ($noimglen > 200000) {
|
||||
@ -2195,17 +2195,28 @@ class DialogController extends AbstractController
|
||||
->orderByDesc('created_at')
|
||||
->where('msg', 'like', "%$uuid%")
|
||||
->value('msg');
|
||||
$list = array_reverse(array_merge($dialogMsg['list'] ?? [], $list));
|
||||
$list = array_reduce($list, function ($result, $item) {
|
||||
$fieldValue = $item['id']; // 指定字段名
|
||||
if (!isset($result[$fieldValue])) {
|
||||
$result[$fieldValue] = $item;
|
||||
// 新增
|
||||
$msgList = $dialogMsg['list'] ?? [];
|
||||
$addList = array_udiff($list, $msgList, function($a, $b) {
|
||||
return ($a['id'] ?? 0) - $b['id'];
|
||||
});
|
||||
foreach ($addList as $key => $item) {
|
||||
$item['id'] = intval(round(microtime(true) * 1000)) + $key;
|
||||
$msgList[] = $item;
|
||||
}
|
||||
// 编辑更新
|
||||
$lists = array_column($list,null,'id');
|
||||
foreach ($msgList as $key => $item) {
|
||||
if (isset($lists[$item['id']]) && $item['userid'] == $user->userid) {
|
||||
$msgList[$key] = $lists[$item['id']];
|
||||
}
|
||||
return $result;
|
||||
}, []);
|
||||
$list = array_reverse(array_values($list));
|
||||
}
|
||||
$list = $msgList;
|
||||
} else {
|
||||
$uuid = Base::generatePassword(36);
|
||||
foreach ($list as $key => $item) {
|
||||
$list[$key]['id'] = intval(round(microtime(true) * 1000)) + $key;
|
||||
}
|
||||
}
|
||||
//
|
||||
usort($list, function ($a, $b) {
|
||||
|
||||
@ -76,12 +76,12 @@
|
||||
<!--接龙-->
|
||||
<div v-else-if="msgData.type === 'word-chain'" class="content-text content-word-chain no-dark-content">
|
||||
<pre v-html="$A.formatTextMsg(msgData.msg.text, userId)"></pre>
|
||||
<ul>
|
||||
<ul :class="{'expand': unfoldWordChainData.indexOf(msgData.id) !== -1 }">
|
||||
<li v-for="(item) in (msgData.msg.list || []).filter(h=>h.type == 'case')">
|
||||
{{ $L('例') }} {{ item.text }}
|
||||
</li>
|
||||
<li v-for="(item,index) in (msgData.msg.list || []).filter(h=>h.type != 'case')">
|
||||
<span class="expand" v-if="index == 2 && msgData.msg.list.length > 4" @click="unfoldWordChain">
|
||||
<span class="expand" v-if="index == 2 && msgData.msg.list.length > 4" @click="unfoldWordChain(msgData)">
|
||||
...{{$L('展开')}}...
|
||||
</span>
|
||||
<span :class="{'shrink': index >= 2 && msgData.msg.list.length > 4 } ">
|
||||
@ -325,7 +325,8 @@ export default {
|
||||
|
||||
emojiUsersNum: 5,
|
||||
|
||||
voteData: {}
|
||||
voteData: {},
|
||||
unfoldWordChainData: []
|
||||
}
|
||||
},
|
||||
|
||||
@ -334,6 +335,9 @@ export default {
|
||||
if (Object.keys(this.voteData).length === 0) {
|
||||
this.voteData = JSON.parse(window.localStorage.getItem(`__cache:vote__`)) || {};
|
||||
}
|
||||
if (this.unfoldWordChainData.length === 0) {
|
||||
this.unfoldWordChainData = JSON.parse(window.localStorage.getItem(`__cache:unfoldWordChain__`)) || [];
|
||||
}
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
@ -643,8 +647,13 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
unfoldWordChain(e) {
|
||||
e.target.parentNode?.parentNode?.classList.add('expand')
|
||||
unfoldWordChain(msg) {
|
||||
if (this.unfoldWordChainData.indexOf(msg.id) == -1) {
|
||||
const data = JSON.parse(window.localStorage.getItem('__cache:unfoldWordChain__')) || [];
|
||||
data.push(msg.id);
|
||||
window.localStorage.setItem('__cache:unfoldWordChain__', JSON.stringify(data));
|
||||
this.unfoldWordChainData.push(msg.id);
|
||||
}
|
||||
},
|
||||
|
||||
onVote(type, msgData) {
|
||||
|
||||
@ -1198,6 +1198,7 @@ export default {
|
||||
this.$store.dispatch('closeDialog', old_id)
|
||||
//
|
||||
window.localStorage.removeItem('__cache:vote__')
|
||||
window.localStorage.removeItem('__cache:unfoldWordChain__')
|
||||
},
|
||||
immediate: true
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user