Some checks failed
Deploy Website on push / Deploy Push Element Ftp (push) Waiting to run
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
65 lines
1.1 KiB
TypeScript
65 lines
1.1 KiB
TypeScript
import { acceptHMRUpdate, defineStore } from 'pinia';
|
|
|
|
interface BasicUserInfo {
|
|
[key: string]: any;
|
|
/**
|
|
* 头像
|
|
*/
|
|
avatar: string;
|
|
/**
|
|
* 用户昵称
|
|
*/
|
|
realName: string;
|
|
/**
|
|
* 用户角色
|
|
*/
|
|
roles?: string[];
|
|
/**
|
|
* 用户id
|
|
*/
|
|
userId: string;
|
|
/**
|
|
* 用户名
|
|
*/
|
|
username: string;
|
|
}
|
|
|
|
interface AccessState {
|
|
/**
|
|
* 用户信息
|
|
*/
|
|
userInfo: BasicUserInfo | null;
|
|
/**
|
|
* 用户角色
|
|
*/
|
|
userRoles: string[];
|
|
}
|
|
|
|
/**
|
|
* @zh_CN 用户信息相关
|
|
*/
|
|
export const useUserStore = defineStore('core-user', {
|
|
actions: {
|
|
setUserInfo(userInfo: BasicUserInfo | null) {
|
|
// 设置用户信息
|
|
this.userInfo = userInfo;
|
|
// 设置角色信息
|
|
const roles = userInfo?.roles ?? [];
|
|
this.setUserRoles(roles);
|
|
},
|
|
setUserRoles(roles: string[]) {
|
|
this.userRoles = roles;
|
|
},
|
|
},
|
|
state: (): AccessState => ({
|
|
userInfo: null,
|
|
userRoles: [],
|
|
}),
|
|
});
|
|
|
|
// 解决热更新问题
|
|
const hot = import.meta.hot;
|
|
if (hot) {
|
|
hot.accept(acceptHMRUpdate(useUserStore, hot));
|
|
}
|