桌面通知

This commit is contained in:
kuaifan 2021-06-24 20:31:21 +08:00
parent a2d807a8be
commit 6356c99543
6 changed files with 95 additions and 2 deletions

View File

@ -37,6 +37,7 @@
"dependencies": { "dependencies": {
"echarts": "^5.1.1", "echarts": "^5.1.1",
"element-ui": "^2.15.2", "element-ui": "^2.15.2",
"notification-koro1": "^1.1.1",
"tinymce": "^5.8.1", "tinymce": "^5.8.1",
"tui-calendar-hi": "^1.13.0-5", "tui-calendar-hi": "^1.13.0-5",
"view-design-hi": "^4.6.1-1", "view-design-hi": "^4.6.1-1",

View File

@ -124,6 +124,7 @@
import { mapState, mapGetters } from 'vuex' import { mapState, mapGetters } from 'vuex'
import TaskDetail from "./manage/components/TaskDetail"; import TaskDetail from "./manage/components/TaskDetail";
import ProjectArchived from "./manage/components/ProjectArchived"; import ProjectArchived from "./manage/components/ProjectArchived";
import notificationKoro from "notification-koro1";
export default { export default {
components: {ProjectArchived, TaskDetail}, components: {ProjectArchived, TaskDetail},
@ -153,12 +154,19 @@ export default {
openMenu: {}, openMenu: {},
archivedProjectShow: false, archivedProjectShow: false,
natificationHidden: false,
natificationReady: false,
notificationClass: null,
} }
}, },
mounted() { mounted() {
this.$store.dispatch("getUserInfo"); this.$store.dispatch("getUserInfo");
this.$store.dispatch("getTaskPriority"); this.$store.dispatch("getTaskPriority");
//
this.notificationInit();
this.onVisibilityChange();
}, },
deactivated() { deactivated() {
@ -173,6 +181,7 @@ export default {
'dialogs', 'dialogs',
'projects', 'projects',
'taskId', 'taskId',
'dialogMsgPush',
]), ]),
...mapGetters(['taskData']), ...mapGetters(['taskData']),
@ -189,6 +198,34 @@ export default {
watch: { watch: {
'$route' (route) { '$route' (route) {
this.curPath = route.path; this.curPath = route.path;
},
dialogMsgPush(data) {
if (this.natificationHidden && this.natificationReady) {
const {userid, 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.$store.dispatch("getUserBasic", {
userid: userid,
success: (user) => {
this.notificationClass.replaceTitle(user.nickname);
this.notificationClass.replaceOptions({
icon: user.userimg,
body: body,
requireInteraction: true
});
this.notificationClass.userAgreed();
}
});
}
} }
}, },
@ -277,6 +314,56 @@ export default {
if (!visible) { if (!visible) {
this.$store.dispatch('openTask', 0) this.$store.dispatch('openTask', 0)
} }
},
notificationInit() {
this.notificationClass = new notificationKoro(this.$L("打开通知成功"));
if (this.notificationClass.support) {
this.notificationClass.notificationEvent({
onclick: () => {
window.focus();
this.notificationClass.close();
this.goForward({path: '/manage/messenger'});
this.$store.dispatch("openDialogUserid", this.dialogMsgPush.userid);
},
});
this.notificationPermission();
}
},
notificationPermission() {
const userSelectFn = msg => {
switch (msg) {
//
case 'already granted':
case 'granted':
return this.natificationReady = true;
//
case 'close':
return this.notificationClass.initNotification(userSelectFn);
// ||
case 'denied':
case 'already denied':
if (msg === "denied") {
console.log("您刚刚拒绝显示通知 请在设置中更改设置");
} else {
console.log("您曾级拒绝显示通知 请在设置中更改设置");
}
break;
}
};
this.notificationClass.initNotification(userSelectFn);
},
onVisibilityChange() {
let hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null;
let visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
let visibilityChangeListener = () => {
this.natificationHidden = !!document[hiddenProperty]
}
document.addEventListener(visibilityChangeEvent, visibilityChangeListener);
} }
} }
} }

View File

@ -100,7 +100,7 @@ export default {
}, },
computed: { computed: {
...mapState(['userId', 'dialogs']), ...mapState(['userId', 'dialogs', 'dialogOpenId']),
dialogList() { dialogList() {
const {dialogActive, dialogKey} = this; const {dialogActive, dialogKey} = this;
@ -145,6 +145,10 @@ export default {
if (val && this.contactsLists === null) { if (val && this.contactsLists === null) {
this.getContactsList(); this.getContactsList();
} }
},
dialogOpenId(id) {
this.$store.state.method.setStorage("messenger::dialogId", id)
this.dialogId = id;
} }
}, },

View File

@ -1127,8 +1127,8 @@ export default {
userid, userid,
}, },
}).then(result => { }).then(result => {
state.method.setStorage("messengerDialogId", result.data.id)
dispatch("saveDialog", result.data); dispatch("saveDialog", result.data);
state.dialogOpenId = result.data.id;
resolve(result); resolve(result);
}).catch(e => { }).catch(e => {
console.error(e); console.error(e);

View File

@ -259,6 +259,7 @@ state.userOnline = {};
state.dialogs = []; state.dialogs = [];
state.dialogMsgs = []; state.dialogMsgs = [];
state.dialogMsgPush = {}; state.dialogMsgPush = {};
state.dialogOpenId = 0;
// 项目任务 // 项目任务
state.projectId = 0; state.projectId = 0;

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB