chore: update types

This commit is contained in:
vben
2024-06-02 20:47:50 +08:00
parent b200ae9997
commit ce0c3834ed
31 changed files with 485 additions and 124 deletions

View File

@@ -1,7 +1,7 @@
import type { LocaleSupportType } from './types';
import type { SupportedLanguagesType } from './types';
interface Language {
key: LocaleSupportType;
key: SupportedLanguagesType;
text: string;
}

View File

@@ -96,7 +96,7 @@ class PreferenceManager {
* 加载偏好设置
* @returns {Preferences} 加载的偏好设置
*/
private loadPreferences(): Preferences | null {
private loadPreferences(): Preferences {
return this.loadCachedPreferences() || { ...defaultPreferences };
}

View File

@@ -2,7 +2,7 @@ import type {
ContentCompactType,
LayoutHeaderModeType,
LayoutType,
LocaleSupportType,
SupportedLanguagesType,
ThemeModeType,
} from '@vben-core/typings';
@@ -36,7 +36,7 @@ interface AppPreferences {
/** 布局方式 */
layout: LayoutType;
/** 支持的语言 */
locale: LocaleSupportType;
locale: SupportedLanguagesType;
/** 应用名 */
name: string;
/** 是否开启半深色菜单只在theme='light'时生效) */
@@ -174,7 +174,6 @@ export type {
HeaderPreferences,
LayoutHeaderModeType,
LayoutType,
LocaleSupportType,
LogoPreferences,
NavigationPreferences,
PageTransitionType,
@@ -182,6 +181,7 @@ export type {
PreferencesKeys,
ShortcutKeyPreferences,
SidebarPreferences,
SupportedLanguagesType,
TabbarPreferences,
ThemeModeType,
ThemePreferences,

View File

@@ -1,4 +1,4 @@
import type { MenuRecordRaw, UserInfo } from '@vben-core/typings';
import type { MenuRecordRaw } from '@vben-core/typings';
import type { RouteRecordRaw } from 'vue-router';
@@ -6,6 +6,28 @@ import { acceptHMRUpdate, defineStore } from 'pinia';
type AccessToken = null | string;
interface BasicUserInfo {
[key: string]: any;
/**
* 头像
*/
avatar: string;
/**
* 用户昵称
*/
realName: string;
/**
* 用户id
*/
userId: string;
/**
* 用户名
*/
username: string;
}
interface AccessState {
/**
* 可访问的菜单列表
@@ -22,7 +44,7 @@ interface AccessState {
/**
* 用户信息
*/
userInfo: UserInfo | null;
userInfo: BasicUserInfo | null;
/**
* 用户角色
*/
@@ -43,12 +65,15 @@ const useAccessStore = defineStore('access', {
setAccessToken(token: AccessToken) {
this.accessToken = token;
},
setUserInfo(userInfo: UserInfo) {
setUserInfo(userInfo: BasicUserInfo) {
// 设置用户信息
this.userInfo = userInfo;
// 设置角色信息
const roles = userInfo?.roles ?? [];
const roleValues = roles.map((item) => item.value);
const roleValues =
typeof roles[0] === 'string'
? roles
: roles.map((item: Record<string, any>) => item.value);
this.setUserRoles(roleValues);
},
setUserRoles(roles: string[]) {
@@ -65,7 +90,7 @@ const useAccessStore = defineStore('access', {
getAccessToken(): AccessToken {
return this.accessToken;
},
getUserInfo(): UserInfo | null {
getUserInfo(): BasicUserInfo | null {
return this.userInfo;
},
getUserRoles(): string[] {