From a95990a4d6022e2d854a33fbc4c3396409854e08 Mon Sep 17 00:00:00 2001
From: qx <1084500556@qq.com>
Date: 星期五, 15 八月 2025 17:33:50 +0800
Subject: [PATCH] qx

---
 src/main.js |  132 ++++++++++++++++++++++++-------------------
 1 files changed, 74 insertions(+), 58 deletions(-)

diff --git a/src/main.js b/src/main.js
index 6aee2e6..d44920f 100644
--- a/src/main.js
+++ b/src/main.js
@@ -17,7 +17,7 @@
 import "./assets/icons";
 import "./permission";
 import { getDicts } from "@/api/system/dict/data";
-import { getConfigKey } from "@/api/system/config";
+import { getConfigKey,yidu } from "@/api/system/config";
 import {
   parseTime,
   resetForm,
@@ -36,7 +36,7 @@
 import DictData from "@/components/DictData";
 import * as echarts from "echarts";
 import VueBarcode from "vue-barcode";
-// import { initWebSocket, closeWebSocket } from "@/utils/websocket";
+import { initWebSocket, closeWebSocket } from "@/utils/websocket";
 import RightToolbar from "@/components/RightToolbar"
 
 // 娉ㄥ唽鍏ㄥ眬缁勪欢
@@ -63,7 +63,7 @@
 Vue.prototype.$echarts = echarts;
 
 // 閫氱煡绠$悊锛氳窡韪綋鍓嶉�氱煡鍜屽亸绉婚噺
-/* const notificationManager = {
+const notificationManager = {
   notifications: [], // 瀛樺偍褰撳墠鏄剧ず鐨勯�氱煡瀹炰緥
   baseOffset: 50, // 鍩虹鍋忕Щ閲�
   notificationHeight: 80, // 姣忎釜閫氱煡鐨勪及璁¢珮搴︼紙鍖呮嫭闂磋窛锛�
@@ -94,10 +94,10 @@
       notification.customClass = notification.customClass.replace(/notification-\d+/, `notification-${index + 1}`);
     });
   }
-}; */
+};
 
 // 鍏ㄥ眬閫氱煡鏂规硶锛屾坊鍔犫�滃凡璇烩�濇寜閽�
-/* Vue.prototype.$showNotification = function (type, title, message, onClick, noticeId) {
+ Vue.prototype.$showNotification = function (type, title, message, onClick, noticeId) {
   console.log('瑙﹀彂閫氱煡:', { type, title, message, noticeId, noticeIdType: typeof noticeId }); // 璋冭瘯锛氳褰� noticeId 鍜岀被鍨�
   const h = this.$createElement;
   const notification = this.$notify({
@@ -134,7 +134,8 @@
     appendTo: document.body
   });
   notificationManager.addNotification(notification); // 娣诲姞鍒伴�氱煡绠$悊
-}; */
+};
+
 
 // 鐩戝惉璺敱鍙樺寲
 router.afterEach(() => {
@@ -142,72 +143,87 @@
 });
 
 // 瀹氫箟 WebSocket 鍒濆鍖栨爣蹇楋紝闃叉閲嶅杩炴帴
