@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
|
@@ -3,9 +3,12 @@ import { _default } from "./TooltipButton.vue.js";
|
|
|
3
3
|
import { ButtonProps, TooltipProps } from "naive-ui";
|
|
4
4
|
|
|
5
5
|
//#region src/components/tooltip-button/index.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 提示按钮属性
|
|
8
|
+
*/
|
|
6
9
|
type TooltipButtonProps = {
|
|
7
|
-
tooltip?: string;
|
|
8
|
-
tooltipProps?: TooltipProps & ClassStyle;
|
|
10
|
+
/** 提示文本 */tooltip?: string; /** 提示框属性 */
|
|
11
|
+
tooltipProps?: TooltipProps & ClassStyle; /** 按钮属性 */
|
|
9
12
|
buttonProps?: ButtonProps & ClassStyle;
|
|
10
13
|
};
|
|
11
14
|
//#endregion
|
|
@@ -3,8 +3,11 @@ import { _default } from "./BaseTransition.vue.js";
|
|
|
3
3
|
import { TransitionProps } from "vue";
|
|
4
4
|
|
|
5
5
|
//#region src/components/transition/index.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 过渡动画属性
|
|
8
|
+
*/
|
|
6
9
|
type TransitionProps$1 = {
|
|
7
|
-
name?: string;
|
|
10
|
+
/** 过渡名称 */name?: string; /** 过渡属性 */
|
|
8
11
|
transitionProps?: TransitionProps & ClassStyle;
|
|
9
12
|
};
|
|
10
13
|
//#endregion
|
package/dist/components.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { SearchInputProps } from "./components/search-input/index.js";
|
|
|
5
5
|
import { _default as _default$2 } from "./components/data-table-plus/DataTablePlus.vue.js";
|
|
6
6
|
import { ClassStyle, DataTablePlusEmits, DataTablePlusExpose, DataTablePlusFields, DataTablePlusInst, DataTablePlusProps } from "./components/data-table-plus/index.js";
|
|
7
7
|
import { _default as _default$3 } from "./components/loading-provider/LoadingProvider.vue.js";
|
|
8
|
-
import { LoadingProviderInst, LoadingProviderProps
|
|
8
|
+
import { LOADING_PROVIDER_INJECTION_KEY, LoadingProviderInst, LoadingProviderProps } from "./components/loading-provider/index.js";
|
|
9
9
|
import { UseNaiveFormRules } from "./composables/use-naive-form.js";
|
|
10
10
|
import { _default } from "./components/config-providers/ConfigProviders.vue.js";
|
|
11
11
|
import { ConfigProvidersProps } from "./components/config-providers/index.js";
|
|
@@ -24,8 +24,6 @@ import { _default as _default$11 } from "./components/tooltip-button/TooltipButt
|
|
|
24
24
|
import { TooltipButtonProps } from "./components/tooltip-button/index.js";
|
|
25
25
|
import { _default as _default$12 } from "./components/transition/BaseTransition.vue.js";
|
|
26
26
|
import { TransitionProps } from "./components/transition/index.js";
|
|
27
|
-
import { _default as _default$13 } from "./components/type-writer/TypeWriter.vue.js";
|
|
28
|
-
import { TypeWriterProps } from "./components/type-writer/index.js";
|
|
29
27
|
import "./components/index.js";
|
|
30
28
|
import { ComponentAttrs, ComponentEmit, ComponentExposed, ComponentProps, ComponentSlots } from "vue-component-type-helpers";
|
|
31
|
-
export { ArrayAwareType, ClassStyle, ComponentAttrs, ComponentEmit, ComponentExposed, ComponentProps, ComponentSlots, ConfigProvidersProps, CopyButtonProps, DataTablePlusEmits, DataTablePlusExpose, DataTablePlusFields, DataTablePlusInst, DataTablePlusProps, LoadingProviderInst, LoadingProviderProps, _default as NConfigProviders, _default$1 as NCopyButton, _default$2 as NDataTablePlus, _default$3 as NLoadingProvider, _default$4 as NPresetForm, _default$5 as NPresetInput, _default$6 as NPresetPicker, _default$7 as NPresetSelect, _default$8 as NRemoteRequest, _default$9 as NSearchInput, _default$10 as NToggleInput, _default$11 as NTooltipButton, _default$12 as NTransition,
|
|
29
|
+
export { ArrayAwareType, ClassStyle, ComponentAttrs, ComponentEmit, ComponentExposed, ComponentProps, ComponentSlots, ConfigProvidersProps, CopyButtonProps, DataTablePlusEmits, DataTablePlusExpose, DataTablePlusFields, DataTablePlusInst, DataTablePlusProps, LOADING_PROVIDER_INJECTION_KEY, LoadingProviderInst, LoadingProviderProps, _default as NConfigProviders, _default$1 as NCopyButton, _default$2 as NDataTablePlus, _default$3 as NLoadingProvider, _default$4 as NPresetForm, _default$5 as NPresetInput, _default$6 as NPresetPicker, _default$7 as NPresetSelect, _default$8 as NRemoteRequest, _default$9 as NSearchInput, _default$10 as NToggleInput, _default$11 as NTooltipButton, _default$12 as NTransition, OptionFormat, PresetFormExpose, PresetFormInst, PresetFormOptionItem, PresetFormOptions, PresetFormProps, PresetInputOptions, PresetInputProps, PresetInputType, PresetPickerEmits, PresetPickerExpose, PresetPickerInst, PresetPickerProps, PresetPickerValue, PresetSelectEmits, PresetSelectExpose, PresetSelectFields, PresetSelectInst, PresetSelectProps, PresetSelectValue, RemoteRequestEmits, RemoteRequestExpose, RemoteRequestFields, RemoteRequestInst, RemoteRequestProps, SearchInputProps, TooltipButtonProps, TransitionProps, UseNaiveFormRules };
|
package/dist/components.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BaseTransition_default from "./components/transition/BaseTransition.js";
|
|
2
2
|
import LoadingProvider_default from "./components/loading-provider/LoadingProvider.js";
|
|
3
|
-
import {
|
|
3
|
+
import { LOADING_PROVIDER_INJECTION_KEY } from "./components/loading-provider/index.js";
|
|
4
4
|
import ConfigProviders_default from "./components/config-providers/ConfigProviders.js";
|
|
5
5
|
import CopyButton_default from "./components/copy-button/CopyButton.js";
|
|
6
6
|
import SearchInput_default from "./components/search-input/SearchInput.js";
|
|
@@ -12,7 +12,6 @@ import PresetSelect_default from "./components/preset-select/PresetSelect.js";
|
|
|
12
12
|
import RemoteRequest_default from "./components/remote-request/RemoteRequest.js";
|
|
13
13
|
import ToggleInput_default from "./components/toggle-input/ToggleInput.js";
|
|
14
14
|
import TooltipButton_default from "./components/tooltip-button/TooltipButton.js";
|
|
15
|
-
import TypeWriter_default from "./components/type-writer/TypeWriter.js";
|
|
16
15
|
import { ComponentAttrs, ComponentEmit, ComponentExposed, ComponentProps, ComponentSlots } from "vue-component-type-helpers";
|
|
17
16
|
|
|
18
|
-
export { ComponentAttrs, ComponentEmit, ComponentExposed, ComponentProps, ComponentSlots, ConfigProviders_default as NConfigProviders, CopyButton_default as NCopyButton, DataTablePlus_default as NDataTablePlus, LoadingProvider_default as NLoadingProvider, PresetForm_default as NPresetForm, PresetInput_default as NPresetInput, PresetPicker_default as NPresetPicker, PresetSelect_default as NPresetSelect, RemoteRequest_default as NRemoteRequest, SearchInput_default as NSearchInput, ToggleInput_default as NToggleInput, TooltipButton_default as NTooltipButton, BaseTransition_default as NTransition
|
|
17
|
+
export { ComponentAttrs, ComponentEmit, ComponentExposed, ComponentProps, ComponentSlots, LOADING_PROVIDER_INJECTION_KEY, ConfigProviders_default as NConfigProviders, CopyButton_default as NCopyButton, DataTablePlus_default as NDataTablePlus, LoadingProvider_default as NLoadingProvider, PresetForm_default as NPresetForm, PresetInput_default as NPresetInput, PresetPicker_default as NPresetPicker, PresetSelect_default as NPresetSelect, RemoteRequest_default as NRemoteRequest, SearchInput_default as NSearchInput, ToggleInput_default as NToggleInput, TooltipButton_default as NTooltipButton, BaseTransition_default as NTransition };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
//#region src/composables/_helper.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* 颜色配置类型,用于定义主题的基础颜色
|
|
4
|
+
*/
|
|
2
5
|
type Colors = {
|
|
3
|
-
primary?: string;
|
|
4
|
-
info?: string;
|
|
5
|
-
success?: string;
|
|
6
|
-
warning?: string;
|
|
6
|
+
/** 主色 */primary?: string; /** 信息色 */
|
|
7
|
+
info?: string; /** 成功色 */
|
|
8
|
+
success?: string; /** 警告色 */
|
|
9
|
+
warning?: string; /** 错误色 */
|
|
7
10
|
error?: string;
|
|
8
11
|
};
|
|
9
12
|
//#endregion
|
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
import { colord } from "colord";
|
|
2
2
|
|
|
3
3
|
//#region src/composables/_helper.ts
|
|
4
|
+
/**
|
|
5
|
+
* 获取变亮的颜色
|
|
6
|
+
* @param color - 原始颜色值
|
|
7
|
+
* @returns 变亮后的颜色值,如果输入无效则返回 undefined
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const darkColor = getDarkColor('#1890ff')
|
|
11
|
+
* // 返回变亮后的颜色值
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
4
14
|
function getDarkColor(color) {
|
|
5
15
|
if (!color) return void 0;
|
|
6
16
|
const colorInst = colord(color);
|
|
7
17
|
if (!colorInst.isValid()) return void 0;
|
|
8
18
|
return colorInst.lighten(.1).toHex();
|
|
9
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* 获取一组变亮的颜色
|
|
22
|
+
* @param colors - 颜色配置对象
|
|
23
|
+
* @returns 包含变亮后颜色的对象
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const darkColors = getDarkColors({
|
|
27
|
+
* primary: '#1890ff',
|
|
28
|
+
* success: '#52c41a'
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
10
32
|
function getDarkColors(colors) {
|
|
11
33
|
return {
|
|
12
34
|
primary: getDarkColor(colors.primary),
|
|
@@ -16,6 +38,16 @@ function getDarkColors(colors) {
|
|
|
16
38
|
error: getDarkColor(colors.error)
|
|
17
39
|
};
|
|
18
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* 获取状态颜色对象,包含基础颜色和交互状态颜色
|
|
43
|
+
* @param color - 原始颜色值
|
|
44
|
+
* @returns 状态颜色对象,如果输入无效则返回 undefined
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const statusColor = getStatusColor('#1890ff')
|
|
48
|
+
* // 返回 { color: '#1890ff', hover: '...', pressed: '...', suppl: '...' }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
19
51
|
function getStatusColor(color) {
|
|
20
52
|
if (!color) return void 0;
|
|
21
53
|
const colorInst = colord(color);
|
|
@@ -27,6 +59,21 @@ function getStatusColor(color) {
|
|
|
27
59
|
suppl: colorInst.lighten(.1).toHex()
|
|
28
60
|
};
|
|
29
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* 获取一组状态颜色
|
|
64
|
+
* @param colors - 颜色配置对象
|
|
65
|
+
* @returns 包含各状态颜色的对象
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const colors = getColors({
|
|
69
|
+
* primary: '#1890ff',
|
|
70
|
+
* info: '#1890ff',
|
|
71
|
+
* success: '#52c41a',
|
|
72
|
+
* warning: '#faad14',
|
|
73
|
+
* error: '#f5222d'
|
|
74
|
+
* })
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
30
77
|
function getColors(colors) {
|
|
31
78
|
const { primary, info, success, warning, error } = colors ?? {};
|
|
32
79
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UseAutoMenuReturn, useAutoMenu } from "./use-auto-menu.js";
|
|
2
1
|
import { DataObject, DataRequestFields, UseDataRequestOptions, UseDataRequestPagination, UseDataRequestReturns, useDataRequest } from "./use-data-request.js";
|
|
3
2
|
import { useLoading } from "./use-loading.js";
|
|
4
3
|
import { UseNaiveFormClearRules, UseNaiveFormOptions, UseNaiveFormReturns, UseNaiveFormRules, useNaiveForm } from "./use-naive-form.js";
|
|
4
|
+
import { UseNaiveMenuOptions, UseNaiveMenuReturn, useNaiveMenu } from "./use-naive-menu.js";
|
|
5
5
|
import { UseNaiveThemeOptions, UseNaiveThemeReturns, useNaiveTheme } from "./use-naive-theme.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as vue4 from "vue";
|
|
2
1
|
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
|
|
@@ -46,14 +46,21 @@ type UseDataRequestPagination = {
|
|
|
46
46
|
* @param api 请求 API 函数
|
|
47
47
|
* @param options 配置选项
|
|
48
48
|
* @returns 数据请求操作对象
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const { loading, data, list, pagination, run, refresh } = useDataRequest(api, {
|
|
52
|
+
* defaultParams: { page: 1, pageSize: 10 },
|
|
53
|
+
* fields: { page: 'page', pageSize: 'size', list: 'data', count: 'total' }
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
49
56
|
*/
|
|
50
57
|
declare function useDataRequest<P extends DataObject = DataObject, D extends DataObject = DataObject, R extends DataObject = DataObject>(api: (...args: P[]) => Promise<D>, options?: UseDataRequestOptions<P, D>): {
|
|
51
|
-
|
|
52
|
-
data: Readonly<
|
|
53
|
-
error: Readonly<
|
|
54
|
-
params: Readonly<
|
|
55
|
-
list:
|
|
56
|
-
pagination:
|
|
58
|
+
loading: Readonly<vue0.Ref<boolean, boolean>>;
|
|
59
|
+
data: Readonly<vue0.Ref<D | undefined, D | undefined>>;
|
|
60
|
+
error: Readonly<vue0.Ref<Error | undefined, Error | undefined>>;
|
|
61
|
+
params: Readonly<vue0.Ref<P[] | [], P[] | []>>;
|
|
62
|
+
list: vue0.ComputedRef<R[]>;
|
|
63
|
+
pagination: vue0.Ref<{
|
|
57
64
|
page: number;
|
|
58
65
|
pageSize: number;
|
|
59
66
|
itemCount: number;
|
|
@@ -61,19 +68,19 @@ declare function useDataRequest<P extends DataObject = DataObject, D extends Dat
|
|
|
61
68
|
page: number;
|
|
62
69
|
pageSize: number;
|
|
63
70
|
itemCount: number;
|
|
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[]]>;
|
|
71
|
+
}>;
|
|
72
|
+
run: (...params: P[]) => void;
|
|
73
|
+
runAsync: (...params: P[]) => Promise<D>;
|
|
74
|
+
refresh: () => void;
|
|
75
|
+
refreshAsync: () => Promise<D>;
|
|
76
|
+
cancel: () => void;
|
|
77
|
+
mutate: (data?: D | ((oldData?: D | undefined) => D | undefined) | undefined) => void;
|
|
78
|
+
setParams: (_params: Partial<P>) => void;
|
|
79
|
+
runParams: (_params: Partial<P>) => void;
|
|
80
|
+
runParamsAsync: (_params: Partial<P>) => Promise<D>;
|
|
81
|
+
onBefore: _vueuse_core0.EventHookOn<[P[]]>;
|
|
82
|
+
onSuccess: _vueuse_core0.EventHookOn<[D, P[]]>;
|
|
83
|
+
onError: _vueuse_core0.EventHookOn<[Error, P[]]>;
|
|
77
84
|
onFinally: _vueuse_core0.EventHookOn<[P[], D | undefined, Error | undefined]>;
|
|
78
85
|
};
|
|
79
86
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { computed, ref } from "vue";
|
|
2
1
|
import { createEventHook } from "@vueuse/core";
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
3
|
import useRequest from "vue-hooks-plus/es/useRequest";
|
|
4
4
|
|
|
5
5
|
//#region src/composables/use-data-request.ts
|
|
@@ -11,6 +11,13 @@ import useRequest from "vue-hooks-plus/es/useRequest";
|
|
|
11
11
|
* @param api 请求 API 函数
|
|
12
12
|
* @param options 配置选项
|
|
13
13
|
* @returns 数据请求操作对象
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const { loading, data, list, pagination, run, refresh } = useDataRequest(api, {
|
|
17
|
+
* defaultParams: { page: 1, pageSize: 10 },
|
|
18
|
+
* fields: { page: 'page', pageSize: 'size', list: 'data', count: 'total' }
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
14
21
|
*/
|
|
15
22
|
function useDataRequest(api, options) {
|
|
16
23
|
const { defaultParams, manual, fields, requestOptions, requestPlugins } = options ?? {};
|
|
@@ -70,15 +77,23 @@ function useDataRequest(api, options) {
|
|
|
70
77
|
const list = computed(() => data.value?.[_fields.list] ?? []);
|
|
71
78
|
/**
|
|
72
79
|
* 设置请求参数
|
|
73
|
-
* @param _params 要设置的参数
|
|
80
|
+
* @param _params - 要设置的参数
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* setParams({ page: 2 })
|
|
84
|
+
* ```
|
|
74
85
|
*/
|
|
75
86
|
function setParams(_params) {
|
|
76
87
|
Object.assign(params.value?.[0], _params);
|
|
77
88
|
}
|
|
78
89
|
/**
|
|
79
90
|
* 设置参数并运行请求
|
|
80
|
-
* @param _params 要设置的参数
|
|
91
|
+
* @param _params - 要设置的参数
|
|
81
92
|
* @returns 请求结果
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* runParams({ page: 2 })
|
|
96
|
+
* ```
|
|
82
97
|
*/
|
|
83
98
|
function runParams(_params) {
|
|
84
99
|
return run({
|
|
@@ -88,8 +103,12 @@ function useDataRequest(api, options) {
|
|
|
88
103
|
}
|
|
89
104
|
/**
|
|
90
105
|
* 设置参数并异步运行请求
|
|
91
|
-
* @param _params 要设置的参数
|
|
106
|
+
* @param _params - 要设置的参数
|
|
92
107
|
* @returns 请求结果 Promise
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* await runParamsAsync({ page: 2 })
|
|
111
|
+
* ```
|
|
93
112
|
*/
|
|
94
113
|
function runParamsAsync(_params) {
|
|
95
114
|
return runAsync({
|
|
@@ -4,6 +4,12 @@ import { LoadingProviderInst } from "../components/loading-provider/index.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* 用于获取 Naive UI 加载状态提供者的组合式 API
|
|
6
6
|
* @returns 加载状态提供者实例
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const loading = useLoading()
|
|
10
|
+
* loading?.start()
|
|
11
|
+
* loading?.finish()
|
|
12
|
+
* ```
|
|
7
13
|
*/
|
|
8
14
|
declare function useLoading(): LoadingProviderInst | undefined;
|
|
9
15
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LOADING_PROVIDER_INJECTION_KEY } from "../components/loading-provider/index.js";
|
|
2
2
|
import { inject } from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/composables/use-loading.ts
|
|
@@ -9,9 +9,15 @@ import { inject } from "vue";
|
|
|
9
9
|
/**
|
|
10
10
|
* 用于获取 Naive UI 加载状态提供者的组合式 API
|
|
11
11
|
* @returns 加载状态提供者实例
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const loading = useLoading()
|
|
15
|
+
* loading?.start()
|
|
16
|
+
* loading?.finish()
|
|
17
|
+
* ```
|
|
12
18
|
*/
|
|
13
19
|
function useLoading() {
|
|
14
|
-
return inject(
|
|
20
|
+
return inject(LOADING_PROVIDER_INJECTION_KEY);
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
//#endregion
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DataObject } from "./use-data-request.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _vueuse_core3 from "@vueuse/core";
|
|
3
|
+
import * as vue5 from "vue";
|
|
3
4
|
import { MaybeRefOrGetter, Ref, TemplateRef } from "vue";
|
|
4
|
-
import * as _vueuse_core0 from "@vueuse/core";
|
|
5
5
|
import { FormInst, FormItemRule, FormRules } from "naive-ui";
|
|
6
6
|
import { ValidateError } from "async-validator";
|
|
7
7
|
|
|
@@ -35,24 +35,32 @@ type UseNaiveFormOptions<T extends DataObject> = {
|
|
|
35
35
|
* @param formInstRef 表单实例引用
|
|
36
36
|
* @param options 配置选项
|
|
37
37
|
* @returns 表单操作对象
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const formRef = ref<FormInst>()
|
|
41
|
+
* const { formValue, formRules, formProps, validate, reset, clear } = useNaiveForm(formRef, {
|
|
42
|
+
* value: { name: '', age: 0 },
|
|
43
|
+
* rules: { name: { required: true, message: '请输入姓名' } }
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
38
46
|
*/
|
|
39
47
|
declare function useNaiveForm<T extends DataObject = DataObject>(formInstRef: TemplateRef<FormInst>, options?: UseNaiveFormOptions<T>): {
|
|
40
|
-
|
|
41
|
-
formValue: Ref<T, T>;
|
|
42
|
-
formRules: Ref<Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>>, Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>>>;
|
|
48
|
+
formInst: Readonly<vue5.ShallowRef<FormInst | null>>;
|
|
49
|
+
formValue: Ref<T, T>;
|
|
50
|
+
formRules: Ref<Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>>, Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>>>;
|
|
43
51
|
formProps: {
|
|
44
|
-
model:
|
|
45
|
-
rules:
|
|
46
|
-
};
|
|
47
|
-
setValue: (
|
|
52
|
+
model: vue5.Reactive<T>;
|
|
53
|
+
rules: vue5.Reactive<Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>>>;
|
|
54
|
+
};
|
|
55
|
+
setValue: (value: Partial<T>) => void;
|
|
48
56
|
validate: () => Promise<{
|
|
49
57
|
warnings?: ValidateError[][];
|
|
50
|
-
}>;
|
|
51
|
-
resetValidation: () => void;
|
|
52
|
-
resetForm: () => void;
|
|
53
|
-
reset: () => void;
|
|
54
|
-
clear: () => void;
|
|
55
|
-
onValidated:
|
|
58
|
+
}>;
|
|
59
|
+
resetValidation: () => void;
|
|
60
|
+
resetForm: () => void;
|
|
61
|
+
reset: () => void;
|
|
62
|
+
clear: () => void;
|
|
63
|
+
onValidated: _vueuse_core3.EventHookOn<[T]>;
|
|
56
64
|
};
|
|
57
65
|
/**
|
|
58
66
|
* useNaiveForm 返回类型
|
|
@@ -1,29 +1,16 @@
|
|
|
1
|
-
import { reactive, ref, toRaw, toValue, watchEffect } from "vue";
|
|
2
1
|
import { createEventHook } from "@vueuse/core";
|
|
2
|
+
import { reactive, ref, toRaw, toValue, watchEffect } from "vue";
|
|
3
3
|
import { cloneDeep } from "es-toolkit/object";
|
|
4
|
+
import { isPlainObject } from "es-toolkit/predicate";
|
|
4
5
|
|
|
5
6
|
//#region src/composables/use-naive-form.ts
|
|
6
|
-
/**
|
|
7
|
-
* 检查值是否为对象类型
|
|
8
|
-
* @param value 要检查的值
|
|
9
|
-
* @returns 是否为对象类型
|
|
10
|
-
*/
|
|
11
|
-
function isObject(value) {
|
|
12
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 清空对象值
|
|
16
|
-
* @param obj 要清空的对象
|
|
17
|
-
* @param rules 清空规则
|
|
18
|
-
* @returns 清空后的对象
|
|
19
|
-
*/
|
|
20
7
|
function clearObjectValues(obj, rules) {
|
|
21
8
|
const { string: _string = "", number: _number = null, boolean: _boolean = false } = rules ?? {};
|
|
22
9
|
if (Array.isArray(obj)) {
|
|
23
10
|
obj.length = 0;
|
|
24
11
|
return obj;
|
|
25
12
|
}
|
|
26
|
-
if (
|
|
13
|
+
if (isPlainObject(obj)) {
|
|
27
14
|
for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key)) obj[key] = clearObjectValues(obj[key], rules);
|
|
28
15
|
return obj;
|
|
29
16
|
}
|
|
@@ -33,26 +20,19 @@ function clearObjectValues(obj, rules) {
|
|
|
33
20
|
return obj;
|
|
34
21
|
}
|
|
35
22
|
/**
|
|
36
|
-
* 深度合并对象
|
|
37
|
-
* @param target 目标对象
|
|
38
|
-
* @param source 源对象
|
|
39
|
-
* @returns 合并后的对象
|
|
40
|
-
*/
|
|
41
|
-
function deepMerge(target = {}, source = {}) {
|
|
42
|
-
for (const key in source) if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
43
|
-
const sourceValue = source[key];
|
|
44
|
-
const targetValue = target[key];
|
|
45
|
-
if (isObject(sourceValue) && isObject(targetValue)) deepMerge(targetValue, sourceValue);
|
|
46
|
-
else target[key] = sourceValue;
|
|
47
|
-
}
|
|
48
|
-
return target;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
23
|
* 用于处理 Naive UI 表单的组合式 API
|
|
52
24
|
* @template T 表单值类型
|
|
53
25
|
* @param formInstRef 表单实例引用
|
|
54
26
|
* @param options 配置选项
|
|
55
27
|
* @returns 表单操作对象
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const formRef = ref<FormInst>()
|
|
31
|
+
* const { formValue, formRules, formProps, validate, reset, clear } = useNaiveForm(formRef, {
|
|
32
|
+
* value: { name: '', age: 0 },
|
|
33
|
+
* rules: { name: { required: true, message: '请输入姓名' } }
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
56
36
|
*/
|
|
57
37
|
function useNaiveForm(formInstRef, options) {
|
|
58
38
|
const { value, rules, clearRules } = options ?? {};
|
|
@@ -62,7 +42,9 @@ function useNaiveForm(formInstRef, options) {
|
|
|
62
42
|
formValueRef.value = toValue(value) ?? {};
|
|
63
43
|
});
|
|
64
44
|
const formRulesRef = ref(toValue(rules));
|
|
65
|
-
watchEffect(() =>
|
|
45
|
+
watchEffect(() => {
|
|
46
|
+
formRulesRef.value = toValue(rules) ?? {};
|
|
47
|
+
});
|
|
66
48
|
const formProps = {
|
|
67
49
|
model: reactive(formValueRef.value),
|
|
68
50
|
rules: reactive(formRulesRef.value)
|
|
@@ -70,19 +52,31 @@ function useNaiveForm(formInstRef, options) {
|
|
|
70
52
|
const onValidatedEvent = createEventHook();
|
|
71
53
|
/**
|
|
72
54
|
* 设置表单值
|
|
73
|
-
* @param
|
|
55
|
+
* @param value - 要设置的值
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* setValue({ name: '张三' })
|
|
59
|
+
* ```
|
|
74
60
|
*/
|
|
75
|
-
function setValue(
|
|
76
|
-
Object.assign(formValueRef.value,
|
|
61
|
+
function setValue(value) {
|
|
62
|
+
Object.assign(formValueRef.value, value);
|
|
77
63
|
}
|
|
78
64
|
/**
|
|
79
65
|
* 验证表单
|
|
80
|
-
* @returns 验证结果Promise
|
|
66
|
+
* @returns 验证结果 Promise
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* try {
|
|
70
|
+
* await validate()
|
|
71
|
+
* } catch (errors) {
|
|
72
|
+
* console.log(errors)
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
81
75
|
*/
|
|
82
76
|
function validate() {
|
|
77
|
+
if (!formInstRef.value) throw new Error("useNaiveForm: formInstRef is not found.");
|
|
83
78
|
return new Promise((resolve, reject) => {
|
|
84
|
-
|
|
85
|
-
formInstRef.value.validate().then((res) => {
|
|
79
|
+
formInstRef.value?.validate().then((res) => {
|
|
86
80
|
onValidatedEvent.trigger(toRaw(toValue(formValueRef)));
|
|
87
81
|
return resolve(res);
|
|
88
82
|
}).catch(reject);
|
|
@@ -90,26 +84,41 @@ function useNaiveForm(formInstRef, options) {
|
|
|
90
84
|
}
|
|
91
85
|
/**
|
|
92
86
|
* 重置表单验证状态
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* resetValidation()
|
|
90
|
+
* ```
|
|
93
91
|
*/
|
|
94
92
|
function resetValidation() {
|
|
95
93
|
formInstRef.value?.restoreValidation();
|
|
96
94
|
}
|
|
97
95
|
/**
|
|
98
96
|
* 清空表单值
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* clear()
|
|
100
|
+
* ```
|
|
99
101
|
*/
|
|
100
102
|
function clear() {
|
|
101
103
|
clearObjectValues(formValueRef.value, clearRules);
|
|
102
104
|
}
|
|
103
105
|
/**
|
|
104
106
|
* 重置表单值到初始状态
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* resetForm()
|
|
110
|
+
* ```
|
|
105
111
|
*/
|
|
106
112
|
function resetForm() {
|
|
107
113
|
clear();
|
|
108
|
-
|
|
109
|
-
deepMerge(formValueRef.value, _cacheValue);
|
|
114
|
+
Object.assign(formValueRef.value, cloneDeep(cacheValue));
|
|
110
115
|
}
|
|
111
116
|
/**
|
|
112
117
|
* 重置表单验证状态和值
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* reset()
|
|
121
|
+
* ```
|
|
113
122
|
*/
|
|
114
123
|
function reset() {
|
|
115
124
|
resetValidation();
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as vue8 from "vue";
|
|
2
|
+
import { MaybeRefOrGetter, VNodeChild } from "vue";
|
|
3
|
+
import { MenuOption } from "naive-ui";
|
|
4
|
+
import { RouteRecordRaw } from "vue-router";
|
|
5
|
+
|
|
6
|
+
//#region src/composables/use-naive-menu.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* 配置选项接口
|
|
9
|
+
* 用于定义 useNaiveMenu 组合函数的配置参数
|
|
10
|
+
*/
|
|
11
|
+
type UseNaiveMenuOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* 隐藏条件,可以是函数或字符串
|
|
14
|
+
* - 如果是函数,返回 true 时路由将不显示在菜单中
|
|
15
|
+
* - 如果是字符串,则从 route.meta 中获取对应属性的值
|
|
16
|
+
* @default 'hidden'
|
|
17
|
+
*/
|
|
18
|
+
hidden?: ((route: RouteRecordRaw) => boolean | string) | string;
|
|
19
|
+
/**
|
|
20
|
+
* 根路由判断,可以是函数或字符串
|
|
21
|
+
* - 如果是函数,返回 true 时路由将作为顶级菜单
|
|
22
|
+
* - 如果是字符串,则从 route.meta 中获取对应属性的值
|
|
23
|
+
* @default 'root'
|
|
24
|
+
*/
|
|
25
|
+
root?: ((route: RouteRecordRaw) => boolean | string) | string;
|
|
26
|
+
/**
|
|
27
|
+
* 标签字段名,从 route.meta 中获取对应属性的值作为菜单标签
|
|
28
|
+
* @default 'title'
|
|
29
|
+
*/
|
|
30
|
+
labelField?: string;
|
|
31
|
+
/**
|
|
32
|
+
* 键字段名,从 route 中获取对应属性的值作为菜单键
|
|
33
|
+
* @default 'name'
|
|
34
|
+
*/
|
|
35
|
+
keyField?: string;
|
|
36
|
+
/**
|
|
37
|
+
* 图标字段名,从 route.meta 中获取对应属性的值作为菜单图标
|
|
38
|
+
* @default 'icon'
|
|
39
|
+
*/
|
|
40
|
+
iconField?: string;
|
|
41
|
+
/**
|
|
42
|
+
* 图标渲染函数,用于自定义图标渲染
|
|
43
|
+
*/
|
|
44
|
+
renderIcon?: (icon: string) => VNodeChild;
|
|
45
|
+
/**
|
|
46
|
+
* 父路由元信息字段名
|
|
47
|
+
* @default 'parent'
|
|
48
|
+
*/
|
|
49
|
+
parentField?: string;
|
|
50
|
+
/**
|
|
51
|
+
* 父路由文件路径
|
|
52
|
+
* @default ''
|
|
53
|
+
*/
|
|
54
|
+
parentFilePath?: string;
|
|
55
|
+
/**
|
|
56
|
+
* 父路由元信息生成函数
|
|
57
|
+
*/
|
|
58
|
+
parent?: (route: RouteRecordRaw) => Record<string, unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* 自定义菜单选项创建函数
|
|
61
|
+
*/
|
|
62
|
+
createMenuOption?: (route: RouteRecordRaw) => MenuOption;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* 自动菜单组合函数
|
|
66
|
+
* 将路由配置转换为菜单配置,并提供扁平化的菜单选项
|
|
67
|
+
* @param routes 路由配置数组,可以是响应式或普通数组
|
|
68
|
+
* @param options 配置选项
|
|
69
|
+
* @returns 包含菜单选项和扁平化菜单选项的对象
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* // 基本使用
|
|
73
|
+
* const { menuOptions, flattenedMenuOptions } = useNaiveMenu(routes)
|
|
74
|
+
*
|
|
75
|
+
* // 带配置选项(使用函数)
|
|
76
|
+
* const { menuOptions, flattenedMenuOptions } = useNaiveMenu(routes, {
|
|
77
|
+
* hidden: (route) => route.meta?.hidden,
|
|
78
|
+
* root: (route) => route.meta?.root,
|
|
79
|
+
* labelField: 'title',
|
|
80
|
+
* keyField: 'name',
|
|
81
|
+
* iconField: 'icon',
|
|
82
|
+
* renderIcon: (icon) => h('i', { class: icon })
|
|
83
|
+
* })
|
|
84
|
+
*
|
|
85
|
+
* // 带配置选项(使用字符串)
|
|
86
|
+
* const { menuOptions, flattenedMenuOptions } = useNaiveMenu(routes, {
|
|
87
|
+
* hidden: 'hidden',
|
|
88
|
+
* root: 'root',
|
|
89
|
+
* labelField: 'title',
|
|
90
|
+
* keyField: 'name',
|
|
91
|
+
* iconField: 'icon'
|
|
92
|
+
* })
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare function useNaiveMenu(routes: MaybeRefOrGetter<RouteRecordRaw[]>, options?: UseNaiveMenuOptions): {
|
|
96
|
+
menuOptions: vue8.ComputedRef<MenuOption[]>;
|
|
97
|
+
flattenedMenuOptions: vue8.ComputedRef<MenuOption[]>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* useNaiveMenu 返回类型
|
|
101
|
+
*/
|
|
102
|
+
type UseNaiveMenuReturn = ReturnType<typeof useNaiveMenu>;
|
|
103
|
+
//#endregion
|
|
104
|
+
export { UseNaiveMenuOptions, UseNaiveMenuReturn, useNaiveMenu };
|