perf: 显示待办消息数量

This commit is contained in:
kuaifan 2022-07-08 14:00:16 +08:00
parent 6412efd031
commit 883e5c26d9
7 changed files with 41 additions and 16 deletions

View File

@ -403,7 +403,7 @@ class DialogController extends AbstractController
// //
if ($reDialog) { if ($reDialog) {
$data['dialog'] = $dialog->formatData($user->userid, true); $data['dialog'] = $dialog->formatData($user->userid, true);
$data['todo'] = $data['dialog']->has_todo ? WebSocketDialogMsgTodo::whereDialogId($dialog->id)->whereUserid($user->userid)->whereDoneAt(null)->orderByDesc('id')->take(50)->get() : []; $data['todo'] = $data['dialog']->todo_num > 0 ? WebSocketDialogMsgTodo::whereDialogId($dialog->id)->whereUserid($user->userid)->whereDoneAt(null)->orderByDesc('id')->take(50)->get() : [];
} }
return Base::retSuccess('success', $data); return Base::retSuccess('success', $data);
} }

View File

@ -81,7 +81,7 @@ class WebSocketDialog extends AbstractModel
$builder = WebSocketDialogUser::whereDialogId($this->id); $builder = WebSocketDialogUser::whereDialogId($this->id);
$this->people = $builder->count(); $this->people = $builder->count();
// 有待办 // 有待办
$this->has_todo = WebSocketDialogMsgTodo::whereDialogId($this->id)->whereUserid($userid)->whereDoneAt(null)->exists(); $this->todo_num = WebSocketDialogMsgTodo::whereDialogId($this->id)->whereUserid($userid)->whereDoneAt(null)->count();
} }
// 对方信息 // 对方信息
$this->dialog_user = null; $this->dialog_user = null;

View File

