
Dingtalk_20230109142301.jpg
/** win10发通知*/
win10Info(info) {
console.log(info, '消息提示')
const notification = window.Notification || window.mozNotification || window.webkitNotification
if (notification) {
// 可以通过使用箭头函数变更this指向
notification.requestPermission(result => {
console.log(result) // granted(允许) || denied(拒绝)
if (result == 'denied') {
// console.warn('请授权浏览器通知!')
this.$message({
message: '请授权浏览器通知!',
type: 'warning'
});
} else {
const tag = 'tag' + new Date().getTime()
let itme = info; let name = null; let msg = null;
if (itme.file == undefined) {
name = itme._id.split(',')[0]
msg = itme.msg
} else {
name = itme.msg.split(',')[0]
msg = itme.file.name
}
const notify = new Notification(
name, // title标题
{
dir: 'auto', // 文字的方向;它的值可以是 auto(自动), ltr(从左到右), or rtl(从右到左)
lang: 'zh-CN', // 指定通知中所使用的语言
body: msg, // 通知中额外显示的字符串
tag: tag, // 赋予通知一个ID,以便在必要的时候对通知进行刷新、替换或移除
icon: '../../../../public/favicon.ico' // 将被用于显示通知的图标,可使用import引入,也可以填写图标存放路径
})
notify.onclick = () => {
console.info('click methods')
}
notify.onerror = () => {
console.error('error methods')
}
notify.onshow = () => {
console.log('show methods')
}
notify.onclose = () => {
console.info('close methods')
}
}
})
}
}
网友评论