ljc 1 месяц назад
Родитель
Сommit
005f4c47ac
3 измененных файлов с 15 добавлено и 37 удалено
  1. 4 1
      components/cwg-notice.vue
  2. 5 1
      components/cwg-page-wrapper.vue
  3. 6 35
      pages/mine/improveImmediately.vue

+ 4 - 1
components/cwg-notice.vue

@@ -34,7 +34,7 @@
 </template>
 
 <script setup lang="ts">
-import { computed, ref, onMounted } from 'vue'
+import { computed, ref, onMounted,onUnmounted } from 'vue'
 import { newsApi } from '@/service/news'
 import useRouter from "@/hooks/useRouter";
 import { useI18n } from 'vue-i18n'
@@ -105,6 +105,9 @@ onMounted(() => {
     getList()
   })
 })
+onUnmounted(() => {
+  uni.off('updateUnreadCount')
+})
 </script>
 
 <style scoped lang="scss">

+ 5 - 1
components/cwg-page-wrapper.vue

@@ -176,6 +176,10 @@ const initWebSocket = () => {
       if (data.newsType == 3) {
         pushRes(data)
       }
+      if (data.newsType == 1) {
+        // 认证更新文件信息
+        uni.$emit('updateImproveFile', data)
+      }
       if (data.newsType == 4) {
         // 全局广播未读消息数量更新
         uni.$emit('updateUnreadCount', data.count)
@@ -274,7 +278,7 @@ onUnmounted(() => {
   // 在组件销毁时移除事件监听器
   uni.$off('open-ib', handleOpenIb)
   uni.$off('open-right-drawer', handleOpenRightDrawer)
-  
+
   if (websock) {
     websock.close()
     websock = null

+ 6 - 35
pages/mine/improveImmediately.vue

@@ -1438,33 +1438,7 @@
     actionOtherAdd.value = Config.Host80 + '/custom/file/upload/10'
   }
 
-  // WebSocket
-  function initWebSocket() {
-    // 初始化WebSocket
-    let token = sessionStorage.getItem("access_token")
-    if (typeof WebSocket == 'undefined') {
-      uni.showToast({ title: t('Msg.socket'), icon: 'none' })
-    } else {
-      const wsUrl = HostWs.value + '/webSocket?Access-Token=' + token
-      websock.value = new WebSocket(wsUrl)
-      websock.value.onMessage = websocketonmessage
-      websock.value.onOpen = websocketonopen
-      websock.value.onError = websocketonerror
-      websock.value.onClose = websocketclose
-    }
-  }
-
-  function websocketonopen() {
-  }
-
-  function websocketonerror() {
-    initWebSocket()
-  }
-
-  function websocketonmessage(e: any) {
-    let data = JSON.parse(e.data)
-    if (data.newsType == 1) {
-      let myData = JSON.parse(e.data)
+  function updateFile(myData) {
       if (myData.type == 1) {
         fileListID1.value = myData
       } else if (myData.type == 2) {
@@ -1490,10 +1464,6 @@
         }
       }
       actionType()
-    }
-  }
-
-  function websocketclose() {
   }
 
   // 判断是否为PC端
@@ -1555,15 +1525,16 @@
     await getMobileInfo()
     await getCustomFileList()
     // WebSocket
-    initWebSocket()
+    // initWebSocket()
     isPC.value = IsPC()
+    uni.$on('updateImproveFile',(data)=>{
+      updateFile(data)
+    })
   })
 
   // 组件销毁时
   onUnmounted(() => {
-    if (websock.value) {
-      websock.value.close() // 离开路由之后断开WebSocket连接
-    }
+    uni.$off('updateImproveFile')
   })
 </script>