ZaiZai 11 tháng trước cách đây
mục cha
commit
62a939c108
5 tập tin đã thay đổi với 19 bổ sung2 xóa
  1. 1 1
      public/version.json
  2. 5 0
      src/layout/index.vue
  3. 5 1
      src/plugins/HcSocket.js
  4. 7 0
      src/store/index.js
  5. 1 0
      src/store/modules/user.js

+ 1 - 1
public/version.json

@@ -1,3 +1,3 @@
 {
-  "value": "20240905161803"
+  "value": "20240905164148"
 }

+ 5 - 0
src/layout/index.vue

@@ -199,6 +199,11 @@ const socketData = async (res) => {
         annRefs.value.push(ref)
     } else if (type === 'msgRemind') {
         taskCount.value = data ?? 0
+    } else if (type === 'msgLink') {
+        if (store.isLogin) {
+            socket.send('getMsg')
+            store.setIsLogin(false)
+        }
     }
     //倒计时更新
     //isReminderText.value = '系统将在xx秒后,进行更新'

+ 5 - 1
src/plugins/HcSocket.js

@@ -4,11 +4,12 @@ import { getObjValue, isNullES } from 'js-fast-way'
 // 长链接推送插件
 class HcSocket {
 
-    constructor(data, change) {
+    constructor(data, change, open) {
         this.limit = website.socketLimit
         this.interval = website.socketInterval
         this.param = getObjValue(data)
         this.onChange = change
+        this.onSocketOpen = open
         this.socket = null
         this.isReconnecting = false
         this.connectionStatus = 'disconnected'
@@ -43,6 +44,9 @@ class HcSocket {
         console.log('WebSocket 链接成功')
         this.connectionStatus = 'connected'
         this.isManualClosed = false
+        if (typeof this.onSocketOpen === 'function' && this.onSocketOpen) {
+            this.onSocketOpen()
+        }
     }
 
     handleClose() {

+ 7 - 0
src/store/index.js

@@ -39,6 +39,7 @@ export const useAppStore = defineStore('main', {
         barMenuName: '',
         isSource: getStoreValue('isSource') || '', //来源
         isLayout: getStoreValue('isLayout') || '', //是否显示layout
+        isLogin: getStoreValue('isLogin') || false, //是否刚登录
     }),
     getters: {
         //系统信息
@@ -70,6 +71,7 @@ export const useAppStore = defineStore('main', {
         getDragModalSortTop: state => state.dragModalSortTop,
         getIsSource: state => state.isSource,
         getIsLayout: state => state.isLayout,
+        getIsLogin: state => state.isLogin,
     },
     actions: {
         //系统信息
@@ -174,6 +176,10 @@ export const useAppStore = defineStore('main', {
             this.isLayout = value
             setStoreValue('isLayout', value)
         },
+        setIsLogin(value) {
+            this.isLogin = value
+            setStoreValue('isLogin', value)
+        },
         //清除缓存和token
         clearStoreData() {
             //清除状态
@@ -195,6 +201,7 @@ export const useAppStore = defineStore('main', {
             this.dragModalSortTop = []
             this.isSource = ''
             this.isLayout = ''
+            this.isLogin = null
             //清除缓存
             clearStoreAll()
             removeToken()

+ 1 - 0
src/store/modules/user.js

@@ -34,6 +34,7 @@ export const setUserAppInfo = async (res) => {
     store.setRefreshTokenVal(res['refresh_token'])
     store.setTenantId(res['tenant_id'])
     store.setUserInfo(res)
+    store.setIsLogin(true)
     //获取路由菜单
     const routerRes = await setRouterData()
     if (routerRes.length <= 0) {