feat(store): 新增用户和企业信息管理功能
- 在 user store 中添加 userInfo 相关状态和操作 - 创建 enterprise store管理企业信息 - 更新相关组件以使用新的 store 方法
This commit is contained in:
@ -11,12 +11,27 @@ type Role = 'ENTERPRISE' | 'PERSON';
|
||||
interface UserState {
|
||||
role: Role;
|
||||
isLogin: boolean;
|
||||
userInfo: UserInfo | null;
|
||||
}
|
||||
|
||||
interface UserInfo {
|
||||
id: number;
|
||||
mobile: string;
|
||||
name: string;
|
||||
head_image: string;
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
state: (): UserState => ({
|
||||
role: 'PERSON',
|
||||
isLogin: false,
|
||||
// todo 暂时写死,登录功能完成后记得重置为null哦
|
||||
userInfo: {
|
||||
id: 1,
|
||||
mobile: '13600000000',
|
||||
name: '灵机用户0001',
|
||||
head_image: '',
|
||||
},
|
||||
}),
|
||||
|
||||
getters: {
|
||||
@ -37,10 +52,27 @@ export const useUserStore = defineStore('user', {
|
||||
this.isLogin = isLogin;
|
||||
},
|
||||
|
||||
async getUserInfo() {
|
||||
// todo 调用获取用户信息接口,当前用mock数据表示
|
||||
AMessage.success(`当前用户角色为:ENTERPRISE`)
|
||||
this.setUserRole('ENTERPRISE');
|
||||
setUserInfo(userInfo: UserInfo | null) {
|
||||
this.userInfo = userInfo;
|
||||
},
|
||||
setUserMobile(mobile: string) {
|
||||
if (this.userInfo) {
|
||||
this.userInfo.mobile = mobile;
|
||||
}
|
||||
},
|
||||
setUserName(name: string) {
|
||||
if (this.userInfo) {
|
||||
this.userInfo.name = name;
|
||||
}
|
||||
},
|
||||
setUserHeadImage(image: string) {
|
||||
if (this.userInfo) {
|
||||
this.userInfo.head_image = image;
|
||||
}
|
||||
},
|
||||
|
||||
getUserInfo() {
|
||||
return this.userInfo;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user