Browse Source

更新账户信息

Xiao_123 10 months ago
parent
commit
0fc5f72bef
2 changed files with 17 additions and 7 deletions
  1. 3 3
      src/store/user.js
  2. 14 4
      src/utils/eventList.js

+ 3 - 3
src/store/user.js

@@ -5,7 +5,7 @@ import { getUserInfo } from '@/api/personal/user'
 import { getEnterpriseUserAccount, getUserAccount } from '@/api/common'
 import Snackbar from '@/plugins/snackbar'
 import { timesTampChange } from '@/utils/date'
-import { getRewardEventList } from '@/utils/eventList'
+import { updateEventList } from '@/utils/eventList'
 import { getBaseInfoDictOfName } from '@/utils/getText'
 
 
@@ -63,7 +63,7 @@ export const useUserStore = defineStore('user',
           const data = await api({ id: this.accountInfo.userId })
           this.userInfo = data
           localStorage.setItem('userInfo', JSON.stringify(data))
-          getRewardEventList() // 获取规则配置跟踪列表
+          updateEventList(true) // 获取规则配置跟踪列表
           this.getUserAccountInfo()
         } catch (error) {
           Snackbar.error(error.msg)
@@ -121,7 +121,7 @@ export const useUserStore = defineStore('user',
         localStorage.setItem('currentRole', 'enterprise')
         await this.getEnterpriseInfo()
         await this.getEnterpriseUserAccountInfo()
-        getRewardEventList()
+        updateEventList(false)
         Snackbar.success('切换成功')
       },
       // 获取当前登录的企业用户信息

+ 14 - 4
src/utils/eventList.js

@@ -2,19 +2,29 @@
 import { getToken } from '@/utils/auth'
 import { ref } from 'vue'
 import { getRewardEventTrackList } from '@/api/integral'
+import { useUserStore } from '@/store/user'
 
-export const getRewardEventList = async () => {
+const getRewardEventList = async () => {
   const eventList = await getRewardEventTrackList()
   localStorage.setItem('eventList', JSON.stringify(eventList) ?? [])
 }
 
-// 规则配置跟踪列表(每10分钟更新一次)
-export const updateEventList = () => {
+// 规则配置跟踪列表(每5分钟更新一次)
+export const updateEventList = (type) => {
+  const store = useUserStore()
   const timer = ref(null)
   if (getToken()) {
+    getRewardEventList()
+    if (timer.value) clearInterval(timer.value)
+
     timer.value = setInterval(async () => {
       getRewardEventList()
-    }, 600000)
+
+      // 更新账户信息
+      if (type) await store.getUserAccountInfo()
+      else await store.getEnterpriseUserAccountInfo()
+    }, 300000)
+
   } else {
     timer.value = null
     clearInterval(timer.value)