@melt-js/libs-vben 0.0.0-stage → 2026.11.8-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/LICENSE +10 -0
  2. package/README.md +86 -2
  3. package/package.json +98 -3
  4. package/src/access/access-control.vue +47 -0
  5. package/src/access/accessible.ts +236 -0
  6. package/src/access/directive.ts +42 -0
  7. package/src/access/index.ts +4 -0
  8. package/src/access/use-access.ts +53 -0
  9. package/src/composables/index.ts +14 -0
  10. package/src/composables/use-is-mobile.ts +7 -0
  11. package/src/composables/use-layout-style.ts +51 -0
  12. package/src/composables/use-layout-viewport-height.ts +71 -0
  13. package/src/composables/use-namespace.ts +106 -0
  14. package/src/composables/use-priority-value.ts +96 -0
  15. package/src/composables/use-scroll-lock.ts +151 -0
  16. package/src/composables/use-simple-locale/README.md +3 -0
  17. package/src/composables/use-simple-locale/index.ts +27 -0
  18. package/src/composables/use-simple-locale/messages.ts +31 -0
  19. package/src/composables/use-sortable.ts +32 -0
  20. package/src/constants/core.ts +76 -0
  21. package/src/constants/index.ts +2 -0
  22. package/src/core-icons/create-icon.ts +14 -0
  23. package/src/core-icons/index.ts +11 -0
  24. package/src/core-icons/lucide.ts +95 -0
  25. package/src/core-preferences/config.ts +172 -0
  26. package/src/core-preferences/constants.ts +116 -0
  27. package/src/core-preferences/index.ts +24 -0
  28. package/src/core-preferences/preferences.ts +503 -0
  29. package/src/core-preferences/types.ts +471 -0
  30. package/src/core-preferences/update-css-variables.ts +129 -0
  31. package/src/core-preferences/use-preferences.ts +282 -0
  32. package/src/design/css/global.css +1 -0
  33. package/src/design/css/nprogress.css +61 -0
  34. package/src/design/css/transition.css +238 -0
  35. package/src/design/css/ui.css +101 -0
  36. package/src/design/design-tokens/dark.css +446 -0
  37. package/src/design/design-tokens/default.css +491 -0
  38. package/src/design/design-tokens/index.ts +2 -0
  39. package/src/design/index.ts +6 -0
  40. package/src/design/scss-bem/bem.scss +34 -0
  41. package/src/design/scss-bem/constants.scss +5 -0
  42. package/src/hooks/index.ts +9 -0
  43. package/src/hooks/use-app-config.ts +39 -0
  44. package/src/hooks/use-content-maximize.ts +24 -0
  45. package/src/hooks/use-design-tokens.ts +421 -0
  46. package/src/hooks/use-hover-toggle.ts +163 -0
  47. package/src/hooks/use-pagination.ts +72 -0
  48. package/src/hooks/use-refresh.ts +16 -0
  49. package/src/hooks/use-tabs.ts +143 -0
  50. package/src/hooks/use-watermark.ts +84 -0
  51. package/src/icons/iconify/index.ts +5 -0
  52. package/src/icons/icons/empty-icon.vue +27 -0
  53. package/src/icons/index.ts +3 -0
  54. package/src/icons/svg/icons/antdv-logo.svg +29 -0
  55. package/src/icons/svg/icons/antdv-next-logo.svg +1 -0
  56. package/src/icons/svg/icons/avatar-1.svg +1 -0
  57. package/src/icons/svg/icons/avatar-2.svg +1 -0
  58. package/src/icons/svg/icons/avatar-3.svg +1 -0
  59. package/src/icons/svg/icons/avatar-4.svg +1 -0
  60. package/src/icons/svg/icons/bell.svg +1 -0
  61. package/src/icons/svg/icons/cake.svg +1 -0
  62. package/src/icons/svg/icons/card.svg +1 -0
  63. package/src/icons/svg/icons/dingding.svg +1 -0
  64. package/src/icons/svg/icons/download.svg +1 -0
  65. package/src/icons/svg/icons/github.svg +1 -0
  66. package/src/icons/svg/icons/google.svg +1 -0
  67. package/src/icons/svg/icons/qqchat.svg +1 -0
  68. package/src/icons/svg/icons/tdesign-logo.svg +39 -0
  69. package/src/icons/svg/icons/wechat.svg +1 -0
  70. package/src/icons/svg/index.ts +39 -0
  71. package/src/icons/svg/load.ts +81 -0
  72. package/src/locales/i18n.ts +147 -0
  73. package/src/locales/index.ts +30 -0
  74. package/src/locales/langs/en-US/authentication.json +65 -0
  75. package/src/locales/langs/en-US/common.json +27 -0
  76. package/src/locales/langs/en-US/preferences.json +245 -0
  77. package/src/locales/langs/en-US/profile.json +4 -0
  78. package/src/locales/langs/en-US/ui.json +165 -0
  79. package/src/locales/langs/zh-CN/authentication.json +65 -0
  80. package/src/locales/langs/zh-CN/common.json +27 -0
  81. package/src/locales/langs/zh-CN/preferences.json +245 -0
  82. package/src/locales/langs/zh-CN/profile.json +4 -0
  83. package/src/locales/langs/zh-CN/ui.json +165 -0
  84. package/src/locales/langs/zh-TW/authentication.json +65 -0
  85. package/src/locales/langs/zh-TW/common.json +27 -0
  86. package/src/locales/langs/zh-TW/preferences.json +245 -0
  87. package/src/locales/langs/zh-TW/profile.json +4 -0
  88. package/src/locales/langs/zh-TW/ui.json +165 -0
  89. package/src/locales/typing.ts +27 -0
  90. package/src/preferences/index.ts +42 -0
  91. package/src/request/index.ts +2 -0
  92. package/src/request/request-client/index.ts +3 -0
  93. package/src/request/request-client/modules/downloader.ts +60 -0
  94. package/src/request/request-client/modules/interceptor.ts +40 -0
  95. package/src/request/request-client/modules/sse.ts +134 -0
  96. package/src/request/request-client/modules/uploader.ts +79 -0
  97. package/src/request/request-client/preset-interceptors.ts +178 -0
  98. package/src/request/request-client/request-client.ts +163 -0
  99. package/src/request/request-client/types.ts +90 -0
  100. package/src/shared/cache/README.md +418 -0
  101. package/src/shared/cache/index.ts +5 -0
  102. package/src/shared/cache/indexeddb-driver.ts +137 -0
  103. package/src/shared/cache/local-storage-driver.ts +70 -0
  104. package/src/shared/cache/memory-storage-driver.ts +32 -0
  105. package/src/shared/cache/storage-manager.ts +146 -0
  106. package/src/shared/cache/types.ts +39 -0
  107. package/src/shared/color/color.ts +9 -0
  108. package/src/shared/color/convert.ts +62 -0
  109. package/src/shared/color/generator.ts +45 -0
  110. package/src/shared/color/index.ts +3 -0
  111. package/src/shared/constants/globals.ts +20 -0
  112. package/src/shared/constants/index.ts +2 -0
  113. package/src/shared/constants/vben.ts +30 -0
  114. package/src/shared/global-state.ts +45 -0
  115. package/src/shared/store.ts +1 -0
  116. package/src/shared/utils/cn.ts +10 -0
  117. package/src/shared/utils/date.ts +80 -0
  118. package/src/shared/utils/diff.ts +114 -0
  119. package/src/shared/utils/dom.ts +126 -0
  120. package/src/shared/utils/download.ts +186 -0
  121. package/src/shared/utils/error.ts +19 -0
  122. package/src/shared/utils/index.ts +22 -0
  123. package/src/shared/utils/inference.ts +164 -0
  124. package/src/shared/utils/letter.ts +47 -0
  125. package/src/shared/utils/merge.ts +11 -0
  126. package/src/shared/utils/nprogress.ts +52 -0
  127. package/src/shared/utils/resources.ts +21 -0
  128. package/src/shared/utils/stack.ts +103 -0
  129. package/src/shared/utils/state-handler.ts +61 -0
  130. package/src/shared/utils/to.ts +21 -0
  131. package/src/shared/utils/tree.ts +159 -0
  132. package/src/shared/utils/unique.ts +15 -0
  133. package/src/shared/utils/update-css-variables.ts +47 -0
  134. package/src/shared/utils/util.ts +50 -0
  135. package/src/shared/utils/window.ts +37 -0
  136. package/src/stores/index.ts +3 -0
  137. package/src/stores/modules/access.ts +130 -0
  138. package/src/stores/modules/dict.ts +244 -0
  139. package/src/stores/modules/index.ts +5 -0
  140. package/src/stores/modules/tabbar.ts +797 -0
  141. package/src/stores/modules/timezone.ts +132 -0
  142. package/src/stores/modules/user.ts +42 -0
  143. package/src/stores/setup.ts +79 -0
  144. package/src/stores/shim-pinia.d.ts +11 -0
  145. package/src/styles/antd/index.css +78 -0
  146. package/src/styles/antdv-next/index.css +90 -0
  147. package/src/styles/ele/index.css +44 -0
  148. package/src/styles/global/index.scss +1 -0
  149. package/src/styles/index.ts +1 -0
  150. package/src/styles/naive/index.css +26 -0
  151. package/src/styles/style-exports.d.ts +3 -0
  152. package/src/theme.css +592 -0
  153. package/src/types/global.d.ts +28 -0
  154. package/src/types/index.ts +2 -0
  155. package/src/types/shims.d.ts +1 -0
  156. package/src/types/user.ts +20 -0
  157. package/src/typings/app.d.ts +128 -0
  158. package/src/typings/basic.d.ts +42 -0
  159. package/src/typings/helper.d.ts +147 -0
  160. package/src/typings/index.ts +16 -0
  161. package/src/typings/languages.ts +28 -0
  162. package/src/typings/menu-record.ts +82 -0
  163. package/src/typings/tabs.ts +8 -0
  164. package/src/typings/vue-router.d.ts +169 -0
  165. package/src/utils/helpers/find-menu-by-path.ts +37 -0
  166. package/src/utils/helpers/generate-menus.ts +89 -0
  167. package/src/utils/helpers/generate-routes-backend.ts +108 -0
  168. package/src/utils/helpers/generate-routes-frontend.ts +58 -0
  169. package/src/utils/helpers/get-popup-container.ts +10 -0
  170. package/src/utils/helpers/index.ts +8 -0
  171. package/src/utils/helpers/merge-route-modules.ts +28 -0
  172. package/src/utils/helpers/reset-routes.ts +30 -0
  173. package/src/utils/helpers/unmount-global-loading.ts +31 -0
  174. package/src/utils/index.ts +4 -0
