refactor: refacotr preference
This commit is contained in:
22
packages/@vben-core/shared/typings/src/app.ts
Normal file
22
packages/@vben-core/shared/typings/src/app.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
type LocaleSupportType = 'en-US' | 'zh-CN';
|
||||
|
||||
type LayoutType =
|
||||
| 'full-content'
|
||||
| 'header-nav'
|
||||
| 'mixed-nav'
|
||||
| 'side-mixed-nav'
|
||||
| 'side-nav';
|
||||
|
||||
type ThemeModeType = 'auto' | 'dark' | 'light';
|
||||
|
||||
type ContentCompactType = 'compact' | 'wide';
|
||||
|
||||
type LayoutHeaderModeType = 'auto' | 'auto-scroll' | 'fixed' | 'static';
|
||||
|
||||
export type {
|
||||
ContentCompactType,
|
||||
LayoutHeaderModeType,
|
||||
LayoutType,
|
||||
LocaleSupportType,
|
||||
ThemeModeType,
|
||||
};
|
40
packages/@vben-core/shared/typings/src/flatten.d.ts
vendored
Normal file
40
packages/@vben-core/shared/typings/src/flatten.d.ts
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// `Prev` 类型用于表示递归深度的递减。它是一个元组,其索引代表了递归的层数,通过索引访问可以得到减少后的层数。
|
||||
// 例如,Prev[3] 等于 2,表示递归深度从 3 减少到 2。
|
||||
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]];
|
||||
|
||||
// `FlattenDepth` 类型用于将一个嵌套的对象类型“展平”,同时考虑到了递归的深度。
|
||||
// 它接受三个泛型参数:T(要处理的类型),Prefix(属性名前缀,默认为空字符串),Depth(递归深度,默认为3)。
|
||||
// 如果当前深度(Depth)为 0,则停止递归并返回 `never`。否则,如果属性值是对象类型,则递归调用 `FlattenDepth` 并递减深度。
|
||||
// 对于非对象类型的属性,将其直接映射到结果类型中,并根据前缀构造属性名。
|
||||
|
||||
type FlattenDepth<T, Prefix extends string = '', Depth extends number = 4> = {
|
||||
[K in keyof T]: T[K] extends object
|
||||
? Depth extends 0
|
||||
? never
|
||||
: FlattenDepth<
|
||||
T[K],
|
||||
`${Prefix}${K extends string ? (Prefix extends '' ? K : Capitalize<K>) : ''}`,
|
||||
Prev[Depth]
|
||||
>
|
||||
: {
|
||||
[P in `${Prefix}${K extends string ? (Prefix extends '' ? K : Capitalize<K>) : ''}`]: T[K];
|
||||
};
|
||||
}[keyof T] extends infer O
|
||||
? { [P in keyof O]: O[P] }
|
||||
: never;
|
||||
|
||||
// `UnionToIntersection` 类型用于将一个联合类型转换为交叉类型。
|
||||
// 这个类型通过条件类型和类型推断的方式来实现。它先尝试将输入类型(U)映射为一个函数类型,
|
||||
// 然后通过推断这个函数类型的返回类型(infer I),最终得到一个交叉类型。
|
||||
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
||||
k: infer I,
|
||||
) => void
|
||||
? I
|
||||
: never;
|
||||
|
||||
type Flatten<T> = UnionToIntersection<FlattenDepth<T>>;
|
||||
|
||||
type FlattenObject<T> = FlattenDepth<T>;
|
||||
type FlattenObjectKeys<T> = keyof FlattenObject<T>;
|
||||
|
||||
export type { Flatten, FlattenObject, FlattenObjectKeys, UnionToIntersection };
|
@@ -1,5 +1,6 @@
|
||||
export type * from './access';
|
||||
export type * from './app';
|
||||
export type * from './flatten';
|
||||
export type * from './menu-record';
|
||||
export type * from './preference';
|
||||
export type * from './tabs';
|
||||
export type * from './tools';
|
||||
|
@@ -1,144 +0,0 @@
|
||||
type LayoutType =
|
||||
| 'full-content'
|
||||
| 'header-nav'
|
||||
| 'mixed-nav'
|
||||
| 'side-mixed-nav'
|
||||
| 'side-nav';
|
||||
|
||||
type BreadcrumbStyle = 'background' | 'normal';
|
||||
|
||||
type NavigationStyle = 'plain' | 'rounded';
|
||||
|
||||
type ThemeType = 'auto' | 'dark' | 'light';
|
||||
|
||||
type ContentCompactType = 'compact' | 'wide';
|
||||
|
||||
type LayoutHeaderMode = 'auto' | 'auto-scroll' | 'fixed' | 'static';
|
||||
|
||||
type PageTransitionType = 'fade-slide';
|
||||
|
||||
type AuthPageLayout = 'panel-center' | 'panel-left' | 'panel-right';
|
||||
|
||||
type SupportLocale = 'en-US' | 'zh-CN';
|
||||
|
||||
interface Language {
|
||||
key: SupportLocale;
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface Preference {
|
||||
/** 应用名 */
|
||||
appName: string;
|
||||
/** 登录注册页面布局 */
|
||||
authPageLayout: AuthPageLayout;
|
||||
/** 面包屑是否只有一个时隐藏 */
|
||||
breadcrumbHideOnlyOne: boolean;
|
||||
/** 面包屑首页图标是否可见 */
|
||||
breadcrumbHome: boolean;
|
||||
/** 面包屑图标是否可见 */
|
||||
breadcrumbIcon: boolean;
|
||||
/** 面包屑类型 */
|
||||
breadcrumbStyle: BreadcrumbStyle;
|
||||
/** 面包屑是否可见 */
|
||||
breadcrumbVisible: boolean;
|
||||
/** 是否开启灰色模式 */
|
||||
colorGrayMode: boolean;
|
||||
/** 主题色 */
|
||||
colorPrimary: string;
|
||||
/** 是否开启色弱模式 */
|
||||
colorWeakMode: boolean;
|
||||
/** 是否开启紧凑模式 */
|
||||
compact: boolean;
|
||||
/** 是否开启内容紧凑模式 */
|
||||
contentCompact: ContentCompactType;
|
||||
/** 页脚Copyright */
|
||||
copyright: string;
|
||||
/** 应用默认头像 */
|
||||
defaultAvatar: string;
|
||||
/** 开启动态标题 */
|
||||
dynamicTitle: boolean;
|
||||
/** 页脚是否固定 */
|
||||
footerFixed: boolean;
|
||||
/** 页脚是否可见 */
|
||||
footerVisible: boolean;
|
||||
/** 顶栏是否隐藏 */
|
||||
headerHidden: boolean;
|
||||
/** header显示模式 */
|
||||
headerMode: LayoutHeaderMode;
|
||||
/** 顶栏是否可见 */
|
||||
headerVisible: boolean;
|
||||
/** 是否移动端 */
|
||||
isMobile: boolean;
|
||||
/** 开启标签页缓存功能 */
|
||||
keepAlive: boolean;
|
||||
/** 布局方式 */
|
||||
layout: LayoutType;
|
||||
/** 支持的语言 */
|
||||
locale: SupportLocale;
|
||||
/** 应用Logo */
|
||||
logo: string;
|
||||
/** logo是否可见 */
|
||||
logoVisible: boolean;
|
||||
/** 导航菜单手风琴模式 */
|
||||
navigationAccordion: boolean;
|
||||
/** 导航菜单是否切割,只在 layout=mixed-nav 生效 */
|
||||
navigationSplit: boolean;
|
||||
/** 导航菜单风格 */
|
||||
navigationStyle: NavigationStyle;
|
||||
/** 是否开启页面加载进度条 */
|
||||
pageProgress: boolean;
|
||||
/** 页面切换动画 */
|
||||
pageTransition: PageTransitionType;
|
||||
/** 页面切换动画是否启用 */
|
||||
pageTransitionEnable: boolean;
|
||||
/** 是否开启半深色菜单(只在theme='light'时生效) */
|
||||
semiDarkMenu: boolean;
|
||||
/** 是否启用快捷键 */
|
||||
shortcutKeys: boolean;
|
||||
/** 是否显示偏好设置 */
|
||||
showPreference: boolean;
|
||||
/** 侧边栏是否折叠 */
|
||||
sideCollapse: boolean;
|
||||
/** 侧边栏折叠时,是否显示title */
|
||||
sideCollapseShowTitle: boolean;
|
||||
/** 菜单自动展开状态 */
|
||||
sideExpandOnHover: boolean;
|
||||
/** 侧边栏扩展区域是否折叠 */
|
||||
sideExtraCollapse: boolean;
|
||||
/** 侧边栏是否隐藏 */
|
||||
sideHidden: boolean;
|
||||
/** 侧边栏是否可见 */
|
||||
sideVisible: boolean;
|
||||
/** 侧边栏宽度 */
|
||||
sideWidth: number;
|
||||
/** 是否开启多标签页图标 */
|
||||
tabsIcon: boolean;
|
||||
/** 是否开启多标签页 */
|
||||
tabsVisible: boolean;
|
||||
/** 当前主题 */
|
||||
theme: ThemeType;
|
||||
}
|
||||
|
||||
// 这些属性是静态的,不会随着用户的操作而改变
|
||||
interface StaticPreference {
|
||||
/** 主题色预设 */
|
||||
colorPrimaryPresets: string[];
|
||||
/** 支持的语言 */
|
||||
supportLanguages: Language[];
|
||||
}
|
||||
|
||||
type PreferenceKeys = keyof Preference;
|
||||
|
||||
export type {
|
||||
AuthPageLayout,
|
||||
BreadcrumbStyle,
|
||||
ContentCompactType,
|
||||
LayoutHeaderMode,
|
||||
LayoutType,
|
||||
PageTransitionType,
|
||||
Preference,
|
||||
PreferenceKeys,
|
||||
StaticPreference,
|
||||
SupportLocale,
|
||||
ThemeType,
|
||||
};
|
Reference in New Issue
Block a user