Explorar el Código

feat:socket

ljc hace 1 mes
padre
commit
3698a1859b
Se han modificado 1 ficheros con 3 adiciones y 5 borrados
  1. 3 5
      components/cwg-page-wrapper.vue

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

@@ -64,6 +64,7 @@ import { userToken } from "@/composables/config";
 import { useI18n } from 'vue-i18n'
 import Config from '@/config/index'
 import { customApi } from '@/service/custom'
+import tool from "@/global/tool"
 
 const { t, locale } = useI18n()
 const globalStore = useGlobalStore()
@@ -143,17 +144,14 @@ const initWebSocket = () => {
   let token = userToken.value || uni.getStorageSync('token')
   if (!token) return
   
-  // 模拟 tool.tokenReplace 移除 Bearer
-  if (token.startsWith('Bearer ')) {
-    token = token.replace('Bearer ', '')
-  }
+  token = tool.tokenReplace(token);
 
   const wsUrl = `${Config.HostWs}/webSocket?Access-Token=${token}`
 
   websock = uni.connectSocket({
     url: wsUrl,
     success: () => {
-      // console.log('WebSocket connected successfully')
+      console.log('WebSocket connected successfully')
     },
     fail: () => {
       uni.showToast({ title: t('Msg.socket'), icon: 'none' })