初始化

This commit is contained in:
2024-07-10 13:50:01 +08:00
commit e30966c6c5
1073 changed files with 143076 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
/**
* 登录用户 store
*/
import { defineStore } from 'pinia';
import type { User } from '@/uni_modules/ws-common/api/system/user/model';
import { getUserInfo } from '@/uni_modules/ws-common/api/layout';
export interface UserState {
info: User | null;
menus: any[] | null | undefined;
authorities: (string | undefined)[];
roles: (string | undefined)[];
}
export const useUserStore = defineStore({
id: 'user',
state: (): UserState => ({
// 当前登录用户的信息
info: null,
// 当前登录用户的菜单
menus: null,
// 当前登录用户的权限
authorities: [],
// 当前登录用户的角色
roles: []
}),
getters: {},
actions: {
/**
* 请求用户信息、权限、角色、菜单
*/
async fetchUserInfo() {
const result = await getUserInfo().catch(() => {});
if (!result) {
return {};
}
// 用户信息
this.info = result;
// 用户权限
this.authorities =
result.authorities
?.filter((d) => !!d.authority)
?.map((d) => d.authority) ?? [];
// 用户角色
this.roles = result.roles?.map((d) => d.roleCode) ?? [];
// 用户菜单, 过滤掉按钮类型并转为 children 形式
this.menus = [];
return result;
},
/**
* 更新用户信息
*/
setInfo(value: User) {
this.info = value;
},
}
});