@ -88,8 +88,8 @@ export default {
}, },
msgUnreadMention() { msgUnreadMention() {
if (this.cacheDialogs.find(item => item.has_todo)) { if (this.msgTodoTotal) {
return this.$L("待办") return this.msgTodoTotal
} }
let num = 0; let num = 0;
let mention = 0; let mention = 0;
@ -112,6 +112,15 @@ export default {
return String(num); return String(num);
}, },
msgTodoTotal() {
let todoNum = this.cacheDialogs.reduce((total, current) => total + (current.todo_num || 0), 0)
if (todoNum > 0) {
if (todoNum > 99) todoNum = "99+"
return `${this.$L("待办")}${todoNum}`
}
return null;
},
activeName() { activeName() {
if (this.isMore || ['manage-calendar', 'manage-file', 'manage-setting'].includes(this.routeName)) { if (this.isMore || ['manage-calendar', 'manage-file', 'manage-setting'].includes(this.routeName)) {
return 'more'; return 'more';

View File

@ -510,8 +510,8 @@ export default {
}, },
msgUnreadMention() { msgUnreadMention() {
if (this.cacheDialogs.find(item => item.has_todo)) { if (this.msgTodoTotal) {
return this.$L("待办") return this.msgTodoTotal
} }
let num = 0; let num = 0;
let mention = 0; let mention = 0;
@ -542,8 +542,20 @@ export default {
return num; return num;
}, },
msgTodoTotal() {
let todoNum = this.cacheDialogs.reduce((total, current) => total + (current.todo_num || 0), 0)
if (todoNum > 0) {
if (todoNum > 9) todoNum = "9+"
return `${this.$L("待办")}${todoNum}`
}
return null;
},
unreadTotal() { unreadTotal() {
if (this.userId > 0) { if (this.userId > 0) {
if (this.msgTodoTotal) {
return this.msgTodoTotal
}
return this.msgAllUnread + this.dashboardTask.overdue_count + this.reportUnreadNumber return this.msgAllUnread + this.dashboardTask.overdue_count + this.reportUnreadNumber
} else { } else {
return 0 return 0
@ -696,9 +708,9 @@ export default {
}, },
unreadTotal: { unreadTotal: {
handler(num) { handler(val) {
if (this.$Electron) { if (this.$Electron) {
this.$Electron.sendMessage('setDockBadge', num); this.$Electron.sendMessage('setDockBadge', val);
} }
}, },
immediate: true immediate: true

View File

@ -579,7 +579,7 @@ export default {
}, },
todoList() { todoList() {
if (!this.dialogData.has_todo) { if (!this.dialogData.todo_num) {
return [] return []
} }
return this.dialogTodos.filter(item => !item.done_at && item.dialog_id == this.dialogId).sort((a, b) => { return this.dialogTodos.filter(item => !item.done_at && item.dialog_id == this.dialogId).sort((a, b) => {
@ -1079,6 +1079,10 @@ export default {
id: this.todoViewId, id: this.todoViewId,
done_at: $A.formatDate("Y-m-d H:i:s") done_at: $A.formatDate("Y-m-d H:i:s")
}) })
this.$store.dispatch("saveDialog", {
id: this.dialogId,
todo_num: this.todoList.length
})
if (data.add) { if (data.add) {
this.sendSuccess(data.add) this.sendSuccess(data.add)
} }

View File

@ -60,7 +60,7 @@
<Icon v-else class="icon-avatar" type="md-person" /> <Icon v-else class="icon-avatar" type="md-person" />
<div class="dialog-box"> <div class="dialog-box">
<div class="dialog-title"> <div class="dialog-title">
<div v-if="dialog.has_todo" class="todo">[{{$L('待办')}}]</div> <div v-if="dialog.todo_num" class="todo">[{{$L('待办')}}{{dialog.todo_num > 99 ? '99+' : dialog.todo_num}}]</div>
<div v-if="$A.getDialogMention(dialog) > 0" class="mention">[@{{$A.getDialogMention(dialog)}}]</div> <div v-if="$A.getDialogMention(dialog) > 0" class="mention">[@{{$A.getDialogMention(dialog)}}]</div>
<template v-for="tag in $A.dialogTags(dialog)" v-if="tag.color != 'success'"> <template v-for="tag in $A.dialogTags(dialog)" v-if="tag.color != 'success'">
<Tag :color="tag.color" :fade="false" @on-click="openDialog(dialog.id)">{{$L(tag.text)}}</Tag> <Tag :color="tag.color" :fade="false" @on-click="openDialog(dialog.id)">{{$L(tag.text)}}</Tag>
@ -216,8 +216,8 @@ export default {
if (a.top_at || b.top_at) { if (a.top_at || b.top_at) {
return $A.Date(b.top_at) - $A.Date(a.top_at); return $A.Date(b.top_at) - $A.Date(a.top_at);
} }
if (a.has_todo || b.has_todo) { if (a.todo_num > 0 || b.todo_num > 0) {
return (b.has_todo ? 1 : 0) - (a.has_todo ? 1 : 0); return b.todo_num - a.todo_num;
} }
return $A.Date(b.last_at) - $A.Date(a.last_at); return $A.Date(b.last_at) - $A.Date(a.last_at);
}); });
@ -279,8 +279,8 @@ export default {
if (a.top_at || b.top_at) { if (a.top_at || b.top_at) {
return $A.Date(b.top_at) - $A.Date(a.top_at); return $A.Date(b.top_at) - $A.Date(a.top_at);
} }
if (a.has_todo || b.has_todo) { if (a.todo_num > 0 || b.todo_num > 0) {
return (b.has_todo ? 1 : 0) - (a.has_todo ? 1 : 0); return b.todo_num - a.todo_num;
} }
return $A.Date(b.last_at) - $A.Date(a.last_at); return $A.Date(b.last_at) - $A.Date(a.last_at);
}) })

View File

@ -2042,14 +2042,14 @@ export default {
if ($A.arrayLength(data) > 0) { if ($A.arrayLength(data) > 0) {
dispatch("saveDialog", { dispatch("saveDialog", {
id: dialog_id, id: dialog_id,
has_todo: true todo_num: $A.arrayLength(data)
}); });
state.dialogTodos = state.dialogTodos.filter(item => item.dialog_id != dialog_id) state.dialogTodos = state.dialogTodos.filter(item => item.dialog_id != dialog_id)
dispatch("saveDialogTodo", data) dispatch("saveDialogTodo", data)
} else { } else {
dispatch("saveDialog", { dispatch("saveDialog", {
id: dialog_id, id: dialog_id,
has_todo: false todo_num: 0
}); });
} }
}).catch(console.warn); }).catch(console.warn);