perf: 代码优化

This commit is contained in:
weifashi 2023-12-28 22:10:56 +08:00
parent 91d5bd80ff
commit 5aded9daa3
4 changed files with 18 additions and 11 deletions

View File

@ -2297,7 +2297,7 @@ class DialogController extends AbstractController
*/ */
public function toplist() public function toplist()
{ {
$user = User::auth(); User::auth();
// //
$dialog_id = intval(Request::input('dialog_id')); $dialog_id = intval(Request::input('dialog_id'));
// //

View File

@ -426,7 +426,6 @@ class WebSocketDialogMsg extends AbstractModel
} }
} }
$data['add'] = $res['data']; $data['add'] = $res['data'];
$resData['tops'] = self::whereDialogId($dialog->id)->whereNotNull('top_at')->orderByDesc('top_at')->take(50)->get();
$dialog->pushMsg('update', $resData); $dialog->pushMsg('update', $resData);
} else { } else {
$this->top = $before; $this->top = $before;

View File

@ -3444,11 +3444,20 @@ export default {
}).then(({ data, msg }) => { }).then(({ data, msg }) => {
resolve(msg) resolve(msg)
this.tagOrTodoOrTopSuccess(data) this.tagOrTodoOrTopSuccess(data)
this.$store.dialogTops = this.dialogMsgs.filter(item => item.dialog_id != this.dialogId) //
const index = this.dialogMsgs.findIndex(({id}) => id == data.update?.id); const dialogTops = this.dialogTops.filter(item => item.dialog_id == this.dialogId);
if (index > -1) { this.$store.dispatch("saveDialogTop", dialogTops.map(item => {
const update = Object.assign({}, this.dialogMsgs[index], data.update) item.top = 0;
this.$store.dispatch("saveDialogTop", update) item.top_at = "";
return item;
}))
//
if (data.update?.top) {
const index = this.dialogMsgs.findIndex(({ id }) => id == data.update.id && data.update.top);
if (index > -1) {
const update = Object.assign({}, this.dialogMsgs[index], data.update)
this.$store.dispatch("saveDialogTop", update)
}
} }
}).catch(({ msg }) => { }).catch(({ msg }) => {
reject(msg); reject(msg);

View File

@ -2563,7 +2563,7 @@ export default {
dialog_id, dialog_id,
}, },
}).then(({data}) => { }).then(({data}) => {
if ($A.arrayLength(data) > 0) { if ($A.isArray(data)) {
state.dialogTops = state.dialogTops.filter(item => item.dialog_id != dialog_id) state.dialogTops = state.dialogTops.filter(item => item.dialog_id != dialog_id)
dispatch("saveDialogTop", data) dispatch("saveDialogTop", data)
} }
@ -3476,9 +3476,8 @@ export default {
dispatch("getDialogTodo", dialog_id) dispatch("getDialogTodo", dialog_id)
} }
// 更新置顶 // 更新置顶
if ($A.isArray(data.tops)) { if (typeof data.top !== "undefined") {
state.dialogTops = state.dialogTops.filter(item => item.dialog_id != data.dialog_id) dispatch("getDialogTop", dialog_id)
dispatch("saveDialogTop", data.tops)
} }
return; return;
} }