ZaiZai vor 1 Jahr
Ursprung
Commit
5d02fed0ac
2 geänderte Dateien mit 20 neuen und 6 gelöschten Zeilen
  1. 2 2
      src/config/index.json
  2. 18 4
      src/layout/index.vue

+ 2 - 2
src/config/index.json

@@ -2,8 +2,8 @@
     "version": "20230607160059",
     "target1": "http://127.0.0.1:8090",
     "target2": "http://192.168.0.125:8090",
-    "target3": "http://39.108.216.210:8090",
-    "target": "http://192.168.0.109:8090",
+    "target": "http://39.108.216.210:8090",
+    "target4": "http://192.168.0.109:8090",
     "smsPhone": "",
     "vite": {
         "port": 5180,

+ 18 - 4
src/layout/index.vue

@@ -47,6 +47,7 @@
 <script setup>
 import { nextTick, onMounted, ref, watch } from 'vue'
 import { useAppStore } from '~src/store'
+import { getToken } from '~src/api/auth'
 import { useRoute, useRouter } from 'vue-router'
 import { initButtons } from '~sto/app'
 import { isNullES } from 'js-fast-way'
@@ -134,12 +135,19 @@ const msgCount = ref({
 })
 
 //项目合同段的ID
-let times
+let times = ref()
 const cascaderSend = async ({ projectId, contractId }) => {
-    if (isNullES(contractId)) clearInterval(times)
+    //合同段id为空,清空定时器
+    if (isNullES(contractId)) {
+        if (!isNullES(times.value)) clearInterval(times.value)
+        return
+    }
+    //先获取一次
     await getUnreadMessage({ projectId, contractId })
-    if (!isNullES(times)) clearInterval(times)
-    times = setInterval(async () => {
+    //切换项目合同段时,先清空轮询
+    if (!isNullES(times.value)) clearInterval(times.value)
+    //定时轮询获取数据
+    times.value = setInterval(async () => {
         await getUnreadMessage({ projectId, contractId })
     }, 10000)
 }
@@ -147,6 +155,12 @@ const cascaderSend = async ({ projectId, contractId }) => {
 //获取未读消息数量
 const taskCount = ref(0)
 const getUnreadMessage = async ({ projectId, contractId }) => {
+    //如果退出登录了,清空轮询
+    if (isNullES(getToken())) {
+        if (!isNullES(times.value)) clearInterval(times.value)
+        return
+    }
+    //获取数据
     const { data } = await messageApi.getUnreadMessage({
         projectId, contractId,
     })