| | |
| | | }, |
| | | mounted() { |
| | | // this.getHubConnectionBuilder() |
| | | |
| | | }, |
| | | computed: { |
| | | ...mapGetters([ |
| | |
| | | // }, |
| | | // 建立hub连接 |
| | | async getHubConnectionBuilder() { |
| | | const url = 'http://121.196.36.24:8019/chatHub' |
| | | const url = 'http://121.196.36.24:8048/chatHub' |
| | | |
| | | // 本地开发 |
| | | // if (process.env.NODE_ENV === 'development') { |
| | | // url = 'http://121.196.36.24:8048/chatHub' |
| | | // } else { // 生产环境(关键!!!用相对路径,避免跨域/协议错误) |
| | | // url = '/chatHub' |
| | | // } |
| | | |
| | | this.signalr = new signalR.HubConnectionBuilder().withUrl(url, { |
| | | // skipNegotiation: true, |
| | | // transport: signalR.HttpTransportType.WebSockets |
| | | withCredentials: false, // 跨域需要 |
| | | skipNegotiation: true, |
| | | transport: signalR.HttpTransportType.WebSockets |
| | | }).configureLogging(signalR.LogLevel.Information).build() |
| | | |
| | | await this.signalr.start().then(() => { |
| | | if (window.Notification) { |
| | | if (Notification.permission === 'granted') { |
| | | console.log('允许通知') |
| | | } else if (Notification.permission !== 'denied') { |
| | | console.log('需要通知权限') |
| | | Notification.requestPermission((permission) => { |
| | | console.log('权限通知', permission) |
| | | }) |
| | | } else if (Notification.permission === 'denied') { |
| | | // console.log('拒绝通知') |
| | | } |
| | | } else { |
| | | console.error('浏览器不支持Notification') |
| | | } |
| | | // console.log('连接成功') |
| | | // if (window.Notification) { |
| | | // if (Notification.permission === 'granted') { |
| | | // console.log('允许通知') |
| | | // } else if (Notification.permission !== 'denied') { |
| | | // console.log('需要通知权限') |
| | | // Notification.requestPermission((permission) => { |
| | | // console.log('权限通知', permission) |
| | | // }) |
| | | // } else if (Notification.permission === 'denied') { |
| | | // console.log('拒绝通知') |
| | | // } |
| | | // } else { |
| | | // console.error('浏览器不支持Notification') |
| | | // } |
| | | console.log('连接成功') |
| | | }) |
| | | |
| | | this.signalr.off('SendCustomUserMessage') |
| | |
| | | this.$notify({ offset: 80, type: 'warning', title: '消息提醒', message: res }) |
| | | this.$store.state.settings.isDot = true |
| | | }) |
| | | await this.signalr.invoke('AddUser', getCookie('admin')) |
| | | await this.signalr.invoke('AddUser', localStorage.getItem('usercode')) |
| | | }, |
| | | |
| | | systemSetting() { |