update signalR.js

This commit is contained in:
不做码农 2022-06-05 19:03:00 +08:00
parent 43743ebe54
commit d1cc6bf15f

View File

@ -3,6 +3,7 @@ import * as signalR from '@microsoft/signalr'
import store from '../store' import store from '../store'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import { ElNotification } from 'element-plus' import { ElNotification } from 'element-plus'
import { useWebNotification } from '@vueuse/core'
export default { export default {
// signalR对象 // signalR对象
@ -12,7 +13,6 @@ export default {
baseUrl: '', baseUrl: '',
init(url) { init(url) {
var socketUrl = window.location.origin + url var socketUrl = window.location.origin + url
//console.log(socketUrl)
const connection = new signalR.HubConnectionBuilder() const connection = new signalR.HubConnectionBuilder()
.withUrl(socketUrl, { accessTokenFactory: () => getToken() }) .withUrl(socketUrl, { accessTokenFactory: () => getToken() })
.withAutomaticReconnect() //自动重新连接 .withAutomaticReconnect() //自动重新连接
@ -77,6 +77,16 @@ export default {
dangerouslyUseHTMLString: true, dangerouslyUseHTMLString: true,
duration: 0 duration: 0
}) })
const { show, isSupported } = useWebNotification({
title: data,
dir: 'auto',
lang: 'en',
renotify: true,
tag: 'tag',
})
if (isSupported) {
show()
}
}) })
// 接收系统通知/公告 // 接收系统通知/公告
connection.on("moreNotice", (data) => { connection.on("moreNotice", (data) => {