ZaiZai 6 months ago
parent
commit
c2e1bd6b01
3 changed files with 47 additions and 1 deletions
  1. 39 1
      src/layout/index.vue
  2. 7 0
      src/store/index.js
  3. 1 0
      src/store/modules/user.js

+ 39 - 1
src/layout/index.vue

@@ -41,6 +41,7 @@
                 </div>
             </el-main>
         </el-container>
+        <hc-reminder v-model="isReminderShow" :text="isReminderText" />
     </el-container>
 </template>
 
@@ -196,7 +197,6 @@ const cascaderSend = async ({ projectId, contractId }) => {
 //长链接消息
 let annUpdateRef
 const annRefs = ref([])
-
 const socketData = async (res) => {
     console.log('socket:', res)
     const { type, data } = getObjValue(res)
@@ -217,6 +217,44 @@ const socketData = async (res) => {
         //普通公告,追加公告
         const ref = await HcAnnouncement({ type: 'system', data: data })
         annRefs.value.push(ref)
+    } else if (type === 'msgLink') {
+        if (store.isLogin) {
+            socket.send('getMsg')
+            store.setIsLogin(false)
+        }
+    } else if (type === 'msgCountDown') {
+        //倒计时更新
+        if (isNullES(data) || data <= 0) {
+            closeReminder()
+            return
+        }
+        isReminderText.value = `系统将在${data}秒后,进行更新`
+        setReminderText(data - 1)
+        isReminderShow.value = true
+    }
+}
+
+//倒计时
+let timeRef
+const isReminderShow = ref(false)
+const isReminderText = ref('')
+const setReminderText = (time) => {
+    if (time < 0) {
+        closeReminder()
+        return
+    }
+    timeRef = setTimeout(() => {
+        isReminderText.value = `系统将在${time}秒后,进行更新`
+        setReminderText(time - 1)
+    }, 1000)
+}
+
+//关闭倒计时
+const closeReminder = () => {
+    isReminderShow.value = false
+    if (!isNullES(timeRef)) {
+        clearTimeout(timeRef)
+        timeRef = null
     }
 }
 

+ 7 - 0
src/store/index.js

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

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

@@ -35,6 +35,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) {
         return { error: true, msg: '路由异常', res }