小小儁爺
2026-05-15 df418a35e80167ae120e5840d6ff8d19676ee399
src/layout/components/Navbar.vue
@@ -268,7 +268,7 @@
    // Vue.prototype.$ButtonData = JSON.parse(localStorage.getItem('ButtonData'))
  },
  mounted() {
    this.getHubConnectionBuilder()
    // this.getHubConnectionBuilder()
  },
  computed: {
    ...mapGetters([
@@ -313,27 +313,36 @@
    // 建立hub连接
    async getHubConnectionBuilder() {
      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') {
        // 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('连接成功')
        //   }
        // } else {
        //   console.error('浏览器不支持Notification')
        // }
        console.log('连接成功')
      })
      this.signalr.off('SendCustomUserMessage')
@@ -341,7 +350,7 @@
        this.$notify({ offset: 80, type: 'warning', title: '消息提醒', message: res })
        this.$store.state.settings.isDot = true
      })
      await this.signalr.invoke('AddUser', localStorage.getItem('account'))
      await this.signalr.invoke('AddUser', localStorage.getItem('usercode'))
    },
    systemSetting() {