Bladeren bron

调用时机修改

zhengnaiwen_citu 11 maanden geleden
bovenliggende
commit
0281910836
3 gewijzigde bestanden met toevoegingen van 33 en 16 verwijderingen
  1. 11 11
      src/hooks/web/useIM.js
  2. 10 2
      src/layout/company/navBar.vue
  3. 12 3
      src/layout/personal/navBar.vue

+ 11 - 11
src/hooks/web/useIM.js

@@ -197,16 +197,8 @@ export const useIM = async () => {
   const IM = useIMStore()
   const unreadCount = ref(0)
   const connected = ref(0)
-  // 通过自身userId和企业id获取token和uid
-  const { uid, wsUrl, token } = await getKey()
-  IM.setUid(uid)
-  // 单机模式可以直接设置地址
-  WKSDK.shared().config.addr = 'ws://' + wsUrl // 默认端口为5200
-  // 认证信息
-  WKSDK.shared().config.uid = uid // 用户uid(需要在悟空通讯端注册过)
-  WKSDK.shared().config.token = token // 用户token (需要在悟空通讯端注册过)
   
-  // onMounted(() => {
+  onMounted(() => {
     // console.log('1')
     // 连接状态监听
     WKSDK.shared().connectManager.addConnectStatusListener(connectStatusListener)
@@ -216,7 +208,7 @@ export const useIM = async () => {
     // 连接
     // console.log('连接')
     WKSDK.shared().connectManager.connect()
-  // })
+  })
   onUnmounted(() => {
     WKSDK.shared().connectManager.removeConnectStatusListener(connectStatusListener)
     // 常规消息监听移除
@@ -224,7 +216,15 @@ export const useIM = async () => {
     // 连接状态监听移除
     WKSDK.shared().connectManager.disconnect()
   })
-
+  // 通过自身userId和企业id获取token和uid
+  const { uid, wsUrl, token } = await getKey()
+  IM.setUid(uid)
+  // 单机模式可以直接设置地址
+  WKSDK.shared().config.addr = 'ws://' + wsUrl // 默认端口为5200
+  // 认证信息
+  WKSDK.shared().config.uid = uid // 用户uid(需要在悟空通讯端注册过)
+  WKSDK.shared().config.token = token // 用户token (需要在悟空通讯端注册过)
+  
   async function messageListen (message) {
     console.log('收到消息', message)
     IM.setFromChannel(message.channel.channelID)

+ 10 - 2
src/layout/company/navBar.vue

@@ -27,7 +27,7 @@
           <div class="line"></div>
           
           <!-- 头像用户名 -->
-          <div class="d-flex align-center" v-if="getToken()">
+          <div class="d-flex align-center" v-if="showBall">
             <v-menu open-on-hover>
               <template v-slot:activator="{ props }">
                 <div class="d-flex ml-5 pl-2 align-center cursor-pointer" v-bind="props">
@@ -92,7 +92,7 @@ import {
   getUserBindEnterpriseList,
   getUserRegisterEnterpriseApply
 } from '@/api/personal/user'
-import { computed, ref } from 'vue'
+import { computed, ref, onMounted } from 'vue'
 import { getToken } from '@/utils/auth'
 import { useUserStore } from '@/store/user'; const userStore = useUserStore()
 // import { useLocaleStore } from '@/store/locale'; const localeStore = useLocaleStore()
@@ -108,6 +108,14 @@ defineProps({
   }
 })
 
+const showBall = ref(false)
+
+onMounted(() => {
+  if (getToken()) {
+    showBall.value = true
+  }
+})
+
 const handleLogoClick = () => { router.push({ path: '/recruit/enterprise'}) }
 
 const enterpriseClick = (tabKey = 1) => {

+ 12 - 3
src/layout/personal/navBar.vue

@@ -83,7 +83,7 @@
               </v-list-item>
             </v-list>
           </v-menu> -->
-          <div class="d-flex align-center" v-if="getToken()">
+          <div class="d-flex align-center" v-if="showBall">
             <!-- <span class="cursor-pointer mx-5" @click="router.push({ path: '/recruit/personal/TaskCenter' })">{{ $t('sys.signIn') }}</span> -->
             <!-- <span class="cursor-pointer" @click="router.push({ path: '/recruit/personal/message' })">{{ $t('sys.news') }}</span> -->
             <!-- <v-badge
@@ -93,7 +93,7 @@
             >
               <v-btn class="ml-1" size="small" icon="mdi-bell-outline" @click="router.push({ path: '/recruit/personal/message' })"></v-btn>
             </v-badge> -->
-            <message-notification v-if="getToken()"></message-notification>
+            <message-notification v-if="showBall"></message-notification>
             
           </div>
         </div>
@@ -110,7 +110,7 @@
 </template>
 
 <script setup>
-import { ref } from 'vue'
+import { onMounted, ref } from 'vue'
 import { getToken } from '@/utils/auth'
 import { useUserStore } from '@/store/user'
 // import { useLocaleStore } from '@/store/locale'
@@ -119,6 +119,7 @@ import CtDialog from '@/components/CtDialog'
 import { useRouter } from 'vue-router'; const router = useRouter()
 import { getUserBindEnterpriseList, getUserRegisterEnterpriseApply } from '@/api/personal/user'
 import MessageNotification from './message.vue'
+
 // import { useIMStore } from '@/store/im'
 defineOptions({ name: 'personal-navbar' })
 
@@ -129,6 +130,14 @@ defineProps({
   }
 })
 
+const showBall = ref(false)
+
+onMounted(() => {
+  if (getToken()) {
+    showBall.value = true
+  }
+})
+
 // const useIM = useIMStore()
 
 const { t } = useI18n()