diff --git a/src/const/userConst.js b/src/const/userConst.js index daac06c..7a0b3d8 100644 --- a/src/const/userConst.js +++ b/src/const/userConst.js @@ -2,3 +2,4 @@ export const CLIENT_TYPE = 2 export const CLIENT_NAME = 'web' export const CLIENT_VERSION = '0.0.1' export const CLIENT_ID = 'XXAA' +export const USER_DATA_EXPIRE = 3600 diff --git a/src/stores/user.js b/src/stores/user.js index 619564e..87a7911 100644 --- a/src/stores/user.js +++ b/src/stores/user.js @@ -1,6 +1,7 @@ import { defineStore } from 'pinia' import { ref } from 'vue' import { userInfoService } from '@/api/user' +import { USER_DATA_EXPIRE } from '@/const/userConst' // 用户模块 export const userStore = defineStore( @@ -48,9 +49,14 @@ export const userStore = defineStore( } const user = ref({}) + const loginTime = ref(0) const getUser = async () => { - const res = await userInfoService() - user.value = res.data.data + const now = new Date().getTime() + if (loginTime.value === 0 || now - loginTime.value > USER_DATA_EXPIRE * 1000) { + const res = await userInfoService() + user.value = res.data.data + loginTime.value = now + } } const setUser = (obj) => { user.value = obj @@ -65,7 +71,8 @@ export const userStore = defineStore( clearRt, user, getUser, - setUser + setUser, + loginTime } }, {