Prechádzať zdrojové kódy

沟通数据获取调整

Xiao_123 2 mesiacov pred
rodič
commit
f8908934a7
4 zmenil súbory, kde vykonal 15 pridanie a 21 odobranie
  1. 3 3
      custom-tab-bar/index.js
  2. 0 1
      hooks/useIM.js
  3. 10 4
      pages/index/communicate.vue
  4. 2 13
      store/user.js

+ 3 - 3
custom-tab-bar/index.js

@@ -36,12 +36,12 @@ Component({
   },
   methods: {
     switchTab(e) {
-      const data = e.currentTarget.dataset
+			const data = e.currentTarget.dataset
       wx.switchTab({
-        url: data.path
+				url: data.path
       })
       this.setData({  
-        selected: data.index  
+				selected: data.index  
       })
     }
   }

+ 0 - 1
hooks/useIM.js

@@ -84,7 +84,6 @@ const ConnectStatus = {
 // api 接入
 export function useDataSource () {
   const useUserStore = userStore()
-  if (!useUserStore?.userInfo?.enterpriseId) return
   // 最近会话数据源
   WKSDK.shared().config.provider.syncConversationsCallback  = async () => {
     const query = {

+ 10 - 4
pages/index/communicate.vue

@@ -62,19 +62,26 @@ const IM = useIMStore()
 
 const items = ref([])
 watch([() => useUserStore.refreshToken, () => IM.newMsg], () => {
+	if (!useUserStore.refreshToken) return items.value = []
 	// 检测实例是否存在
 	if (!IM.uid?.value) {
 		return
 	}
-	init()
-})
+	if (!userInfo?.enterpriseId) setTimeout(() => {
+		init()
+	}, 2000)
+	
+}, { deep: true })
 
 watch(() => IM.uid, (val) => {
 	if (!val) {
+		items.value = []
 		return
 	}
 	// 监听uid变化
-	init()
+	if (!userInfo?.enterpriseId) setTimeout(() => {
+		init()
+	}, 2000)
 })
 
 onShow(() => {
@@ -134,7 +141,6 @@ const handleTo = (item) => {
 }
 
 async function init () {
-	if (!userInfo.value?.enterpriseId) return
 	try {
 		const { data } = await getConversationSync({ msg_count: 1, enterpriseId: userInfo.value.enterpriseId })
 		if (!data) {

+ 2 - 13
store/user.js

@@ -5,15 +5,6 @@ import { closeAuthModal, showAuthModal } from '@/hooks/useModal'
 import { timesTampChange } from '@/utils/date'
 import { getBaseInfoDictOfName } from '@/utils/getText'
 
-// 默认用户信息
-const defaultBaseInfo = {
-  avatar: '', // 头像
-  nickname: '', // 昵称
-  gender: 0, // 性别
-  mobile: '', // 手机号
-  point: 0, // 积分
-};
-
 // 默认账户信息
 const defaultAccountInfo = {
   accessToken: '',
@@ -120,9 +111,6 @@ export const userStore = defineStore('user', {
         return;
       }
       this.lastUpdateTime = nowTime;
-
-      // 获取最新信息
-      return this.baseInfo;
     },
 
     // 重置用户默认数据
@@ -130,8 +118,9 @@ export const userStore = defineStore('user', {
       // 清空 token
       this.setToken();
       // 清空用户相关的缓存
-      this.baseInfo = { ...defaultBaseInfo };
       this.userInfo = {}
+      this.phone = ''
+      this.userAccountInfo = {}
       this.accountInfo = { ...defaultAccountInfo };
     },