perf: 消息列表显示任务基本状态

This commit is contained in:
kuaifan 2022-01-23 16:17:11 +08:00
parent 493cf7d46a
commit 9b0ca581f1
6 changed files with 100 additions and 18 deletions

View File

@ -18,6 +18,7 @@ use Illuminate\Support\Facades\DB;
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel saveOrIgnore()
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel getKeyValue()
* @method static \Illuminate\Database\Eloquent\Model|object|static|null cancelAppend()
* @method static \Illuminate\Database\Eloquent\Model|object|static|null cancelHidden()
* @method static \Illuminate\Database\Eloquent\Builder|static with($relations)
* @method static \Illuminate\Database\Query\Builder|static select($columns = [])
* @method static \Illuminate\Database\Query\Builder|static whereNotIn($column, $values, $boolean = 'and')
@ -72,6 +73,15 @@ class AbstractModel extends Model
return $this->setAppends([]);
}
/**
* 取消隐藏值
* @return static
*/
protected function scopeCancelHidden()
{
return $this->setHidden([]);
}
/**
* 为数组 / JSON 序列化准备日期。
* @param DateTimeInterface $date

View File

@ -120,10 +120,10 @@ class WebSocketDialog extends AbstractModel
break;
case "group":
if ($dialog->group_type === 'project') {
$dialog->group_info = Project::withTrashed()->select(['id', 'name'])->whereDialogId($dialog->id)->first();
$dialog->group_info = Project::withTrashed()->select(['id', 'name', 'archived_at', 'deleted_at'])->whereDialogId($dialog->id)->first()?->cancelAppend()->cancelHidden();
$dialog->name = $dialog->group_info ? $dialog->group_info->name : '';
} elseif ($dialog->group_type === 'task') {
$dialog->group_info = ProjectTask::withTrashed()->select(['id', 'name'])->whereDialogId($dialog->id)->first();
$dialog->group_info = ProjectTask::withTrashed()->select(['id', 'name', 'complete_at', 'archived_at', 'deleted_at'])->whereDialogId($dialog->id)->first()?->cancelAppend()->cancelHidden();
$dialog->name = $dialog->group_info ? $dialog->group_info->name : '';
}
break;

View File

@ -315,6 +315,37 @@
return [new Date(), lastSecond(e.getTime())];
}
}];
},
/**
* 对话标签
* @param dialog
* @returns {*[]}
*/
dialogTags(dialog) {
let tags = [];
if (dialog.type == 'group') {
if (['project', 'task'].includes(dialog.group_type) && $A.isJson(dialog.group_info)) {
if (dialog.group_type == 'task' && dialog.group_info.complete_at) {
tags.push({
color: 'success',
text: '已完成'
})
}
if (dialog.group_info.deleted_at) {
tags.push({
color: 'error',
text: '已删除'
})
} else if (dialog.group_info.archived_at) {
tags.push({
color: 'default',
text: '已归档'
})
}
}
}
return tags;
}
});

View File

@ -8,6 +8,7 @@
<slot name="head">
<div class="dialog-title">
<div class="main-title">
<Tag v-for="(tag, ti) in $A.dialogTags(dialogData)" :key="`tag_${ti}`" :color="tag.color">{{$L(tag.text)}}</Tag>
<h2>{{dialogData.name}}</h2>
<em v-if="peopleNum > 0">({{peopleNum}})</em>
</div>
@ -413,7 +414,7 @@ export default {
}
})
}
}
},
}
}
</script>

View File

@ -40,6 +40,7 @@
<Icon v-else class="icon-avatar" type="md-person" />
<div class="dialog-box">
<div class="dialog-title">
<Tag v-for="(tag, ti) in $A.dialogTags(dialog)" :key="`tag_${ti}`" :color="tag.color">{{$L(tag.text)}}</Tag>
<span>{{dialog.name}}</span>
<Icon v-if="dialog.type == 'user' && lastMsgReadDone(dialog.last_msg)" :type="lastMsgReadDone(dialog.last_msg)"/>
<em v-if="dialog.last_at">{{$A.formatTime(dialog.last_at)}}</em>
@ -124,32 +125,24 @@ export default {
dialogList() {
const {dialogActive, dialogKey} = this;
if (dialogActive == '' && dialogKey == '') {
return this.cacheDialogs.filter(({name, last_at}) => {
if (name === undefined) {
return false;
}
return last_at;
}).sort((a, b) => {
return this.cacheDialogs.filter(dialog => this.filterDialog(dialog)).sort((a, b) => {
return $A.Date(b.last_at) - $A.Date(a.last_at);
});
}
return this.cacheDialogs.filter(({name, type, group_type, last_msg, last_at}) => {
if (name === undefined) {
return false;
}
if (!last_at) {
return this.cacheDialogs.filter(dialog => {
if (!this.filterDialog(dialog)) {
return false;
}
if (dialogActive) {
switch (dialogActive) {
case 'project':
case 'task':
if (group_type != dialogActive) {
if (dialog.group_type != dialogActive) {
return false;
}
break;
case 'user':
if (type != 'user') {
if (dialog.type != 'user') {
return false;
}
break;
@ -158,8 +151,8 @@ export default {
}
}
if (dialogKey) {
let existName = $A.strExists(name, dialogKey);
let existMsg = last_msg && last_msg.type === 'text' && $A.strExists(last_msg.msg.text, dialogKey);
let existName = $A.strExists(dialog.name, dialogKey);
let existMsg = dialog.last_msg && dialog.last_msg.type === 'text' && $A.strExists(dialog.last_msg.msg.text, dialogKey);
if (!existName && !existMsg) {
return false;
}
@ -276,6 +269,44 @@ export default {
});
},
filterDialog(dialog) {
if (dialog.unread > 0 || dialog.id == this.dialogId) {
return true
}
if (dialog.name === undefined) {
return false;
}
if (!dialog.last_at) {
return false;
}
if (dialog.type == 'group') {
if (['project', 'task'].includes(dialog.group_type) && $A.isJson(dialog.group_info)) {
if (dialog.group_type == 'task' && dialog.group_info.complete_at) {
// 5
let time = Math.max($A.Date(dialog.last_at, true), $A.Date(dialog.group_info.complete_at, true))
if (5 * 86400 + time < $A.Time()) {
return false
}
}
if (dialog.group_info.deleted_at) {
// 3
let time = Math.max($A.Date(dialog.last_at, true), $A.Date(dialog.group_info.deleted_at, true))
if (3 * 86400 + time < $A.Time()) {
return false
}
}
if (dialog.group_info.archived_at) {
// 7
let time = Math.max($A.Date(dialog.last_at, true), $A.Date(dialog.group_info.archived_at, true))
if (7 * 86400 + time < $A.Time()) {
return false
}
}
}
}
return true;
},
getContactsList(page) {
if (this.contactsData === null) {
this.contactsData = {};

View File

@ -124,6 +124,15 @@
align-items: center;
justify-content: space-between;
line-height: 24px;
.ivu-tag {
padding: 0 5px;
&.ivu-tag-error,
&.ivu-tag-primary,
&.ivu-tag-success,
&.ivu-tag-warning {
padding: 0 6px;
}
}
> span {
flex: 1;
color: #333333;