|
@@ -1,10 +1,10 @@
|
|
|
import { defineStore } from 'pinia';
|
|
|
import { clone, cloneDeep } from 'lodash-es';
|
|
|
-import { getUserInfo } from '@/api/user';
|
|
|
+import { getBaseInfo, getUserInfo } from '@/api/user';
|
|
|
import { smsLogin, passwordLogin, logout } from '@/api/common'
|
|
|
|
|
|
// 默认用户信息
|
|
|
-const defaultUserInfo = {
|
|
|
+const defaultBaseInfo = {
|
|
|
avatar: '', // 头像
|
|
|
nickname: '', // 昵称
|
|
|
gender: 0, // 性别
|
|
@@ -31,7 +31,8 @@ const tabUrl = [
|
|
|
export const userStore = defineStore({
|
|
|
id: 'user',
|
|
|
state: () => ({
|
|
|
- userInfo: {}, // 用户信息
|
|
|
+ baseInfo: {}, // 用户信息
|
|
|
+ userInfo: {},
|
|
|
isLogin: !!uni.getStorageSync('token'), // 登录状态
|
|
|
lastUpdateTime: 0, // 上次更新时间
|
|
|
accountInfo: cloneDeep(defaultAccountInfo), // 账号信息
|
|
@@ -49,6 +50,7 @@ export const userStore = defineStore({
|
|
|
}
|
|
|
this.accountInfo = data
|
|
|
this.getInfo()
|
|
|
+ this.getUserInfo()
|
|
|
|
|
|
// 登录成功后的跳转地址
|
|
|
// if (tabUrl.includes(route)) {
|
|
@@ -64,9 +66,18 @@ export const userStore = defineStore({
|
|
|
url: '/pages/index/position'
|
|
|
})
|
|
|
},
|
|
|
- // 获取用户信息
|
|
|
+ // 获取人才信息
|
|
|
async getInfo() {
|
|
|
- const { code, data } = await getUserInfo({ userId: this.accountInfo.userId });
|
|
|
+ const { code, data } = await getBaseInfo({ userId: this.accountInfo.userId });
|
|
|
+ if (code !== 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.baseInfo = data;
|
|
|
+ return Promise.resolve(data);
|
|
|
+ },
|
|
|
+ // 获取用户信息
|
|
|
+ async getUserInfo() {
|
|
|
+ const { code, data } = await getUserInfo({ id: this.accountInfo.userId });
|
|
|
if (code !== 0) {
|
|
|
return;
|
|
|
}
|
|
@@ -102,9 +113,7 @@ export const userStore = defineStore({
|
|
|
this.lastUpdateTime = nowTime;
|
|
|
|
|
|
// 获取最新信息
|
|
|
- // await this.getInfo();
|
|
|
- // this.getWallet();
|
|
|
- return this.userInfo;
|
|
|
+ return this.baseInfo;
|
|
|
},
|
|
|
|
|
|
// 重置用户默认数据
|
|
@@ -112,7 +121,8 @@ export const userStore = defineStore({
|
|
|
// 清空 token
|
|
|
this.setToken();
|
|
|
// 清空用户相关的缓存
|
|
|
- this.userInfo = clone(defaultUserInfo);
|
|
|
+ this.baseInfo = clone(defaultBaseInfo);
|
|
|
+ this.userInfo = {}
|
|
|
this.accountInfo = cloneDeep(defaultAccountInfo);
|
|
|
},
|
|
|
|