@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,146 @@
1
+ import type {
2
+ IStorageDriver,
3
+ StorageItem,
4
+ StorageManagerOptions,
5
+ } from './types';
6
+
7
+ import { LocalStorageDriver } from './local-storage-driver';
8
+ import { MemoryStorageDriver } from './memory-storage-driver';
9
+
10
+ /**
11
+ * 存储管理器(策略模式)
12
+ * - prefix(命名空间隔离)在此层处理
13
+ * - TTL(过期机制)在此层处理
14
+ * - Driver 只负责纯粹的 KV 存取
15
+ */
16
+ class StorageManager {
17
+ private driver: IStorageDriver;
18
+ private prefix: string;
19
+
20
+ constructor({ driver, prefix = '' }: StorageManagerOptions = {}) {
21
+ this.driver = driver || this.createDefaultDriver();
22
+ this.prefix = prefix;
23
+ if (!this.prefix && this.driver instanceof LocalStorageDriver) {
24
+ console.warn(
25
+ '[StorageManager] empty prefix combined with LocalStorageDriver — clear()/keys() will affect every localStorage entry.',
26
+ );
27
+ }
28
+ }
29
+
30
+ /**
31
+ * 清除所有带前缀的存储项
32
+ */
33
+ async clear(): Promise<void> {
34
+ const allKeys = await this.driver.keys();
35
+ const fullPrefix = this.prefix ? `${this.prefix}-` : '';
36
+ const prefixedKeys = allKeys.filter((key) => key.startsWith(fullPrefix));
37
+ await Promise.all(prefixedKeys.map((key) => this.driver.removeItem(key)));
38
+ }
39
+
40
+ /**
41
+ * 清除所有过期的存储项
42
+ */
43
+ async clearExpiredItems(): Promise<void> {
44
+ const allKeys = await this.driver.keys();
45
+ const fullPrefix = this.prefix ? `${this.prefix}-` : '';
46
+ const prefixedKeys = allKeys.filter((key) => key.startsWith(fullPrefix));
47
+
48
+ for (const fullKey of prefixedKeys) {
49
+ const raw = await this.driver.getItem<StorageItem<unknown>>(fullKey);
50
+ if (raw && raw.expiry && Date.now() > raw.expiry) {
51
+ await this.driver.removeItem(fullKey);
52
+ }
53
+ }
54
+ }
55
+
56
+ /**
57
+ * 获取存储项
58
+ * @param key 键
59
+ * @param defaultValue 当项不存在或已过期时返回的默认值
60
+ * @returns 值,如果项已过期则返回默认值
61
+ */
62
+ async getItem<T>(
63
+ key: string,
64
+ defaultValue: null | T = null,
65
+ ): Promise<null | T> {
66
+ const fullKey = this.getFullKey(key);
67
+ const raw = await this.driver.getItem<StorageItem<T>>(fullKey);
68
+
69
+ if (!raw) {
70
+ return defaultValue;
71
+ }
72
+
73
+ // TTL 检查
74
+ if (raw.expiry && Date.now() > raw.expiry) {
75
+ await this.driver.removeItem(fullKey);
76
+ return defaultValue;
77
+ }
78
+
79
+ return raw.value;
80
+ }
81
+
82
+ /**
83
+ * 获取当前前缀下的所有存储键(已去除前缀部分)
84
+ */
85
+ async keys(): Promise<string[]> {
86
+ const allKeys = await this.driver.keys();
87
+ const fullPrefix = this.prefix ? `${this.prefix}-` : '';
88
+ if (!fullPrefix) return allKeys;
89
+ return allKeys
90
+ .filter((key) => key.startsWith(fullPrefix))
91
+ .map((key) => key.slice(fullPrefix.length));
92
+ }
93
+
94
+ /**
95
+ * 移除存储项
96
+ * @param key 键
97
+ */
98
+ async removeItem(key: string): Promise<void> {
99
+ const fullKey = this.getFullKey(key);
100
+ await this.driver.removeItem(fullKey);
101
+ }
102
+
103
+ /**
104
+ * 设置存储项
105
+ * @param key 键
106
+ * @param value 值
107
+ * @param ttl 存活时间(毫秒)
108
+ */
109
+ async setItem(key: string, value: unknown, ttl?: number): Promise<void> {
110
+ const fullKey = this.getFullKey(key);
111
+ const expiry = ttl ? Date.now() + ttl : undefined;
112
+ const item: StorageItem<unknown> = { expiry, value };
113
+ await this.driver.setItem(fullKey, item);
114
+ }
115
+
116
+ /**
117
+ * 根据运行环境创建默认驱动:
118
+ * - 浏览器环境(window.localStorage 可用)→ LocalStorageDriver
119
+ * - SSR / Node 环境 → MemoryStorageDriver
120
+ */
121
+ private createDefaultDriver(): IStorageDriver {
122
+ try {
123
+ if (typeof window !== 'undefined' && window.localStorage) {
124
+ return new LocalStorageDriver();
125
+ }
126
+ } catch (error) {
127
+ // localStorage access denied (e.g. Safari private mode)
128
+ console.warn(
129
+ 'localStorage is not accessible, falling back to MemoryStorageDriver:',
130
+ error,
131
+ );
132
+ }
133
+ return new MemoryStorageDriver();
134
+ }
135
+
136
+ /**
137
+ * 获取完整的存储键(带前缀)
138
+ * @param key 原始键
139
+ * @returns 带前缀的完整键
140
+ */
141
+ private getFullKey(key: string): string {
142
+ return this.prefix ? `${this.prefix}-${key}` : key;
143
+ }
144
+ }
145
+
146
+ export { StorageManager };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * 存储驱动接口(策略模式核心抽象)
3
+ * 所有存储实现(localStorage、IndexedDB、Memory 等)都需要实现此接口
4
+ * Driver 层只负责纯粹的 KV 存取,不感知 TTL 和前缀
5
+ */
6
+ interface IStorageDriver {
7
+ /** 清除所有存储项 */
8
+ clear(): Promise<void>;
9
+
10
+ /** 获取存储项 */
11
+ getItem<T>(key: string): Promise<null | T>;
12
+
13
+ /** 获取所有 key */
14
+ keys(): Promise<string[]>;
15
+
16
+ /** 移除存储项 */
17
+ removeItem(key: string): Promise<void>;
18
+
19
+ /** 设置存储项 */
20
+ setItem(key: string, value: unknown): Promise<void>;
21
+ }
22
+
23
+ /**
24
+ * 带 TTL 的存储项包装结构
25
+ * TTL 逻辑由 StorageManager 统一管理,Driver 层不感知
26
+ */
27
+ interface StorageItem<T> {
28
+ expiry?: number;
29
+ value: T;
30
+ }
31
+
32
+ interface StorageManagerOptions {
33
+ /** 存储驱动实例 */
34
+ driver?: IStorageDriver;
35
+ /** 键前缀,用于命名空间隔离 */
36
+ prefix?: string;
37
+ }
38
+
39
+ export type { IStorageDriver, StorageItem, StorageManagerOptions };
@@ -0,0 +1,9 @@
1
+ import { TinyColor } from '@ctrl/tinycolor';
2
+
3
+ export function isDarkColor(color: string) {
4
+ return new TinyColor(color).isDark();
5
+ }
6
+
7
+ export function isLightColor(color: string) {
8
+ return new TinyColor(color).isLight();
9
+ }
@@ -0,0 +1,62 @@
1
+ import { TinyColor } from '@ctrl/tinycolor';
2
+
3
+ /**
4
+ * 将颜色转换为HSL格式。
5
+ *
6
+ * HSL是一种颜色模型,包括色相(Hue)、饱和度(Saturation)和亮度(Lightness)三个部分。
7
+ *
8
+ * @param {string} color 输入的颜色。
9
+ * @returns {string} HSL格式的颜色字符串。
10
+ */
11
+ function convertToHsl(color: string): string {
12
+ const { a, h, l, s } = new TinyColor(color).toHsl();
13
+ const hsl = `hsl(${Math.round(h)} ${Math.round(s * 100)}% ${Math.round(l * 100)}%)`;
14
+ return a < 1 ? `${hsl} ${a}` : hsl;
15
+ }
16
+
17
+ /**
18
+ * 将颜色转换为HSL CSS变量。
19
+ *
20
+ * 这个函数与convertToHsl函数类似,但是返回的字符串格式稍有不同,
21
+ * 以便可以作为CSS变量使用。
22
+ *
23
+ * @param {string} color 输入的颜色。
24
+ * @returns {string} 可以作为CSS变量使用的HSL格式的颜色字符串。
25
+ */
26
+ function convertToHslCssVar(color: string): string {
27
+ const { a, h, l, s } = new TinyColor(color).toHsl();
28
+ const hsl = `${Math.round(h)} ${Math.round(s * 100)}% ${Math.round(l * 100)}%`;
29
+ return a < 1 ? `${hsl} / ${a}` : hsl;
30
+ }
31
+
32
+ /**
33
+ * 将颜色转换为RGB颜色字符串
34
+ * TinyColor无法处理hsl内包含'deg'、'grad'、'rad'或'turn'的字符串
35
+ * 比如 hsl(231deg 98% 65%)将被解析为rgb(0, 0, 0)
36
+ * 这里在转换之前先将这些单位去掉
37
+ * @param str 表示HLS颜色值的字符串
38
+ * @returns 如果颜色值有效,则返回对应的RGB颜色字符串;如果无效,则返回rgb(0, 0, 0)
39
+ */
40
+ function convertToRgb(str: string): string {
41
+ return new TinyColor(str.replaceAll(/deg|grad|rad|turn/g, '')).toRgbString();
42
+ }
43
+
44
+ /**
45
+ * 检查颜色是否有效
46
+ * @param {string} color - 待检查的颜色
47
+ * 如果颜色有效返回true,否则返回false
48
+ */
49
+ function isValidColor(color?: string) {
50
+ if (!color) {
51
+ return false;
52
+ }
53
+ return new TinyColor(color).isValid;
54
+ }
55
+
56
+ export {
57
+ convertToHsl,
58
+ convertToHslCssVar,
59
+ convertToRgb,
60
+ isValidColor,
61
+ TinyColor,
62
+ };
@@ -0,0 +1,45 @@
1
+ import { getColors } from 'theme-colors';
2
+
3
+ import { convertToHslCssVar, TinyColor } from './convert';
4
+
5
+ interface ColorItem {
6
+ alias?: string;
7
+ color: string;
8
+ name: string;
9
+ }
10
+
11
+ function generatorColorVariables(colorItems: ColorItem[]) {
12
+ const colorVariables: Record<string, string> = {};
13
+
14
+ colorItems.forEach(({ alias, color, name }) => {
15
+ if (color) {
16
+ const colorsMap = getColors(new TinyColor(color).toHexString());
17
+
18
+ let mainColor = colorsMap['500'];
19
+
20
+ const colorKeys = Object.keys(colorsMap);
21
+
22
+ colorKeys.forEach((key) => {
23
+ const colorValue = colorsMap[key];
24
+
25
+ if (colorValue) {
26
+ const hslColor = convertToHslCssVar(colorValue);
27
+ colorVariables[`--${name}-${key}`] = hslColor;
28
+ if (alias) {
29
+ colorVariables[`--${alias}-${key}`] = hslColor;
30
+ }
31
+
32
+ if (key === '500') {
33
+ mainColor = hslColor;
34
+ }
35
+ }
36
+ });
37
+ if (alias && mainColor) {
38
+ colorVariables[`--${alias}`] = mainColor;
39
+ }
40
+ }
41
+ });
42
+ return colorVariables;
43
+ }
44
+
45
+ export { generatorColorVariables };
@@ -0,0 +1,3 @@
1
+ export * from './color';
2
+ export * from './convert';
3
+ export * from './generator';
@@ -0,0 +1,20 @@
1
+ /** layout content 组件的高度 */
2
+ export const CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT = `--vben-content-height`;
3
+ /** layout content 组件的宽度 */
4
+ export const CSS_VARIABLE_LAYOUT_CONTENT_WIDTH = `--vben-content-width`;
5
+ /** layout header 组件的高度 */
6
+ export const CSS_VARIABLE_LAYOUT_HEADER_HEIGHT = `--vben-header-height`;
7
+ /** layout footer 组件的高度 */
8
+ export const CSS_VARIABLE_LAYOUT_FOOTER_HEIGHT = `--vben-footer-height`;
9
+ /** layout overlay 使用的视口高度,CSS 按 100vh → 100dvh 降级 */
10
+ export const CSS_VARIABLE_LAYOUT_VIEWPORT_HEIGHT = `--vben-viewport-height`;
11
+
12
+ /** 内容区域的组件ID */
13
+ export const ELEMENT_ID_MAIN_CONTENT = `__vben_main_content`;
14
+ /** layout 滚动容器ID */
15
+ export const ELEMENT_ID_LAYOUT_SCROLL = `__vben_layout_scroll`;
16
+
17
+ /**
18
+ * @zh_CN 默认命名空间
19
+ */
20
+ export const DEFAULT_NAMESPACE = 'vben';
@@ -0,0 +1,2 @@
1
+ export * from './globals';
2
+ export * from './vben';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @zh_CN GITHUB 仓库地址
3
+ */
4
+ export const VBEN_GITHUB_URL = 'https://github.com/vbenjs/vue-vben-admin';
5
+
6
+ /**
7
+ * @zh_CN 文档地址
8
+ */
9
+ export const VBEN_DOC_URL = 'https://doc.vben.pro';
10
+
11
+ /**
12
+ * @zh_CN Vben Logo
13
+ */
14
+ export const VBEN_LOGO_URL =
15
+ 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp';
16
+
17
+ /**
18
+ * @zh_CN Vben Admin 首页地址
19
+ */
20
+ export const VBEN_PREVIEW_URL = 'https://www.vben.pro';
21
+
22
+ export const VBEN_ANTDV_NEXT_PREVIEW_URL = 'https://antdv-next.vben.pro';
23
+
24
+ export const VBEN_ELE_PREVIEW_URL = 'https://ele.vben.pro';
25
+
26
+ export const VBEN_NAIVE_PREVIEW_URL = 'https://naive.vben.pro';
27
+
28
+ export const VBEN_ANT_PREVIEW_URL = 'https://ant.vben.pro';
29
+
30
+ export const VBEN_TD_PREVIEW_URL = 'https://tdesign.vben.pro';
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 全局复用的变量、组件、配置,各个模块之间共享
3
+ * 通过单例模式实现,单例必须注意不受请求影响,例如用户信息这些需要根据请求获取的。后续如果有ssr需求,也不会影响
4
+ */
5
+
6
+ interface ComponentsState {
7
+ [key: string]: any;
8
+ }
9
+
10
+ interface MessageState {
11
+ copyPreferencesSuccess?: (title: string, content?: string) => void;
12
+ }
13
+
14
+ export interface IGlobalSharedState {
15
+ components: ComponentsState;
16
+ message: MessageState;
17
+ }
18
+
19
+ class GlobalShareState {
20
+ #components: ComponentsState = {};
21
+ #message: MessageState = {};
22
+
23
+ /**
24
+ * 定义框架内部各个场景的消息提示
25
+ */
26
+ public defineMessage({ copyPreferencesSuccess }: MessageState) {
27
+ this.#message = {
28
+ copyPreferencesSuccess,
29
+ };
30
+ }
31
+
32
+ public getComponents(): ComponentsState {
33
+ return this.#components;
34
+ }
35
+
36
+ public getMessage(): MessageState {
37
+ return this.#message;
38
+ }
39
+
40
+ public setComponents(value: ComponentsState) {
41
+ this.#components = value;
42
+ }
43
+ }
44
+
45
+ export const globalShareState = new GlobalShareState();
@@ -0,0 +1 @@
1
+ export * from '@tanstack/vue-store';
@@ -0,0 +1,10 @@
1
+ import type { ClassValue } from 'clsx';
2
+
3
+ import { clsx } from 'clsx';
4
+ import { twMerge } from 'tailwind-merge';
5
+
6
+ function cn(...inputs: ClassValue[]) {
7
+ return twMerge(clsx(inputs));
8
+ }
9
+
10
+ export { cn };
@@ -0,0 +1,80 @@
1
+ import dayjs from 'dayjs';
2
+ import timezone from 'dayjs/plugin/timezone.js';
3
+ import utc from 'dayjs/plugin/utc.js';
4
+
5
+ import { getErrorMessage } from './error';
6
+
7
+ dayjs.extend(utc);
8
+ dayjs.extend(timezone);
9
+
10
+ type FormatDate = Date | dayjs.Dayjs | number | string;
11
+
12
+ type Format =
13
+ | 'HH'
14
+ | 'HH:mm'
15
+ | 'HH:mm:ss'
16
+ | 'YYYY'
17
+ | 'YYYY-MM'
18
+ | 'YYYY-MM-DD'
19
+ | 'YYYY-MM-DD HH'
20
+ | 'YYYY-MM-DD HH:mm'
21
+ | 'YYYY-MM-DD HH:mm:ss'
22
+ | (string & {});
23
+
24
+ export function formatDate(time?: FormatDate, format: Format = 'YYYY-MM-DD') {
25
+ if (time === undefined || time === null || time === '') {
26
+ return '';
27
+ }
28
+ try {
29
+ const date = dayjs.isDayjs(time) ? time : dayjs(time);
30
+ if (!date.isValid()) {
31
+ throw new Error('Invalid date');
32
+ }
33
+ return date.tz().format(format);
34
+ } catch (error) {
35
+ console.error(`Error formatting date: ${getErrorMessage(error)}`);
36
+ return String(time ?? '');
37
+ }
38
+ }
39
+
40
+ export function formatDateTime(time?: FormatDate) {
41
+ return formatDate(time, 'YYYY-MM-DD HH:mm:ss');
42
+ }
43
+
44
+ export function isDate(value: any): value is Date {
45
+ return value instanceof Date;
46
+ }
47
+
48
+ export function isDayjsObject(value: any): value is dayjs.Dayjs {
49
+ return dayjs.isDayjs(value);
50
+ }
51
+
52
+ /**
53
+ * 获取当前时区
54
+ * @returns 当前时区
55
+ */
56
+ export const getSystemTimezone = () => {
57
+ return dayjs.tz.guess();
58
+ };
59
+
60
+ /**
61
+ * 自定义设置的时区
62
+ */
63
+ let currentTimezone = getSystemTimezone();
64
+
65
+ /**
66
+ * 设置默认时区
67
+ * @param timezone
68
+ */
69
+ export const setCurrentTimezone = (timezone?: string) => {
70
+ currentTimezone = timezone || getSystemTimezone();
71
+ dayjs.tz.setDefault(currentTimezone);
72
+ };
73
+
74
+ /**
75
+ * 获取设置的时区
76
+ * @returns 设置的时区
77
+ */
78
+ export const getCurrentTimezone = () => {
79
+ return currentTimezone;
80
+ };
@@ -0,0 +1,114 @@
1
+ // type Diff<T = any> = T;
2
+
3
+ // 比较两个数组是否相等(忽略顺序)
4
+
5
+ function arraysEqual<T>(a: T[], b: T[]): boolean {
6
+ if (a.length !== b.length) return false;
7
+ const counter = new Map<T, number>();
8
+ for (const value of a) {
9
+ counter.set(value, (counter.get(value) || 0) + 1);
10
+ }
11
+ for (const value of b) {
12
+ const count = counter.get(value);
13
+ if (count === undefined || count === 0) {
14
+ return false;
15
+ }
16
+ counter.set(value, count - 1);
17
+ }
18
+ return true;
19
+ }
20
+
21
+ // 比较两个数组是否相等(顺序敏感)
22
+ function arraysStrictEqual<T>(a: T[], b: T[]): boolean {
23
+ return a.length === b.length && a.every((value, index) => value === b[index]);
24
+ }
25
+
26
+ // 深度对比两个值
27
+ // function deepEqual<T>(oldVal: T, newVal: T): boolean {
28
+ // if (
29
+ // typeof oldVal === 'object' &&
30
+ // oldVal !== null &&
31
+ // typeof newVal === 'object' &&
32
+ // newVal !== null
33
+ // ) {
34
+ // return Array.isArray(oldVal) && Array.isArray(newVal)
35
+ // ? arraysEqual(oldVal, newVal)
36
+ // : diff(oldVal as any, newVal as any) === null;
37
+ // } else {
38
+ // return oldVal === newVal;
39
+ // }
40
+ // }
41
+
42
+ // // diff 函数
43
+ // function diff<T extends object>(
44
+ // oldObj: T,
45
+ // newObj: T,
46
+ // ignoreFields: (keyof T)[] = [],
47
+ // ): { [K in keyof T]?: Diff<T[K]> } | null {
48
+ // const difference: { [K in keyof T]?: Diff<T[K]> } = {};
49
+
50
+ // for (const key in oldObj) {
51
+ // if (ignoreFields.includes(key)) continue;
52
+ // const oldValue = oldObj[key];
53
+ // const newValue = newObj[key];
54
+
55
+ // if (!deepEqual(oldValue, newValue)) {
56
+ // difference[key] = newValue;
57
+ // }
58
+ // }
59
+
60
+ // return Object.keys(difference).length === 0 ? null : difference;
61
+ // }
62
+
63
+ type DiffResult<T> = Partial<{
64
+ [K in keyof T]: T[K] extends object ? DiffResult<T[K]> : T[K];
65
+ }>;
66
+
67
+ type ArrayComparator = (a: any[], b: any[]) => boolean;
68
+
69
+ function createDiff(arrayEquals: ArrayComparator) {
70
+ return function <T extends Record<string, any>>(
71
+ obj1: T,
72
+ obj2: T,
73
+ ): DiffResult<T> {
74
+ function findDifferences(o1: any, o2: any): any {
75
+ if (Array.isArray(o1) && Array.isArray(o2)) {
76
+ if (!arrayEquals(o1, o2)) {
77
+ return o2;
78
+ }
79
+ return undefined;
80
+ }
81
+
82
+ if (
83
+ typeof o1 === 'object' &&
84
+ typeof o2 === 'object' &&
85
+ o1 !== null &&
86
+ o2 !== null
87
+ ) {
88
+ const diffResult: any = {};
89
+
90
+ const keys = new Set([...Object.keys(o1), ...Object.keys(o2)]);
91
+ keys.forEach((key) => {
92
+ const valueDiff = findDifferences(o1[key], o2[key]);
93
+ if (valueDiff !== undefined) {
94
+ diffResult[key] = valueDiff;
95
+ }
96
+ });
97
+
98
+ return Object.keys(diffResult).length > 0 ? diffResult : undefined;
99
+ }
100
+
101
+ return o1 === o2 ? undefined : o2;
102
+ }
103
+
104
+ return findDifferences(obj1, obj2);
105
+ };
106
+ }
107
+
108
+ // 数组比较(不含顺序)
109
+ const diff = createDiff(arraysEqual);
110
+
111
+ // 数组比较(含顺序)
112
+ const diffStrict = createDiff(arraysStrictEqual);
113
+
114
+ export { arraysEqual, arraysStrictEqual, diff, diffStrict };