From 6eb098b9ea2673240e802e4aa460ddc67ec7d869 Mon Sep 17 00:00:00 2001 From: qx <1084500556@qq.com> Date: 星期二, 12 八月 2025 09:50:35 +0800 Subject: [PATCH] Merge branch 'master' of http://101.42.27.146:5001/r/ltkj_peisweb --- src/main.js | 115 ++++++++++++++++++++++++++++++++------------------------- 1 files changed, 65 insertions(+), 50 deletions(-) diff --git a/src/main.js b/src/main.js index e85e3f5..d44920f 100644 --- a/src/main.js +++ b/src/main.js @@ -150,58 +150,73 @@ 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(); -- Gitblit v1.8.0