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

View File

@ -120,10 +120,10 @@ class WebSocketDialog extends AbstractModel
break; break;
case "group": case "group":
if ($dialog->group_type === 'project') { 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 : ''; $dialog->name = $dialog->group_info ? $dialog->group_info->name : '';
} elseif ($dialog->group_type === 'task') { } 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 : ''; $dialog->name = $dialog->group_info ? $dialog->group_info->name : '';
} }
break; break;

View File

@ -315,6 +315,37 @@
return [new Date(), lastSecond(e.getTime())]; 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"> <slot name="head">
<div class="dialog-title"> <div class="dialog-title">
<div class="main-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> <h2>{{dialogData.name}}</h2>
<em v-if="peopleNum > 0">({{peopleNum}})</em> <em v-if="peopleNum > 0">({{peopleNum}})</em>
</div> </div>
@ -413,7 +414,7 @@ export default {
} }
}) })
} }
} },
} }
} }
</script> </script>

View File

@ -40,6 +40,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">
<Tag v-for="(tag, ti) in $A.dialogTags(dialog)" :key="`tag_${ti}`" :color="tag.color">{{$L(tag.text)}}</Tag>
<span>{{dialog.name}}</span> <span>{{dialog.name}}</span>
<Icon v-if="dialog.type == 'user' && lastMsgReadDone(dialog.last_msg)" :type="lastMsgReadDone(dialog.last_msg)"/> <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> <em v-if="dialog.last_at">{{$A.formatTime(dialog.last_at)}}</em>
@ -124,32 +125,24 @@ export default {
dialogList() { dialogList() {
const {dialogActive, dialogKey} = this; const {dialogActive, dialogKey} = this;
if (dialogActive == '' && dialogKey == '') { if (dialogActive == '' && dialogKey == '') {
return this.cacheDialogs.filter(({name, last_at}) => { return this.cacheDialogs.filter(dialog => this.filterDialog(dialog)).sort((a, b) => {
if (name === undefined) {
return false;
}
return last_at;
}).sort((a, b) => {
return $A.Date(b.last_at) - $A.Date(a.last_at); return $A.Date(b.last_at) - $A.Date(a.last_at);
}); });
} }
return this.cacheDialogs.filter(({name, type, group_type, last_msg, last_at}) => { return this.cacheDialogs.filter(dialog => {
if (name === undefined) { if (!this.filterDialog(dialog)) {
return false;
}
if (!last_at) {
return false; return false;
} }
if (dialogActive) { if (dialogActive) {
switch (dialogActive) { switch (dialogActive) {
case 'project': case 'project':
case 'task': case 'task':
if (group_type != dialogActive) { if (dialog.group_type != dialogActive) {
return false; return false;
} }
break; break;
case 'user': case 'user':
if (type != 'user') { if (dialog.type != 'user') {
return false; return false;
} }
break; break;
@ -158,8 +151,8 @@ export default {
} }
} }
if (dialogKey) { if (dialogKey) {
let existName = $A.strExists(name, dialogKey); let existName = $A.strExists(dialog.name, dialogKey);
let existMsg = last_msg && last_msg.type === 'text' && $A.strExists(last_msg.msg.text, dialogKey); let existMsg = dialog.last_msg && dialog.last_msg.type === 'text' && $A.strExists(dialog.last_msg.msg.text, dialogKey);
if (!existName && !existMsg) { if (!existName && !existMsg) {
return false; 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) { getContactsList(page) {
if (this.contactsData === null) { if (this.contactsData === null) {
this.contactsData = {}; this.contactsData = {};

View File

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