-// let isWebSocketInitialized = false;
+let isWebSocketInitialized = false;
 
 const app = new Vue({
   el: "#app",
   router,
   store,
   render: (h) => h(App),
-  /* mounted() {
-    const token = store.state.user.token || Cookies.get('token') || '';
-    if (token && !isWebSocketInitialized) {
-      console.log('鍒濆鍖� WebSocket锛孴oken:', token);
-      isWebSocketInitialized = true;
-      initWebSocket(token, (type, data) => {
-        console.log('WebSocket 鏀跺埌娑堟伅:', { type, data }); // 璋冭瘯锛氳褰曞師濮嬫暟鎹�
-        if (type === 'error') {
-          Vue.prototype.$showNotification.call(this, 'error', '閿欒', data);
-          return;
-        }
-        try {
-          if (typeof data === 'string' && data.trim().startsWith('{')) {
-            // 鏇挎崲澶ф暣鏁板瓧娈碉紝闃叉绮惧害涓㈠け
-            const normalizedData = data.replace(/"(noticeId|notice_id|id)":\s*(\d+)/g, '"$1":"$2"');
-            const message = JSON.parse(normalizedData);
-            console.log('WebSocket 瑙f瀽鍚庢秷鎭�:', message); // 璋冭瘯锛氳褰曡В鏋愬悗鐨勬秷鎭�
-            if (message.noticeId || message.notice_id || message.id) {
-              const noticeTypeLabel = message.noticeType === '1' ? '閫氱煡' : '鍏憡';
-              const noticeTitle = message.noticeTitle ? message.noticeTitle.replace(/<[^>]+>/g, '') : '鏃犳爣棰�';
-              const contentPreview = message.noticeContent
-                ? message.noticeContent.replace(/<[^>]+>/g, '').substring(0, 20) + '...'
-                : '鏃犲唴瀹�';
-              const noticeId = String(message.noticeId || message.notice_id || message.id);
-              console.log('鍑嗗瑙﹀彂閫氱煡锛宯oticeId:', noticeId, 'type:', typeof noticeId); // 璋冭瘯锛氳褰曚紶閫掔殑 noticeId
-              Vue.prototype.$showNotification.call(
-                this,
-                'success',
-                `鏂�${noticeTypeLabel}`,
-                `${noticeTitle} - ${contentPreview}`,
-                null,
-                noticeId
-              );
-            } else {
-              console.log('鏈煡娑堟伅绫诲瀷:', message);
-              Vue.prototype.$showNotification.call(this, 'info', '娑堟伅', '鏀跺埌鏈煡鏍煎紡鐨勬秷鎭�');
+  mounted() {
+  const token = store.state.user.token || Cookies.get('token') || '';
+  if (token) {
+    // 璋冪敤 getConfigKey 鎺ュ彛锛屾鏌� xxtz 閰嶇疆
+    getConfigKey('xxtz').then(res => {
+      console.log('getConfigKey 杩斿洖缁撴灉:', res); // 璋冭瘯锛氳褰曟帴鍙e搷搴�
+      if (res.msg === 'Y') {
+        // 娑堟伅閫氱煡鍔熻兘寮�鍚�
+        console.log('娑堟伅閫氱煡鍔熻兘宸插惎鐢�');
+        if (!isWebSocketInitialized) {
+          console.log('鍒濆鍖� WebSocket锛孴oken:', token);
+          isWebSocketInitialized = true;
+          initWebSocket(token, (type, data) => {
+            console.log('WebSocket 鏀跺埌娑堟伅:', { type, data }); // 璋冭瘯锛氳褰曞師濮嬫暟鎹�
+            if (type === 'error') {
+              Vue.prototype.$showNotification.call(this, 'error', '閿欒', data);
+              return;
             }
-          } else {
-            console.log('WebSocket 闈� JSON 娑堟伅:', data);
-   
-          }
-        } catch (error) {
-          console.error('娑堟伅瑙f瀽澶辫触:', error, '鍘熷鏁版嵁:', data);
-          Vue.prototype.$showNotification.call(this, 'error', '娑堟伅瑙f瀽澶辫触', `鏈嶅姟鍣ㄥ洖搴斿瓧绗︿覆: ${data}`);
+            try {
+              if (typeof data === 'string' && data.trim().startsWith('{')) {
+                // 鏇挎崲澶ф暣鏁板瓧娈碉紝闃叉绮惧害涓㈠け
+                const normalizedData = data.replace(/"(noticeId|notice_id|id)":\s*(\d+)/g, '"$1":"$2"');
+                const message = JSON.parse(normalizedData);
+                console.log('WebSocket 瑙f瀽鍚庢秷鎭�:', message); // 璋冭瘯锛氳褰曡В鏋愬悗鐨勬秷鎭�
+                if (message.noticeId || message.notice_id || message.id) {
+                  const noticeTypeLabel = message.noticeType === '1' ? '閫氱煡' : '鍏憡';
+                  const noticeTitle = message.noticeTitle ? message.noticeTitle.replace(/<[^>]+>/g, '') : '鏃犳爣棰�';
+                  const contentPreview = message.noticeContent
+                    ? message.noticeContent.replace(/<[^>]+>/g, '').substring(0, 20) + '...'
+                    : '鏃犲唴瀹�';
+                  const noticeId = String(message.noticeId || message.notice_id || message.id);
+                  console.log('鍑嗗瑙﹀彂閫氱煡锛宯oticeId:', noticeId, 'type:', typeof noticeId); // 璋冭瘯锛氳褰曚紶閫掔殑 noticeId
+                  Vue.prototype.$showNotification.call(
+                    this,
+                    'success',
+                    `鏂�${noticeTypeLabel}`,
+                    `${noticeTitle} - ${contentPreview}`,
+                    null,
+                    noticeId
+                  );
+                } else {
+                  console.log('鏈煡娑堟伅绫诲瀷:', message);
+                  Vue.prototype.$showNotification.call(this, 'info', '娑堟伅', '鏀跺埌鏈煡鏍煎紡鐨勬秷鎭�');
+                }
+              } else {
+                console.log('WebSocket 闈� JSON 娑堟伅:', data);
+              }
+            } catch (error) {
+              console.error('娑堟伅瑙f瀽澶辫触:', error, '鍘熷鏁版嵁:', data);
+              Vue.prototype.$showNotification.call(this, 'error', '娑堟伅瑙f瀽澶辫触', `鏈嶅姟鍣ㄥ洖搴斿瓧绗︿覆: ${data}`);
+            }
+          });
+        } else {
+          console.log('WebSocket 宸插垵濮嬪寲锛岃烦杩囬噸澶嶈繛鎺�');
         }
-      });
-    } else if (!token) {
-      console.error('鏈壘鍒� token锛屾棤娉曞垵濮嬪寲 WebSocket');
-    } else {
-      console.log('WebSocket 宸插垵濮嬪寲锛岃烦杩囬噸澶嶈繛鎺�');
-    }
-  },
+      } else {
+        console.log('娑堟伅閫氱煡鍔熻兘鏈惎鐢� (xxtz: N)');
+      }
+    }).catch(error => {
+      console.error('璋冪敤 getConfigKey 澶辫触:', error);
+      // 鍙�夛細鏍规嵁闇�姹傚鐞嗘帴鍙h皟鐢ㄥけ璐ョ殑鎯呭喌
+      Vue.prototype.$showNotification.call(this, 'error', '閰嶇疆鑾峰彇澶辫触', '鏃犳硶鑾峰彇娑堟伅閫氱煡閰嶇疆');
+    });
+  } else {
+    console.error('鏈壘鍒� token锛屾棤娉曞垵濮嬪寲 WebSocket');
+  }
+},
   beforeDestroy() {
     if (isWebSocketInitialized) {
       closeWebSocket();
       isWebSocketInitialized = false;
       console.log('Vue 瀹炰緥閿�姣侊紝WebSocket 宸叉竻鐞�');
     }
-  } */
+  }
 });
 
 // 娉ㄥ唽鎻掍欢

--
Gitblit v1.8.0