@@ -0,0 +1,128 @@
1
+ type LayoutType =
2
+ | 'full-content'
3
+ | 'header-mixed-nav'
4
+ | 'header-nav'
5
+ | 'header-sidebar-nav'
6
+ | 'mixed-nav'
7
+ | 'sidebar-mixed-nav'
8
+ | 'sidebar-nav';
9
+
10
+ type ThemeModeType = 'auto' | 'dark' | 'light';
11
+
12
+ /**
13
+ * 偏好设置按钮位置
14
+ * auto 自动(按布局上下文在 header/fixed 间切换)
15
+ * fixed 固定在屏幕右边缘
16
+ * header 顶栏
17
+ * user-dropdown 用户的下拉弹出框中
18
+ * none 不显示
19
+ */
20
+ type PreferencesButtonPositionType =
21
+ | 'auto'
22
+ | 'fixed'
23
+ | 'header'
24
+ | 'none'
25
+ | 'user-dropdown';
26
+
27
+ type BuiltinThemeType =
28
+ | 'custom'
29
+ | 'deep-blue'
30
+ | 'deep-green'
31
+ | 'default'
32
+ | 'gray'
33
+ | 'green'
34
+ | 'neutral'
35
+ | 'orange'
36
+ | 'pink'
37
+ | 'red'
38
+ | 'rose'
39
+ | 'sky-blue'
40
+ | 'slate'
41
+ | 'stone'
42
+ | 'violet'
43
+ | 'yellow'
44
+ | 'zinc'
45
+ | (string & {});
46
+
47
+ type ContentCompactType = 'compact' | 'wide';
48
+
49
+ type LayoutHeaderModeType = 'auto' | 'auto-scroll' | 'fixed' | 'static';
50
+ type LayoutHeaderMenuAlignType = 'center' | 'end' | 'start';
51
+
52
+ /**
53
+ * 登录过期模式
54
+ * modal 弹窗模式
55
+ * page 页面模式
56
+ */
57
+ type LoginExpiredModeType = 'modal' | 'page';
58
+
59
+ /**
60
+ * 面包屑样式
61
+ * background 背景
62
+ * normal 默认
63
+ */
64
+ type BreadcrumbStyleType = 'background' | 'normal';
65
+
66
+ /**
67
+ * 权限模式
68
+ * backend 后端权限模式
69
+ * frontend 前端权限模式
70
+ * mixed 混合权限模式
71
+ */
72
+ type AccessModeType = 'backend' | 'frontend' | 'mixed';
73
+
74
+ /**
75
+ * 导航风格
76
+ * plain 朴素
77
+ * rounded 圆润
78
+ */
79
+ type NavigationStyleType = 'plain' | 'rounded';
80
+
81
+ /**
82
+ * 标签栏风格
83
+ * brisk 轻快
84
+ * card 卡片
85
+ * chrome 谷歌
86
+ * plain 朴素
87
+ */
88
+ type TabsStyleType = 'brisk' | 'card' | 'chrome' | 'plain';
89
+
90
+ /**
91
+ * 页面切换动画
92
+ */
93
+ type PageTransitionType = 'fade' | 'fade-down' | 'fade-slide' | 'fade-up';
94
+
95
+ /**
96
+ * 页面切换动画
97
+ * panel-center 居中布局
98
+ * panel-left 居左布局
99
+ * panel-right 居右布局
100
+ */
101
+ type AuthPageLayoutType = 'panel-center' | 'panel-left' | 'panel-right';
102
+
103
+ /**
104
+ * 时区选项
105
+ */
106
+ interface TimezoneOption {
107
+ label: string;
108
+ offset: number;
109
+ timezone: string;
110
+ }
111
+
112
+ export type {
113
+ AccessModeType,
114
+ AuthPageLayoutType,
115
+ BreadcrumbStyleType,
116
+ BuiltinThemeType,
117
+ ContentCompactType,
118
+ LayoutHeaderMenuAlignType,
119
+ LayoutHeaderModeType,
120
+ LayoutType,
121
+ LoginExpiredModeType,
122
+ NavigationStyleType,
123
+ PageTransitionType,
124
+ PreferencesButtonPositionType,
125
+ TabsStyleType,
126
+ ThemeModeType,
127
+ TimezoneOption,
128
+ };
@@ -0,0 +1,42 @@
1
+ interface BasicOption {
2
+ label: string;
3
+ value: string;
4
+ }
5
+
6
+ type SelectOption = BasicOption;
7
+
8
+ type TabOption = BasicOption;
9
+
10
+ interface BasicUserInfo {
11
+ [key: string]: any;
12
+ /**
13
+ * 头像
14
+ */
15
+ avatar: string;
16
+ /**
17
+ * 用户昵称
18
+ */
19
+ realName: string;
20
+ /**
21
+ * 用户角色
22
+ */
23
+ roles?: string[];
24
+ /**
25
+ * 用户id
26
+ */
27
+ userId: string;
28
+ /**
29
+ * 用户名
30
+ */
31
+ username: string;
32
+ }
33
+
34
+ type ClassType =
35
+ | Array<ClassType>
36
+ | boolean
37
+ | null
38
+ | object
39
+ | string
40
+ | undefined;
41
+
42
+ export type { BasicOption, BasicUserInfo, ClassType, SelectOption, TabOption };
@@ -0,0 +1,147 @@
1
+ import type { ComputedRef, MaybeRef } from 'vue';
2
+
3
+ /**
4
+ * 类型级递归中增加深度计数
5
+ */
6
+ type Increment<A extends unknown[]> = [...A, unknown];
7
+ /**
8
+ * 深层递归所有属性为可选
9
+ */
10
+ type DeepPartial<
11
+ T,
12
+ D extends number = 10,
13
+ C extends unknown[] = [],
14
+ > = C['length'] extends D
15
+ ? T
16
+ : T extends object
17
+ ? {
18
+ [P in keyof T]?: DeepPartial<T[P], D, Increment<C>>;
19
+ }
20
+ : T;
21
+
22
+ /**
23
+ * 深层递归所有属性为只读
24
+ */
25
+ type DeepReadonly<
26
+ T,
27
+ D extends number = 10,
28
+ C extends unknown[] = [],
29
+ > = C['length'] extends D
30
+ ? T
31
+ : T extends object
32
+ ? {
33
+ readonly [P in keyof T]: DeepReadonly<T[P], D, Increment<C>>;
34
+ }
35
+ : T;
36
+
37
+ /**
38
+ * 任意类型的异步函数
39
+ */
40
+
41
+ type AnyPromiseFunction<T extends any[] = any[], R = void> = (
42
+ ...arg: T
43
+ ) => PromiseLike<R>;
44
+
45
+ /**
46
+ * 任意类型的普通函数
47
+ */
48
+ type AnyNormalFunction<T extends any[] = any[], R = void> = (...arg: T) => R;
49
+
50
+ /**
51
+ * 任意类型的函数
52
+ */
53
+ type AnyFunction<T extends any[] = any[], R = void> =
54
+ | AnyNormalFunction<T, R>
55
+ | AnyPromiseFunction<T, R>;
56
+
57
+ /**
58
+ * T | null 包装
59
+ */
60
+ type Nullable<T> = null | T;
61
+
62
+ /**
63
+ * T | Not null 包装
64
+ */
65
+ type NonNullable<T> = T extends null | undefined ? never : T;
66
+
67
+ /**
68
+ * 字符串类型对象
69
+ */
70
+ type Recordable<T> = Record<string, T>;
71
+
72
+ /**
73
+ * 字符串类型对象(只读)
74
+ */
75
+ interface ReadonlyRecordable<T = any> {
76
+ readonly [key: string]: T;
77
+ }
78
+
79
+ /**
80
+ * setTimeout 返回值类型
81
+ */
82
+ type TimeoutHandle = ReturnType<typeof setTimeout>;
83
+
84
+ /**
85
+ * setInterval 返回值类型
86
+ */
87
+ type IntervalHandle = ReturnType<typeof setInterval>;
88
+
89
+ /**
90
+ * 也许它是一个计算的 ref,或者一个 getter 函数
91
+ *
92
+ */
93
+ type MaybeReadonlyRef<T> = (() => T) | ComputedRef<T>;
94
+
95
+ /**
96
+ * 也许它是一个 ref,或者一个普通值,或者一个 getter 函数
97
+ *
98
+ */
99
+ type MaybeComputedRef<T> = MaybeReadonlyRef<T> | MaybeRef<T>;
100
+
101
+ type Merge<O extends object, T extends object> = {
102
+ [K in keyof O | keyof T]: K extends keyof T
103
+ ? T[K]
104
+ : K extends keyof O
105
+ ? O[K]
106
+ : never;
107
+ };
108
+
109
+ /**
110
+ * T = [
111
+ * { name: string; age: number; },
112
+ * { sex: 'male' | 'female'; age: string }
113
+ * ]
114
+ * =>
115
+ * MergeAll<T> = {
116
+ * name: string;
117
+ * sex: 'male' | 'female';
118
+ * age: string
119
+ * }
120
+ */
121
+ type MergeAll<
122
+ T extends object[],
123
+ R extends object = Record<string, any>,
124
+ > = T extends [infer F extends object, ...infer Rest extends object[]]
125
+ ? MergeAll<Rest, Merge<R, F>>
126
+ : R;
127
+
128
+ type MaybePromise<T> = Promise<T> | T;
129
+
130
+ export type {
131
+ AnyFunction,
132
+ AnyNormalFunction,
133
+ AnyPromiseFunction,
134
+ DeepPartial,
135
+ DeepReadonly,
136
+ IntervalHandle,
137
+ MaybeComputedRef,
138
+ MaybePromise,
139
+ MaybeReadonlyRef,
140
+ Merge,
141
+ MergeAll,
142
+ NonNullable,
143
+ Nullable,
144
+ ReadonlyRecordable,
145
+ Recordable,
146
+ TimeoutHandle,
147
+ };
@@ -0,0 +1,16 @@
1
+ import type { VbenRouteMeta } from './vue-router';
2
+
3
+ // 模块增强随本 barrel 的导入生效:使用方经 @vben/types 的 re-export 或
4
+ // 直接依赖本包即获得 RouteMeta 增强;未导入本包的独立程序不激活。
5
+ declare module 'vue-router' {
6
+ // oxlint-disable-next-line typescript/no-empty-object-type
7
+ interface RouteMeta extends VbenRouteMeta {}
8
+ }
9
+
10
+ export type * from './app';
11
+ export type * from './basic';
12
+ export type * from './helper';
13
+ export type * from './languages';
14
+ export type * from './menu-record';
15
+ export type * from './tabs';
16
+ export type * from './vue-router';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 支持的语言注册表(核心默认语言)。
3
+ *
4
+ * 接口值仅为文档用途的语言标签,类型系统只消费键。
5
+ * 应用如需扩展语言,无需改动核心包,只需在应用内新建 d.ts 文件,
6
+ * 通过模块增强(declaration merging)追加语言键:
7
+ *
8
+ * ```ts
9
+ * declare module '@melt-js/libs-vben/typings' {
10
+ * interface SupportedLanguages {
11
+ * 'zh-TW': '繁體中文';
12
+ * }
13
+ * }
14
+ * ```
15
+ *
16
+ * 追加后 `SupportedLanguagesType` 联合类型会自动包含新语言,
17
+ * 所有引用该类型的包(preferences、locales、constants 等)同步获得类型约束;
18
+ * 运行时语言列表则通过 `setSupportLanguages` 注册。
19
+ */
20
+ export interface SupportedLanguages {
21
+ 'en-US': 'English';
22
+ 'zh-CN': '简体中文';
23
+ }
24
+
25
+ /**
26
+ * 支持的语言类型
27
+ */
28
+ export type SupportedLanguagesType = keyof SupportedLanguages;
@@ -0,0 +1,82 @@
1
+ import type { Component } from 'vue';
2
+ import type { RouteRecordRaw } from 'vue-router';
3
+
4
+ import type { Recordable } from './helper';
5
+
6
+ /**
7
+ * 扩展路由原始对象
8
+ */
9
+ type ExRouteRecordRaw = RouteRecordRaw & {
10
+ parent?: string;
11
+ parents?: string[];
12
+ path?: any;
13
+ };
14
+
15
+ interface MenuRecordBadgeRaw {
16
+ /**
17
+ * 徽标
18
+ */
19
+ badge?: string;
20
+ /**
21
+ * 徽标类型
22
+ */
23
+ badgeType?: 'dot' | 'normal';
24
+ /**
25
+ * 徽标颜色
26
+ */
27
+ badgeVariants?: 'destructive' | 'primary' | (string & {});
28
+ }
29
+
30
+ /**
31
+ * 菜单原始对象
32
+ */
33
+ interface MenuRecordRaw extends MenuRecordBadgeRaw {
34
+ /**
35
+ * 激活时的图标名
36
+ */
37
+ activeIcon?: string;
38
+ /**
39
+ * 子菜单
40
+ */
41
+ children?: MenuRecordRaw[];
42
+ /**
43
+ * 是否禁用菜单
44
+ * @default false
45
+ */
46
+ disabled?: boolean;
47
+ /**
48
+ * 图标名
49
+ */
50
+ icon?: Component | string;
51
+ /**
52
+ * 菜单名
53
+ */
54
+ name: string;
55
+ /**
56
+ * 排序号
57
+ */
58
+ order?: number;
59
+ /**
60
+ * 父级路径
61
+ */
62
+ parent?: string;
63
+ /**
64
+ * 所有父级路径
65
+ */
66
+ parents?: string[];
67
+ /**
68
+ * 菜单路径,唯一,可当作key
69
+ */
70
+ path: string;
71
+ /**
72
+ * 菜单参数
73
+ */
74
+ query?: Recordable<any>;
75
+ /**
76
+ * 是否显示菜单
77
+ * @default true
78
+ */
79
+ show?: boolean;
80
+ }
81
+
82
+ export type { ExRouteRecordRaw, MenuRecordBadgeRaw, MenuRecordRaw };
@@ -0,0 +1,8 @@
1
+ import type { RouteLocationNormalized } from 'vue-router';
2
+
3
+ export interface TabDefinition extends RouteLocationNormalized {
4
+ /**
5
+ * 标签页的key
6
+ */
7
+ key?: string;
8
+ }
@@ -0,0 +1,169 @@
1
+ import type { Component } from 'vue';
2
+ import type { Router, RouteRecordRaw } from 'vue-router';
3
+
4
+ import type { Recordable } from './helper';
5
+
6
+ interface VbenRouteMeta {
7
+ /**
8
+ * 激活图标(菜单/tab)
9
+ */
10
+ activeIcon?: string;
11
+ /**
12
+ * 当前激活的菜单,有时候不想激活现有菜单,需要激活父级菜单时使用
13
+ */
14
+ activePath?: string;
15
+ /**
16
+ * 是否使用 activePath 对应的路由层级生成面包屑
17
+ * @default false
18
+ */
19
+ breadcrumbUseActivePath?: boolean;
20
+ /**
21
+ * 是否固定标签页
22
+ * @default false
23
+ */
24
+ affixTab?: boolean;
25
+ /**
26
+ * 固定标签页的顺序
27
+ * @default 0
28
+ */
29
+ affixTabOrder?: number;
30
+ /**
31
+ * 需要特定的角色标识才可以访问
32
+ * @default []
33
+ */
34
+ authority?: string[];
35
+ /**
36
+ * 徽标
37
+ */
38
+ badge?: string;
39
+ /**
40
+ * 徽标类型
41
+ */
42
+ badgeType?: 'dot' | 'normal';
43
+ /**
44
+ * 徽标颜色
45
+ */
46
+ badgeVariants?:
47
+ | 'default'
48
+ | 'destructive'
49
+ | 'primary'
50
+ | 'success'
51
+ | 'warning'
52
+ | (string & {});
53
+ /**
54
+ * 路由对应dom是否缓存起来
55
+ */
56
+ domCached?: boolean;
57
+ /**
58
+ * 路由的完整路径作为key(默认true)
59
+ */
60
+ fullPathKey?: boolean;
61
+ /**
62
+ * 当前路由的子级在菜单中不展现
63
+ * @default false
64
+ */
65
+ hideChildrenInMenu?: boolean;
66
+ /**
67
+ * 当前路由在面包屑中不展现
68
+ * @default false
69
+ */
70
+ hideInBreadcrumb?: boolean;
71
+ /**
72
+ * 当前路由在菜单中不展现
73
+ * @default false
74
+ */
75
+ hideInMenu?: boolean;
76
+ /**
77
+ * 当前路由在标签页不展现
78
+ * @default false
79
+ */
80
+ hideInTab?: boolean;
81
+ /**
82
+ * 图标(菜单/tab)
83
+ */
84
+ icon?: Component | string;
85
+ /**
86
+ * iframe 地址
87
+ */
88
+ iframeSrc?: string;
89
+ /**
90
+ * 忽略权限,直接可以访问
91
+ * @default false
92
+ */
93
+ ignoreAccess?: boolean;
94
+ /**
95
+ * 开启KeepAlive缓存
96
+ */
97
+ keepAlive?: boolean;
98
+ /**
99
+ * 外链-跳转路径
100
+ */
101
+ link?: string;
102
+ /**
103
+ * 路由是否已经加载过
104
+ */
105
+ loaded?: boolean;
106
+ /**
107
+ * 标签页最大打开数量
108
+ * @default -1
109
+ */
110
+ maxNumOfOpenTab?: number;
111
+ /**
112
+ * 菜单可以看到,但是访问会被重定向到403
113
+ */
114
+ menuVisibleWithForbidden?: boolean;
115
+ /**
116
+ * 不使用基础布局(仅在顶级生效)
117
+ */
118
+ noBasicLayout?: boolean;
119
+ /**
120
+ * 在新窗口打开
121
+ */
122
+ openInNewWindow?: boolean;
123
+ /**
124
+ * 用于路由->菜单排序
125
+ */
126
+ order?: number;
127
+ /**
128
+ * 菜单所携带的参数
129
+ */
130
+ query?: Recordable<any>;
131
+ /**
132
+ * 标题名称
133
+ */
134
+ title: string;
135
+ }
136
+
137
+ // 定义递归类型以将 RouteRecordRaw 的 component 属性更改为 string
138
+ type RouteRecordStringComponent<T = string> = Omit<
139
+ RouteRecordRaw,
140
+ 'children' | 'component'
141
+ > & {
142
+ children?: RouteRecordStringComponent<T>[];
143
+ component: T;
144
+ };
145
+
146
+ type ComponentRecordType = Record<string, () => Promise<Component>>;
147
+
148
+ interface GenerateMenuAndRoutesOptions {
149
+ fetchMenuListAsync?: () => Promise<RouteRecordStringComponent[]>;
150
+ forbiddenComponent?: RouteRecordRaw['component'];
151
+ layoutMap?: ComponentRecordType;
152
+ pageMap?: ComponentRecordType;
153
+ roles?: string[];
154
+ router: Router;
155
+ routes: RouteRecordRaw[];
156
+ }
157
+
158
+ // 以 VbenRouteMeta 为底名、RouteMeta 别名导出:本包 barrel 内的
159
+ // declare module 'vue-router' 增强若直接 extends 同名接口,tsdown 打包
160
+ // dist 时会把别名还原成原名,产出 `interface RouteMeta extends RouteMeta`
161
+ // 的自引用声明(消费者 TS2310)。
162
+ export type {
163
+ ComponentRecordType,
164
+ GenerateMenuAndRoutesOptions,
165
+ VbenRouteMeta as RouteMeta,
166
+ RouteRecordRaw,
167
+ RouteRecordStringComponent,
168
+ VbenRouteMeta,
169
+ };
@@ -0,0 +1,37 @@
1
+ import type { MenuRecordRaw } from '@melt-js/libs-vben/typings';
2
+
3
+ function findMenuByPath(
4
+ list: MenuRecordRaw[],
5
+ path?: string,
6
+ ): MenuRecordRaw | null {
7
+ for (const menu of list) {
8
+ if (menu.path === path) {
9
+ return menu;
10
+ }
11
+ const findMenu = menu.children && findMenuByPath(menu.children, path);
12
+ if (findMenu) {
13
+ return findMenu;
14
+ }
15
+ }
16
+ return null;
17
+ }
18
+
19
+ /**
20
+ * 查找根菜单
21
+ * @param menus
22
+ * @param path
23
+ */
24
+ function findRootMenuByPath(menus: MenuRecordRaw[], path?: string, level = 0) {
25
+ const findMenu = findMenuByPath(menus, path);
26
+ const rootMenuPath = findMenu?.parents?.[level];
27
+ const rootMenu = rootMenuPath
28
+ ? menus.find((item) => item.path === rootMenuPath)
29
+ : undefined;
30
+ return {
31
+ findMenu,
32
+ rootMenu,
33
+ rootMenuPath,
34
+ };
35
+ }
36
+
37
+ export { findMenuByPath, findRootMenuByPath };