perf: 优化通知

This commit is contained in:
kuaifan 2022-02-12 09:50:02 +08:00
parent f7921bf388
commit 2fc039dd70
2 changed files with 44 additions and 36 deletions

View File

@ -337,6 +337,7 @@ export default {
'taskId',
'wsOpenNum',
'columnTemplate',
'dialogOpenId',
'themeMode',
'themeList',
@ -449,7 +450,7 @@ export default {
natificationHidden(val) {
clearTimeout(this.notificationTimeout);
if (!val) {
if (!val && this.notificationClass) {
this.notificationTimeout = setTimeout(() => {
this.notificationClass.close();
}, 6000);
@ -674,39 +675,44 @@ export default {
},
addDialogMsg(data) {
if (this.natificationHidden && this.natificationReady) {
const {id, dialog_id, type, msg} = data;
let body = '';
switch (type) {
case 'text':
body = msg.text;
break;
case 'file':
body = '[' + this.$L(msg.type == 'img' ? '图片信息' : '文件信息') + ']'
break;
default:
return;
}
this._notificationId = id;
this.notificationClass.replaceOptions({
icon: $A.originUrl('images/logo.png'),
body: body,
data: data,
tag: "dialog",
requireInteraction: true
});
let dialog = this.cacheDialogs.find((item) => item.id == dialog_id);
if (dialog) {
this.notificationClass.replaceTitle(dialog.name);
this.notificationClass.userAgreed();
} else {
this.$store.dispatch("getDialogOne", dialog_id).then(({data}) => {
if (this._notificationId === id) {
this.notificationClass.replaceTitle(data.name);
this.notificationClass.userAgreed();
}
}).catch(() => {})
}
if (!this.natificationReady) {
return;
}
if (!this.natificationHidden && this.curPath == "/manage/messenger" && this.dialogOpenId == data.dialog_id) {
return;
}
//
const {id, dialog_id, type, msg} = data;
let body = '';
switch (type) {
case 'text':
body = msg.text;
break;
case 'file':
body = '[' + this.$L(msg.type == 'img' ? '图片信息' : '文件信息') + ']'
break;
default:
return;
}
this._notificationId = id;
this.notificationClass.replaceOptions({
icon: $A.originUrl('images/logo.png'),
body: body,
data: data,
tag: "dialog",
requireInteraction: true
});
let dialog = this.cacheDialogs.find((item) => item.id == dialog_id);
if (dialog) {
this.notificationClass.replaceTitle(dialog.name);
this.notificationClass.userAgreed();
} else {
this.$store.dispatch("getDialogOne", dialog_id).then(({data}) => {
if (this._notificationId === id) {
this.notificationClass.replaceTitle(data.name);
this.notificationClass.userAgreed();
}
}).catch(() => {})
}
},

View File

@ -199,6 +199,10 @@ export default {
this.getContactsList(1);
}
},
dialogId(id) {
$A.setStorage("messenger::dialogId", id);
this.$store.state.dialogOpenId = id;
},
dialogOpenId(id) {
this.dialogId = id;
},
@ -247,11 +251,9 @@ export default {
closeDialog() {
this.dialogId = 0;
$A.setStorage("messenger::dialogId", 0)
},
openDialog(dialog, smooth) {
$A.setStorage("messenger::dialogId", dialog.id)
this.dialogId = dialog.id;
this.scrollIntoActive(smooth);
},