@oiij/naive-ui 0.0.73 → 0.0.75
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 +132 -4
- package/dist/components/config-providers/ConfigProviders.vue.d.ts +2 -2
- package/dist/components/copy-button/CopyButton.js +1 -1
- package/dist/components/copy-button/CopyButton.vue.d.ts +4 -4
- package/dist/components/data-table-plus/DataTablePlus.js +4 -4
- package/dist/components/data-table-plus/DataTablePlus.vue.d.ts +18 -18
- package/dist/components/data-table-plus/index.d.ts +1 -1
- package/dist/components/loading-provider/LoadingProvider.vue.d.ts +2 -2
- package/dist/components/preset-form/PresetForm.js +11 -11
- package/dist/components/preset-form/PresetForm.vue.d.ts +17 -26
- package/dist/components/preset-input/PresetInput.vue.d.ts +3 -3
- package/dist/components/preset-picker/PresetPicker.vue.d.ts +4 -4
- package/dist/components/preset-select/PresetSelect.js +4 -4
- package/dist/components/preset-select/PresetSelect.vue.d.ts +9 -9
- package/dist/components/preset-select/index.d.ts +1 -1
- package/dist/components/remote-request/RemoteRequest.vue.d.ts +4 -4
- package/dist/components/search-input/SearchInput.js +1 -1
- package/dist/components/search-input/SearchInput.vue.d.ts +4 -4
- 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/transition/BaseTransition.vue.d.ts +2 -2
- package/dist/components/type-writer/TypeWriter.js +2 -2
- package/dist/components/type-writer/TypeWriter.vue.d.ts +4 -4
- package/dist/composables/index.d.ts +1 -0
- package/dist/composables/use-auto-menu.d.ts +74 -0
- package/dist/composables/use-auto-menu.js +129 -0
- package/dist/composables/use-data-request.d.ts +60 -30
- package/dist/composables/use-data-request.js +24 -1
- package/dist/composables/use-loading.d.ts +4 -0
- package/dist/composables/use-loading.js +8 -0
- package/dist/composables/use-naive-form.d.ts +42 -19
- package/dist/composables/use-naive-form.js +49 -5
- package/dist/composables/use-naive-theme.d.ts +33 -16
- package/dist/composables/use-naive-theme.js +16 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +7 -5
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DataObject, UseDataRequestPagination } from "../../composables/use-data-request.js";
|
|
2
2
|
import { PresetSelectEmits, PresetSelectExpose, PresetSelectProps, PresetSelectValue } from "./index.js";
|
|
3
|
+
import * as vue49 from "vue";
|
|
3
4
|
import * as _vueuse_core11 from "@vueuse/core";
|
|
4
|
-
import * as vue66 from "vue";
|
|
5
5
|
import { SelectInst, SelectOption } from "naive-ui";
|
|
6
6
|
|
|
7
7
|
//#region src/components/preset-select/PresetSelect.vue.d.ts
|
|
8
8
|
declare const __VLS_export: <V extends PresetSelectValue, P extends DataObject, D extends DataObject, R extends DataObject>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
9
|
-
props:
|
|
9
|
+
props: vue49.PublicProps & __VLS_PrettifyLocal<PresetSelectProps<V, P, D, R> & {
|
|
10
10
|
onSuccess?: ((data: D, params: P[]) => any) | undefined;
|
|
11
11
|
onError?: ((err: Error, params: P[]) => any) | undefined;
|
|
12
12
|
onClear?: (() => any) | undefined;
|
|
@@ -23,7 +23,7 @@ declare const __VLS_export: <V extends PresetSelectValue, P extends DataObject,
|
|
|
23
23
|
}> & (typeof globalThis extends {
|
|
24
24
|
__VLS_PROPS_FALLBACK: infer P_1;
|
|
25
25
|
} ? P_1 : {});
|
|
26
|
-
expose: (exposed:
|
|
26
|
+
expose: (exposed: vue49.ShallowUnwrapRef<PresetSelectExpose<P, D, R>>) => void;
|
|
27
27
|
attrs: any;
|
|
28
28
|
slots: {
|
|
29
29
|
header?: (props: {
|
|
@@ -37,7 +37,7 @@ declare const __VLS_export: <V extends PresetSelectValue, P extends DataObject,
|
|
|
37
37
|
pageSize: number;
|
|
38
38
|
itemCount: number;
|
|
39
39
|
};
|
|
40
|
-
|
|
40
|
+
selectInst: SelectInst | null;
|
|
41
41
|
run: (...params: P[]) => void;
|
|
42
42
|
runAsync: (...params: P[]) => Promise<D>;
|
|
43
43
|
refresh: () => void;
|
|
@@ -64,7 +64,7 @@ declare const __VLS_export: <V extends PresetSelectValue, P extends DataObject,
|
|
|
64
64
|
pageSize: number;
|
|
65
65
|
itemCount: number;
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
selectInst: SelectInst | null;
|
|
68
68
|
run: (...params: P[]) => void;
|
|
69
69
|
runAsync: (...params: P[]) => Promise<D>;
|
|
70
70
|
refresh: () => void;
|
|
@@ -91,7 +91,7 @@ declare const __VLS_export: <V extends PresetSelectValue, P extends DataObject,
|
|
|
91
91
|
pageSize: number;
|
|
92
92
|
itemCount: number;
|
|
93
93
|
};
|
|
94
|
-
|
|
94
|
+
selectInst: SelectInst | null;
|
|
95
95
|
run: (...params: P[]) => void;
|
|
96
96
|
runAsync: (...params: P[]) => Promise<D>;
|
|
97
97
|
refresh: () => void;
|
|
@@ -118,7 +118,7 @@ declare const __VLS_export: <V extends PresetSelectValue, P extends DataObject,
|
|
|
118
118
|
pageSize: number;
|
|
119
119
|
itemCount: number;
|
|
120
120
|
};
|
|
121
|
-
|
|
121
|
+
selectInst: SelectInst | null;
|
|
122
122
|
run: (...params: P[]) => void;
|
|
123
123
|
runAsync: (...params: P[]) => Promise<D>;
|
|
124
124
|
refresh: () => void;
|
|
@@ -145,7 +145,7 @@ declare const __VLS_export: <V extends PresetSelectValue, P extends DataObject,
|
|
|
145
145
|
pageSize: number;
|
|
146
146
|
itemCount: number;
|
|
147
147
|
};
|
|
148
|
-
|
|
148
|
+
selectInst: SelectInst | null;
|
|
149
149
|
run: (...params: P[]) => void;
|
|
150
150
|
runAsync: (...params: P[]) => Promise<D>;
|
|
151
151
|
refresh: () => void;
|
|
@@ -162,7 +162,7 @@ declare const __VLS_export: <V extends PresetSelectValue, P extends DataObject,
|
|
|
162
162
|
}) => any;
|
|
163
163
|
};
|
|
164
164
|
emit: PresetSelectEmits<V, P, D, R>;
|
|
165
|
-
}>) =>
|
|
165
|
+
}>) => vue49.VNode & {
|
|
166
166
|
__ctx?: Awaited<typeof __VLS_setup>;
|
|
167
167
|
};
|
|
168
168
|
declare const _default: typeof __VLS_export;
|
|
@@ -18,7 +18,7 @@ type PresetSelectFields = DataRequestFields & {
|
|
|
18
18
|
children?: string;
|
|
19
19
|
};
|
|
20
20
|
type PresetSelectExpose<P extends DataObject = DataObject, D extends DataObject = DataObject, R extends DataObject = DataObject> = UseDataRequestReturns<P, D, R> & {
|
|
21
|
-
|
|
21
|
+
selectInst: Readonly<ShallowRef<SelectInst | null>>;
|
|
22
22
|
};
|
|
23
23
|
type PresetSelectProps<V extends PresetSelectValue, P extends DataObject = DataObject, D extends DataObject = DataObject, R extends DataObject = DataObject> = RemoteRequestProps<P, D> & {
|
|
24
24
|
value?: V;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { DataObject, UseDataRequestPagination } from "../../composables/use-data-request.js";
|
|
2
2
|
import { RemoteRequestEmits, RemoteRequestExpose, RemoteRequestProps } from "./index.js";
|
|
3
|
+
import * as vue22 from "vue";
|
|
3
4
|
import * as _vueuse_core4 from "@vueuse/core";
|
|
4
|
-
import * as vue38 from "vue";
|
|
5
5
|
|
|
6
6
|
//#region src/components/remote-request/RemoteRequest.vue.d.ts
|
|
7
7
|
declare const __VLS_export: <P extends DataObject, D extends DataObject, R extends DataObject>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
8
|
-
props:
|
|
8
|
+
props: vue22.PublicProps & __VLS_PrettifyLocal<RemoteRequestProps<P, D> & {
|
|
9
9
|
onSuccess?: ((data: D, params: P[]) => any) | undefined;
|
|
10
10
|
onError?: ((err: Error, params: P[]) => any) | undefined;
|
|
11
11
|
onFinally?: ((params: P[], data?: D | undefined, err?: Error | undefined) => any) | undefined;
|
|
@@ -13,7 +13,7 @@ declare const __VLS_export: <P extends DataObject, D extends DataObject, R exten
|
|
|
13
13
|
}> & (typeof globalThis extends {
|
|
14
14
|
__VLS_PROPS_FALLBACK: infer P_1;
|
|
15
15
|
} ? P_1 : {});
|
|
16
|
-
expose: (exposed:
|
|
16
|
+
expose: (exposed: vue22.ShallowUnwrapRef<RemoteRequestExpose<P, D, R>>) => void;
|
|
17
17
|
attrs: any;
|
|
18
18
|
slots: {
|
|
19
19
|
default?: (props: {
|
|
@@ -43,7 +43,7 @@ declare const __VLS_export: <P extends DataObject, D extends DataObject, R exten
|
|
|
43
43
|
}) => any;
|
|
44
44
|
};
|
|
45
45
|
emit: RemoteRequestEmits<P, D>;
|
|
46
|
-
}>) =>
|
|
46
|
+
}>) => vue22.VNode & {
|
|
47
47
|
__ctx?: Awaited<typeof __VLS_setup>;
|
|
48
48
|
};
|
|
49
49
|
declare const _default: typeof __VLS_export;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import MageSearch_default from "../icons/MageSearch.js";
|
|
2
|
-
import { useDebounceFn, useTimeoutFn } from "@vueuse/core";
|
|
3
2
|
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createSlots, createTextVNode, createVNode, defineComponent, mergeProps, openBlock, ref, renderSlot, unref, useTemplateRef, watch, watchEffect, withCtx } from "vue";
|
|
3
|
+
import { useDebounceFn, useTimeoutFn } from "@vueuse/core";
|
|
4
4
|
import { NButton, NInput, NInputGroup } from "naive-ui";
|
|
5
5
|
|
|
6
6
|
//#region src/components/search-input/SearchInput.vue
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SearchInputProps } from "./index.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as vue57 from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/components/search-input/SearchInput.vue.d.ts
|
|
5
5
|
declare var __VLS_19: {}, __VLS_21: {}, __VLS_28: {
|
|
@@ -15,11 +15,11 @@ type __VLS_Slots = {} & {
|
|
|
15
15
|
} & {
|
|
16
16
|
'button-icon'?: (props: typeof __VLS_39) => any;
|
|
17
17
|
};
|
|
18
|
-
declare const __VLS_base:
|
|
18
|
+
declare const __VLS_base: vue57.DefineComponent<SearchInputProps, {}, {}, {}, {}, vue57.ComponentOptionsMixin, vue57.ComponentOptionsMixin, {} & {
|
|
19
19
|
"update:value": (v: string | null | undefined) => any;
|
|
20
|
-
}, string,
|
|
20
|
+
}, string, vue57.PublicProps, Readonly<SearchInputProps> & Readonly<{
|
|
21
21
|
"onUpdate:value"?: ((v: string | null | undefined) => any) | undefined;
|
|
22
|
-
}>, {}, {}, {}, {}, string,
|
|
22
|
+
}>, {}, {}, {}, {}, string, vue57.ComponentProvideOptions, false, {}, any>;
|
|
23
23
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
24
24
|
declare const _default: typeof __VLS_export;
|
|
25
25
|
type __VLS_WithSlots<T, S> = T & {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClassStyle } from "../data-table-plus/index.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as vue15 from "vue";
|
|
3
3
|
import { InputProps } from "naive-ui";
|
|
4
4
|
|
|
5
5
|
//#region src/components/toggle-input/ToggleInput.vue.d.ts
|
|
@@ -27,14 +27,14 @@ type __VLS_Slots = {} & {
|
|
|
27
27
|
} & {
|
|
28
28
|
default?: (props: typeof __VLS_13) => any;
|
|
29
29
|
};
|
|
30
|
-
declare const __VLS_base:
|
|
30
|
+
declare const __VLS_base: vue15.DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, vue15.ComponentOptionsMixin, vue15.ComponentOptionsMixin, {
|
|
31
31
|
"update:value": (value: string | number | undefined) => any;
|
|
32
32
|
} & {
|
|
33
33
|
trigger: () => any;
|
|
34
|
-
}, string,
|
|
34
|
+
}, string, vue15.PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
35
35
|
"onUpdate:value"?: ((value: string | number | undefined) => any) | undefined;
|
|
36
36
|
onTrigger?: (() => any) | undefined;
|
|
37
|
-
}>, {}, {}, {}, {}, string,
|
|
37
|
+
}>, {}, {}, {}, {}, string, vue15.ComponentProvideOptions, false, {}, any>;
|
|
38
38
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
39
39
|
declare const _default: typeof __VLS_export;
|
|
40
40
|
type __VLS_WithSlots<T, S> = T & {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TooltipButtonProps } from "./index.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as vue10 from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/components/tooltip-button/TooltipButton.vue.d.ts
|
|
5
5
|
declare var __VLS_17: {}, __VLS_20: {}, __VLS_22: {};
|
|
@@ -10,11 +10,11 @@ type __VLS_Slots = {} & {
|
|
|
10
10
|
} & {
|
|
11
11
|
tooltip?: (props: typeof __VLS_22) => any;
|
|
12
12
|
};
|
|
13
|
-
declare const __VLS_base:
|
|
13
|
+
declare const __VLS_base: vue10.DefineComponent<TooltipButtonProps, {}, {}, {}, {}, vue10.ComponentOptionsMixin, vue10.ComponentOptionsMixin, {} & {
|
|
14
14
|
click: (ev: MouseEvent) => any;
|
|
15
|
-
}, string,
|
|
15
|
+
}, string, vue10.PublicProps, Readonly<TooltipButtonProps> & Readonly<{
|
|
16
16
|
onClick?: ((ev: MouseEvent) => any) | undefined;
|
|
17
|
-
}>, {}, {}, {}, {}, string,
|
|
17
|
+
}>, {}, {}, {}, {}, string, vue10.ComponentProvideOptions, false, {}, any>;
|
|
18
18
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
19
19
|
declare const _default: typeof __VLS_export;
|
|
20
20
|
type __VLS_WithSlots<T, S> = T & {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { TransitionProps as TransitionProps$1 } from "./index.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as vue30 from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/components/transition/BaseTransition.vue.d.ts
|
|
5
5
|
declare var __VLS_7: {};
|
|
6
6
|
type __VLS_Slots = {} & {
|
|
7
7
|
default?: (props: typeof __VLS_7) => any;
|
|
8
8
|
};
|
|
9
|
-
declare const __VLS_base:
|
|
9
|
+
declare const __VLS_base: vue30.DefineComponent<TransitionProps$1, {}, {}, {}, {}, vue30.ComponentOptionsMixin, vue30.ComponentOptionsMixin, {}, string, vue30.PublicProps, Readonly<TransitionProps$1> & Readonly<{}>, {}, {}, {}, {}, string, vue30.ComponentProvideOptions, false, {}, any>;
|
|
10
10
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
11
11
|
declare const _default: typeof __VLS_export;
|
|
12
12
|
type __VLS_WithSlots<T, S> = T & {
|
|
@@ -43,7 +43,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
43
43
|
onStop((v) => {
|
|
44
44
|
emit("stop", v);
|
|
45
45
|
});
|
|
46
|
-
const {
|
|
46
|
+
const { html } = useMarkdownIt(void 0, {
|
|
47
47
|
value: typedValue,
|
|
48
48
|
markdownItOptions: {
|
|
49
49
|
html: true,
|
|
@@ -53,7 +53,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
53
53
|
highlight
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
|
-
const renderValue = computed(() => __props.markdown ?
|
|
56
|
+
const renderValue = computed(() => __props.markdown ? html.value : typedValue.value);
|
|
57
57
|
return (_ctx, _cache) => {
|
|
58
58
|
return openBlock(), createBlock(unref(NEl), {
|
|
59
59
|
tag: "div",
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { TypeWriterProps } from "./index.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as vue75 from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/components/type-writer/TypeWriter.vue.d.ts
|
|
5
|
-
declare const __VLS_export:
|
|
5
|
+
declare const __VLS_export: vue75.DefineComponent<TypeWriterProps, {}, {}, {}, {}, vue75.ComponentOptionsMixin, vue75.ComponentOptionsMixin, {} & {
|
|
6
6
|
start: () => any;
|
|
7
7
|
update: (v: {
|
|
8
8
|
index: number;
|
|
9
9
|
value: string;
|
|
10
10
|
}) => any;
|
|
11
11
|
stop: (v: string) => any;
|
|
12
|
-
}, string,
|
|
12
|
+
}, string, vue75.PublicProps, Readonly<TypeWriterProps> & Readonly<{
|
|
13
13
|
onStart?: (() => any) | undefined;
|
|
14
14
|
onUpdate?: ((v: {
|
|
15
15
|
index: number;
|
|
16
16
|
value: string;
|
|
17
17
|
}) => any) | undefined;
|
|
18
18
|
onStop?: ((v: string) => any) | undefined;
|
|
19
|
-
}>, {}, {}, {}, {}, string,
|
|
19
|
+
}>, {}, {}, {}, {}, string, vue75.ComponentProvideOptions, false, {}, any>;
|
|
20
20
|
declare const _default: typeof __VLS_export;
|
|
21
21
|
//#endregion
|
|
22
22
|
export { _default };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UseAutoMenuReturn, useAutoMenu } from "./use-auto-menu.js";
|
|
1
2
|
import { DataObject, DataRequestFields, UseDataRequestOptions, UseDataRequestPagination, UseDataRequestReturns, useDataRequest } from "./use-data-request.js";
|
|
2
3
|
import { useLoading } from "./use-loading.js";
|
|
3
4
|
import { UseNaiveFormClearRules, UseNaiveFormOptions, UseNaiveFormReturns, UseNaiveFormRules, useNaiveForm } from "./use-naive-form.js";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as vue0 from "vue";
|
|
2
|
+
import { MaybeRefOrGetter, VNode } from "vue";
|
|
3
|
+
import { MenuOption } from "naive-ui";
|
|
4
|
+
import { RouteRecordRaw } from "vue-router";
|
|
5
|
+
|
|
6
|
+
//#region src/composables/use-auto-menu.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* 配置选项接口
|
|
9
|
+
*/
|
|
10
|
+
type Options = {
|
|
11
|
+
/**
|
|
12
|
+
* 隐藏条件,可以是函数或字符串
|
|
13
|
+
* - 如果是函数,返回 true 时路由将不显示在菜单中
|
|
14
|
+
* - 如果是字符串,则从 route.meta 中获取对应属性的值
|
|
15
|
+
*/
|
|
16
|
+
hide?: ((route: RouteRecordRaw) => boolean | string) | string;
|
|
17
|
+
/**
|
|
18
|
+
* 根路由判断,可以是函数或字符串
|
|
19
|
+
* - 如果是函数,返回 true 时路由将作为顶级菜单
|
|
20
|
+
* - 如果是字符串,则从 route.meta 中获取对应属性的值
|
|
21
|
+
*/
|
|
22
|
+
root?: ((route: RouteRecordRaw) => boolean | string) | string;
|
|
23
|
+
/**
|
|
24
|
+
* 标签生成,可以是函数或字符串
|
|
25
|
+
* - 如果是函数,使用函数返回值作为菜单项的显示文本
|
|
26
|
+
* - 如果是字符串,则从 route.meta 中获取对应属性的值
|
|
27
|
+
*/
|
|
28
|
+
label?: ((route: RouteRecordRaw) => string) | string;
|
|
29
|
+
/**
|
|
30
|
+
* 键生成,可以是函数或字符串
|
|
31
|
+
* - 如果是函数,使用函数返回值作为菜单项的唯一标识
|
|
32
|
+
* - 如果是字符串,则从 route.meta 中获取对应属性的值
|
|
33
|
+
*/
|
|
34
|
+
key?: ((route: RouteRecordRaw) => string) | string;
|
|
35
|
+
/**
|
|
36
|
+
* 图标渲染函数,用于自定义路由图标
|
|
37
|
+
*/
|
|
38
|
+
icon?: (route: RouteRecordRaw) => VNode | string | undefined | null;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* 自动菜单组合函数
|
|
42
|
+
* @param routes 路由配置数组
|
|
43
|
+
* @param options 配置选项
|
|
44
|
+
* @returns 包含菜单选项和扁平化菜单选项的对象
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // 基本使用
|
|
48
|
+
* const { menuOptions, flattenedMenuOptions } = useAutoMenu(routes)
|
|
49
|
+
*
|
|
50
|
+
* // 带配置选项(使用函数)
|
|
51
|
+
* const { menuOptions, flattenedMenuOptions } = useAutoMenu(routes, {
|
|
52
|
+
* hide: (route) => route.meta?.hidden,
|
|
53
|
+
* root: (route) => route.meta?.root,
|
|
54
|
+
* label: (route) => route.meta?.title ?? route.name,
|
|
55
|
+
* key: (route) => route.path,
|
|
56
|
+
* icon: (route) => route.meta?.icon
|
|
57
|
+
* })
|
|
58
|
+
*
|
|
59
|
+
* // 带配置选项(使用字符串)
|
|
60
|
+
* const { menuOptions, flattenedMenuOptions } = useAutoMenu(routes, {
|
|
61
|
+
* hide: 'hidden',
|
|
62
|
+
* root: 'root',
|
|
63
|
+
* label: 'title',
|
|
64
|
+
* key: 'path',
|
|
65
|
+
* icon: (route) => route.meta?.icon
|
|
66
|
+
* })
|
|
67
|
+
*/
|
|
68
|
+
declare function useAutoMenu(routes: MaybeRefOrGetter<RouteRecordRaw[]>, options?: Options): {
|
|
69
|
+
menuOptions: vue0.ComputedRef<MenuOption[]>;
|
|
70
|
+
flattenedMenuOptions: vue0.ComputedRef<MenuOption[]>;
|
|
71
|
+
};
|
|
72
|
+
type UseAutoMenuReturn = ReturnType<typeof useAutoMenu>;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { UseAutoMenuReturn, useAutoMenu };
|
|
@@ -0,0 +1,129 @@
|
|
|
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 };
|
|
@@ -1,35 +1,59 @@
|
|
|
1
|
+
import * as vue4 from "vue";
|
|
1
2
|
import * as _vueuse_core0 from "@vueuse/core";
|
|
2
|
-
import * as vue0 from "vue";
|
|
3
3
|
import { UseRequestOptions, UseRequestPlugin } from "vue-hooks-plus/es/useRequest/types";
|
|
4
4
|
|
|
5
5
|
//#region src/composables/use-data-request.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 数据对象类型
|
|
8
|
+
*/
|
|
6
9
|
type DataObject = Record<string, any>;
|
|
10
|
+
/**
|
|
11
|
+
* 数据请求字段配置
|
|
12
|
+
* 用于自定义请求参数和响应数据的字段名
|
|
13
|
+
*/
|
|
7
14
|
type DataRequestFields = Record<string, string | undefined> & {
|
|
8
|
-
page?: string;
|
|
9
|
-
pageSize?: string;
|
|
10
|
-
list?: string;
|
|
11
|
-
count?: string;
|
|
15
|
+
/** 页码字段名 */page?: string; /** 每页大小字段名 */
|
|
16
|
+
pageSize?: string; /** 列表数据字段名 */
|
|
17
|
+
list?: string; /** 总数字段名 */
|
|
18
|
+
count?: string; /** 行键字段名 */
|
|
12
19
|
rowKey?: string;
|
|
13
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* 数据请求配置选项
|
|
23
|
+
* @template P 请求参数类型
|
|
24
|
+
* @template D 响应数据类型
|
|
25
|
+
*/
|
|
14
26
|
type UseDataRequestOptions<P extends DataObject = DataObject, D extends DataObject = DataObject> = {
|
|
15
|
-
defaultParams?: Partial<P>;
|
|
16
|
-
manual?: boolean;
|
|
17
|
-
fields?: DataRequestFields;
|
|
18
|
-
requestOptions?: UseRequestOptions<D, P[]>;
|
|
27
|
+
/** 默认请求参数 */defaultParams?: Partial<P>; /** 是否手动触发请求 */
|
|
28
|
+
manual?: boolean; /** 字段配置 */
|
|
29
|
+
fields?: DataRequestFields; /** useRequest 配置选项 */
|
|
30
|
+
requestOptions?: UseRequestOptions<D, P[]>; /** useRequest 插件 */
|
|
19
31
|
requestPlugins?: UseRequestPlugin<D, P[]>[];
|
|
20
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* 数据请求分页信息
|
|
35
|
+
*/
|
|
21
36
|
type UseDataRequestPagination = {
|
|
22
|
-
page: number;
|
|
23
|
-
pageSize: number;
|
|
37
|
+
/** 当前页码 */page: number; /** 每页大小 */
|
|
38
|
+
pageSize: number; /** 总数据量 */
|
|
24
39
|
itemCount: number;
|
|
25
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* 用于处理数据请求的组合式 API
|
|
43
|
+
* @template P 请求参数类型
|
|
44
|
+
* @template D 响应数据类型
|
|
45
|
+
* @template R 列表项类型
|
|
46
|
+
* @param api 请求 API 函数
|
|
47
|
+
* @param options 配置选项
|
|
48
|
+
* @returns 数据请求操作对象
|
|
49
|
+
*/
|
|
26
50
|
declare function useDataRequest<P extends DataObject = DataObject, D extends DataObject = DataObject, R extends DataObject = DataObject>(api: (...args: P[]) => Promise<D>, options?: UseDataRequestOptions<P, D>): {
|
|
27
|
-
loading: Readonly<
|
|
28
|
-
data: Readonly<
|
|
29
|
-
error: Readonly<
|
|
30
|
-
params: Readonly<
|
|
31
|
-
list:
|
|
32
|
-
pagination:
|
|
51
|
+
/** 加载状态 */loading: Readonly<vue4.Ref<boolean, boolean>>; /** 响应数据 */
|
|
52
|
+
data: Readonly<vue4.Ref<D | undefined, D | undefined>>; /** 错误信息 */
|
|
53
|
+
error: Readonly<vue4.Ref<Error | undefined, Error | undefined>>; /** 请求参数 */
|
|
54
|
+
params: Readonly<vue4.Ref<[] | P[], [] | P[]>>; /** 列表数据 */
|
|
55
|
+
list: vue4.ComputedRef<R[]>; /** 分页信息 */
|
|
56
|
+
pagination: vue4.Ref<{
|
|
33
57
|
page: number;
|
|
34
58
|
pageSize: number;
|
|
35
59
|
itemCount: number;
|
|
@@ -37,21 +61,27 @@ declare function useDataRequest<P extends DataObject = DataObject, D extends Dat
|
|
|
37
61
|
page: number;
|
|
38
62
|
pageSize: number;
|
|
39
63
|
itemCount: number;
|
|
40
|
-
}>;
|
|
41
|
-
run: (...params: P[]) => void;
|
|
42
|
-
runAsync: (...params: P[]) => Promise<D>;
|
|
43
|
-
refresh: () => void;
|
|
44
|
-
refreshAsync: () => Promise<D>;
|
|
45
|
-
cancel: () => void;
|
|
46
|
-
mutate: (data?: D | ((oldData?: D | undefined) => D | undefined) | undefined) => void;
|
|
47
|
-
setParams: (_params: Partial<P>) => void;
|
|
48
|
-
runParams: (_params: Partial<P>) => void;
|
|
49
|
-
runParamsAsync: (_params: Partial<P>) => Promise<D>;
|
|
50
|
-
onBefore: _vueuse_core0.EventHookOn<[P[]]>;
|
|
51
|
-
onSuccess: _vueuse_core0.EventHookOn<[D, P[]]>;
|
|
52
|
-
onError: _vueuse_core0.EventHookOn<[Error, P[]]>;
|
|
64
|
+
}>; /** 运行请求 */
|
|
65
|
+
run: (...params: P[]) => void; /** 异步运行请求 */
|
|
66
|
+
runAsync: (...params: P[]) => Promise<D>; /** 刷新请求 */
|
|
67
|
+
refresh: () => void; /** 异步刷新请求 */
|
|
68
|
+
refreshAsync: () => Promise<D>; /** 取消请求 */
|
|
69
|
+
cancel: () => void; /** 修改响应数据 */
|
|
70
|
+
mutate: (data?: D | ((oldData?: D | undefined) => D | undefined) | undefined) => void; /** 设置请求参数 */
|
|
71
|
+
setParams: (_params: Partial<P>) => void; /** 设置参数并运行请求 */
|
|
72
|
+
runParams: (_params: Partial<P>) => void; /** 设置参数并异步运行请求 */
|
|
73
|
+
runParamsAsync: (_params: Partial<P>) => Promise<D>; /** 请求前事件 */
|
|
74
|
+
onBefore: _vueuse_core0.EventHookOn<[P[]]>; /** 请求成功事件 */
|
|
75
|
+
onSuccess: _vueuse_core0.EventHookOn<[D, P[]]>; /** 请求错误事件 */
|
|
76
|
+
onError: _vueuse_core0.EventHookOn<[Error, P[]]>; /** 请求完成事件 */
|
|
53
77
|
onFinally: _vueuse_core0.EventHookOn<[P[], D | undefined, Error | undefined]>;
|
|
54
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* useDataRequest 返回类型
|
|
81
|
+
* @template P 请求参数类型
|
|
82
|
+
* @template D 响应数据类型
|
|
83
|
+
* @template R 列表项类型
|
|
84
|
+
*/
|
|
55
85
|
type UseDataRequestReturns<P extends DataObject = DataObject, D extends DataObject = DataObject, R extends DataObject = DataObject> = ReturnType<typeof useDataRequest<P, D, R>>;
|
|
56
86
|
//#endregion
|
|
57
87
|
export { DataObject, DataRequestFields, UseDataRequestOptions, UseDataRequestPagination, UseDataRequestReturns, useDataRequest };
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { createEventHook } from "@vueuse/core";
|
|
2
1
|
import { computed, ref } from "vue";
|
|
2
|
+
import { createEventHook } from "@vueuse/core";
|
|
3
3
|
import useRequest from "vue-hooks-plus/es/useRequest";
|
|
4
4
|
|
|
5
5
|
//#region src/composables/use-data-request.ts
|
|
6
|
+
/**
|
|
7
|
+
* 用于处理数据请求的组合式 API
|
|
8
|
+
* @template P 请求参数类型
|
|
9
|
+
* @template D 响应数据类型
|
|
10
|
+
* @template R 列表项类型
|
|
11
|
+
* @param api 请求 API 函数
|
|
12
|
+
* @param options 配置选项
|
|
13
|
+
* @returns 数据请求操作对象
|
|
14
|
+
*/
|
|
6
15
|
function useDataRequest(api, options) {
|
|
7
16
|
const { defaultParams, manual, fields, requestOptions, requestPlugins } = options ?? {};
|
|
8
17
|
const _fields = {
|
|
@@ -59,15 +68,29 @@ function useDataRequest(api, options) {
|
|
|
59
68
|
}
|
|
60
69
|
}, requestPlugins);
|
|
61
70
|
const list = computed(() => data.value?.[_fields.list] ?? []);
|
|
71
|
+
/**
|
|
72
|
+
* 设置请求参数
|
|
73
|
+
* @param _params 要设置的参数
|
|
74
|
+
*/
|
|
62
75
|
function setParams(_params) {
|
|
63
76
|
Object.assign(params.value?.[0], _params);
|
|
64
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* 设置参数并运行请求
|
|
80
|
+
* @param _params 要设置的参数
|
|
81
|
+
* @returns 请求结果
|
|
82
|
+
*/
|
|
65
83
|
function runParams(_params) {
|
|
66
84
|
return run({
|
|
67
85
|
...params.value?.[0],
|
|
68
86
|
..._params
|
|
69
87
|
});
|
|
70
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* 设置参数并异步运行请求
|
|
91
|
+
* @param _params 要设置的参数
|
|
92
|
+
* @returns 请求结果 Promise
|
|
93
|
+
*/
|
|
71
94
|
function runParamsAsync(_params) {
|
|
72
95
|
return runAsync({
|
|
73
96
|
...params.value?.[0],
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { LoadingProviderInst } from "../components/loading-provider/index.js";
|
|
2
2
|
|
|
3
3
|
//#region src/composables/use-loading.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 用于获取 Naive UI 加载状态提供者的组合式 API
|
|
6
|
+
* @returns 加载状态提供者实例
|
|
7
|
+
*/
|
|
4
8
|
declare function useLoading(): LoadingProviderInst | undefined;
|
|
5
9
|
//#endregion
|
|
6
10
|
export { useLoading };
|