@oiij/naive-ui 0.0.75 → 0.0.77
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.
- package/README.md +3 -3
- package/dist/components/config-providers/ConfigProviders.vue.d.ts +2 -2
- package/dist/components/config-providers/index.d.ts +16 -7
- package/dist/components/copy-button/CopyButton.js +3 -3
- package/dist/components/copy-button/CopyButton.vue.d.ts +4 -4
- package/dist/components/copy-button/index.d.ts +6 -3
- package/dist/components/data-table-plus/DataTablePlus.js +74 -125
- package/dist/components/data-table-plus/DataTablePlus.vue.d.ts +16 -81
- package/dist/components/data-table-plus/index.d.ts +52 -32
- package/dist/components/index.d.ts +2 -4
- package/dist/components/loading-provider/LoadingProvider.js +2 -2
- package/dist/components/loading-provider/LoadingProvider.vue.d.ts +2 -2
- package/dist/components/loading-provider/index.d.ts +19 -10
- package/dist/components/loading-provider/index.js +5 -2
- package/dist/components/preset-form/PresetForm.js +42 -21
- package/dist/components/preset-form/PresetForm.vue.d.ts +17 -17
- package/dist/components/preset-form/_utils.js +23 -8
- package/dist/components/preset-form/index.d.ts +32 -13
- package/dist/components/preset-input/PresetInput.vue.d.ts +3 -3
- package/dist/components/preset-input/index.d.ts +30 -20
- package/dist/components/preset-picker/PresetPicker.js +31 -34
- package/dist/components/preset-picker/PresetPicker.vue.d.ts +5 -10
- package/dist/components/preset-picker/index.d.ts +45 -31
- package/dist/components/preset-select/PresetSelect.js +23 -59
- package/dist/components/preset-select/PresetSelect.vue.d.ts +34 -38
- package/dist/components/preset-select/index.d.ts +56 -22
- package/dist/components/remote-request/RemoteRequest.js +7 -7
- package/dist/components/remote-request/RemoteRequest.vue.d.ts +7 -7
- package/dist/components/remote-request/index.d.ts +30 -8
- package/dist/components/search-input/SearchInput.js +1 -1
- package/dist/components/search-input/SearchInput.vue.d.ts +4 -4
- package/dist/components/search-input/index.d.ts +10 -7
- package/dist/components/toggle-input/ToggleInput.vue.d.ts +4 -4
- package/dist/components/tooltip-button/TooltipButton.vue.d.ts +4 -4
- package/dist/components/tooltip-button/index.d.ts +5 -2
- package/dist/components/transition/index.d.ts +4 -1
- package/dist/components.d.ts +2 -4
- package/dist/components.js +2 -3
- package/dist/composables/_helper.d.ts +7 -4
- package/dist/composables/_helper.js +47 -0
- package/dist/composables/index.d.ts +1 -1
- package/dist/composables/use-data-request.d.ts +27 -20
- package/dist/composables/use-data-request.js +23 -4
- package/dist/composables/use-loading.d.ts +6 -0
- package/dist/composables/use-loading.js +8 -2
- package/dist/composables/use-naive-form.d.ts +23 -15
- package/dist/composables/use-naive-form.js +49 -40
- package/dist/composables/use-naive-menu.d.ts +104 -0
- package/dist/composables/use-naive-menu.js +133 -0
- package/dist/composables/use-naive-theme.d.ts +27 -14
- package/dist/composables/use-naive-theme.js +22 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +5 -7
- package/dist/components/_utils/prismjs.js +0 -16
- package/dist/components/icons/MageArrowUp.js +0 -29
- package/dist/components/type-writer/TypeWriter.js +0 -75
- package/dist/components/type-writer/TypeWriter.vue.d.ts +0 -22
- package/dist/components/type-writer/index.d.ts +0 -13
- package/dist/components/type-writer/type-writer.cssr.js +0 -27
- package/dist/composables/use-auto-menu.d.ts +0 -74
- package/dist/composables/use-auto-menu.js +0 -129
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { computed, toValue } from "vue";
|
|
2
|
-
|
|
3
|
-
//#region src/composables/use-auto-menu.ts
|
|
4
|
-
/**
|
|
5
|
-
* 获取配置值,支持函数和字符串两种类型
|
|
6
|
-
* @param route 路由配置
|
|
7
|
-
* @param config 配置项,可以是函数或字符串
|
|
8
|
-
* @param defaultValue 默认值
|
|
9
|
-
* @returns 配置值
|
|
10
|
-
*/
|
|
11
|
-
function getConfigValue(route, config, defaultValue) {
|
|
12
|
-
if (!config) return defaultValue;
|
|
13
|
-
if (typeof config === "function") return config(route);
|
|
14
|
-
return route.meta?.[config] ?? defaultValue;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* 创建单个菜单选项
|
|
18
|
-
* @param route 路由配置
|
|
19
|
-
* @param options 配置选项
|
|
20
|
-
* @returns 菜单选项
|
|
21
|
-
*/
|
|
22
|
-
function createMenuOption(route, options) {
|
|
23
|
-
const { label, key, icon } = options ?? {};
|
|
24
|
-
return {
|
|
25
|
-
label: getConfigValue(route, label) ?? route.meta?.title ?? route.name ?? route.path,
|
|
26
|
-
key: getConfigValue(route, key) ?? route.name?.toString() ?? route.path?.toString(),
|
|
27
|
-
icon: icon ? () => icon(route) : void 0,
|
|
28
|
-
meta: route.meta
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* 判断路由是否应该隐藏
|
|
33
|
-
* @param route 路由配置
|
|
34
|
-
* @param hide 隐藏条件
|
|
35
|
-
* @returns 是否隐藏
|
|
36
|
-
*/
|
|
37
|
-
function shouldHide(route, hide) {
|
|
38
|
-
if (!hide) return false;
|
|
39
|
-
const result = getConfigValue(route, hide);
|
|
40
|
-
return typeof result === "boolean" ? result : !!result;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* 判断路由是否为根路由
|
|
44
|
-
* @param route 路由配置
|
|
45
|
-
* @param root 根路由判断
|
|
46
|
-
* @returns 是否为根路由
|
|
47
|
-
*/
|
|
48
|
-
function isRoot(route, root) {
|
|
49
|
-
if (!root) return !!route.meta?.root;
|
|
50
|
-
const result = getConfigValue(route, root);
|
|
51
|
-
return typeof result === "boolean" ? result : !!result;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* 将路由配置转换为菜单配置的递归函数
|
|
55
|
-
* @param routes 路由配置数组
|
|
56
|
-
* @param options 配置选项
|
|
57
|
-
* @returns 菜单配置数组
|
|
58
|
-
*/
|
|
59
|
-
function routes2menu(routes, options) {
|
|
60
|
-
const { hide, root } = options ?? {};
|
|
61
|
-
const menuOptions = [];
|
|
62
|
-
for (const route of routes ?? []) {
|
|
63
|
-
if (shouldHide(route, hide)) continue;
|
|
64
|
-
const menu = createMenuOption(route, options);
|
|
65
|
-
if (route.children?.length) {
|
|
66
|
-
const rootChildren = route.children.filter((child) => isRoot(child, root));
|
|
67
|
-
const normalChildren = route.children.filter((child) => !isRoot(child, root));
|
|
68
|
-
if (normalChildren.length) menu.children = routes2menu(normalChildren, options);
|
|
69
|
-
if (rootChildren.length) {
|
|
70
|
-
const rootMenuOptions = rootChildren.filter((child) => !shouldHide(child, hide)).map((child) => createMenuOption(child, options));
|
|
71
|
-
menuOptions.push(...rootMenuOptions);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
menuOptions.push(menu);
|
|
75
|
-
}
|
|
76
|
-
return menuOptions;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* 深度扁平化菜单选项
|
|
80
|
-
* @param menuOptions 菜单选项数组
|
|
81
|
-
* @returns 扁平化的菜单选项数组
|
|
82
|
-
*/
|
|
83
|
-
function flattenMenuOptions(menuOptions) {
|
|
84
|
-
const flattened = [];
|
|
85
|
-
function processMenu(menu) {
|
|
86
|
-
flattened.push(menu);
|
|
87
|
-
if (menu.children?.length) for (const child of menu.children) processMenu(child);
|
|
88
|
-
}
|
|
89
|
-
for (const menu of menuOptions) processMenu(menu);
|
|
90
|
-
return flattened;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* 自动菜单组合函数
|
|
94
|
-
* @param routes 路由配置数组
|
|
95
|
-
* @param options 配置选项
|
|
96
|
-
* @returns 包含菜单选项和扁平化菜单选项的对象
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* // 基本使用
|
|
100
|
-
* const { menuOptions, flattenedMenuOptions } = useAutoMenu(routes)
|
|
101
|
-
*
|
|
102
|
-
* // 带配置选项(使用函数)
|
|
103
|
-
* const { menuOptions, flattenedMenuOptions } = useAutoMenu(routes, {
|
|
104
|
-
* hide: (route) => route.meta?.hidden,
|
|
105
|
-
* root: (route) => route.meta?.root,
|
|
106
|
-
* label: (route) => route.meta?.title ?? route.name,
|
|
107
|
-
* key: (route) => route.path,
|
|
108
|
-
* icon: (route) => route.meta?.icon
|
|
109
|
-
* })
|
|
110
|
-
*
|
|
111
|
-
* // 带配置选项(使用字符串)
|
|
112
|
-
* const { menuOptions, flattenedMenuOptions } = useAutoMenu(routes, {
|
|
113
|
-
* hide: 'hidden',
|
|
114
|
-
* root: 'root',
|
|
115
|
-
* label: 'title',
|
|
116
|
-
* key: 'path',
|
|
117
|
-
* icon: (route) => route.meta?.icon
|
|
118
|
-
* })
|
|
119
|
-
*/
|
|
120
|
-
function useAutoMenu(routes, options) {
|
|
121
|
-
const menuOptions = computed(() => routes2menu(toValue(routes), options));
|
|
122
|
-
return {
|
|
123
|
-
menuOptions,
|
|
124
|
-
flattenedMenuOptions: computed(() => flattenMenuOptions(menuOptions.value))
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
//#endregion
|
|
129
|
-
export { useAutoMenu };
|