qx
5 天以前 6eb098b9ea2673240e802e4aa460ddc67ec7d869
src/main.js
@@ -152,7 +152,14 @@
  render: (h) => h(App),
 mounted() {
    const token = store.state.user.token || Cookies.get('token') || '';
    if (token && !isWebSocketInitialized) {
  if (token) {
    // 调用 getConfigKey 接口,检查 xxtz 配置
    getConfigKey('xxtz').then(res => {
      console.log('getConfigKey 返回结果:', res); // 调试:记录接口响应
      if (res.msg === 'Y') {
        // 消息通知功能开启
        console.log('消息通知功能已启用');
        if (!isWebSocketInitialized) {
      console.log('初始化 WebSocket,Token:', token);
      isWebSocketInitialized = true;
      initWebSocket(token, (type, data) => {
@@ -189,18 +196,26 @@
            }
          } else {
            console.log('WebSocket 非 JSON 消息:', data);
          }
        } catch (error) {
          console.error('消息解析失败:', error, '原始数据:', data);
          Vue.prototype.$showNotification.call(this, 'error', '消息解析失败', `服务器回应字符串: ${data}`);
        }
      });
    } else if (!token) {
      console.error('未找到 token,无法初始化 WebSocket');
    } else {
      console.log('WebSocket 已初始化,跳过重复连接');
    }
      } else {
        console.log('消息通知功能未启用 (xxtz: N)');
      }
    }).catch(error => {
      console.error('调用 getConfigKey 失败:', error);
      // 可选:根据需求处理接口调用失败的情况
      Vue.prototype.$showNotification.call(this, 'error', '配置获取失败', '无法获取消息通知配置');
    });
  } else {
    console.error('未找到 token,无法初始化 WebSocket');
  }
  },
  beforeDestroy() {
    if (isWebSocketInitialized) {