@yugu-ui/shared 0.0.0-stage → 0.1.1
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/bin.ts +4 -0
- package/dist/bin.d.ts +0 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/reg.d.ts +12 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +15 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/use-boolean.d.ts +12 -0
- package/dist/hooks/use-context.d.ts +15 -0
- package/dist/hooks/use-count-down.d.ts +12 -0
- package/dist/hooks/use-loading.d.ts +10 -0
- package/dist/hooks/use-request.d.ts +23 -0
- package/dist/hooks/use-svg-icon-render.d.ts +19 -0
- package/dist/hooks/use-table.d.ts +63 -0
- package/dist/hooks.d.ts +2 -0
- package/dist/hooks.js +205 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3146 -0
- package/dist/nanoid-CQE6QAZJ.js +2 -0
- package/dist/request/constant.d.ts +6 -0
- package/dist/request/index.d.ts +22 -0
- package/dist/request/options.d.ts +6 -0
- package/dist/request/shared.d.ts +17 -0
- package/dist/request/type.d.ts +94 -0
- package/dist/request.d.ts +2 -0
- package/dist/request.js +182 -0
- package/dist/scripts/src/commands/changelog.d.ts +2 -0
- package/dist/scripts/src/commands/cleanup.d.ts +1 -0
- package/dist/scripts/src/commands/git-commit.d.ts +9 -0
- package/dist/scripts/src/commands/index.d.ts +6 -0
- package/dist/scripts/src/commands/release.d.ts +1 -0
- package/dist/scripts/src/commands/router.d.ts +2 -0
- package/dist/scripts/src/commands/update-pkg.d.ts +1 -0
- package/dist/scripts/src/config/index.d.ts +2 -0
- package/dist/scripts/src/index.d.ts +1 -0
- package/dist/scripts/src/locales/index.d.ts +25 -0
- package/dist/scripts/src/shared/index.d.ts +2 -0
- package/dist/scripts/src/types/index.d.ts +30 -0
- package/dist/uno-preset/index.d.ts +4 -0
- package/dist/uno-preset.d.ts +6 -0
- package/dist/uno-preset.js +49 -0
- package/dist/utils/color/constant/index.d.ts +2 -0
- package/dist/utils/color/constant/name.d.ts +8 -0
- package/dist/utils/color/constant/palette.d.ts +2 -0
- package/dist/utils/color/index.d.ts +5 -0
- package/dist/utils/color/palette/antd.d.ts +18 -0
- package/dist/utils/color/palette/index.d.ts +17 -0
- package/dist/utils/color/palette/recommend.d.ts +20 -0
- package/dist/utils/color/shared/colord.d.ts +38 -0
- package/dist/utils/color/shared/index.d.ts +2 -0
- package/dist/utils/color/shared/name.d.ts +6 -0
- package/dist/utils/color/types/index.d.ts +52 -0
- package/dist/utils/common.d.ts +2 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/klona.d.ts +2 -0
- package/dist/utils/nanoid.d.ts +1 -0
- package/dist/utils/storage.d.ts +28 -0
- package/package.json +89 -4
- package/scripts/src/commands/changelog.ts +10 -0
- package/scripts/src/commands/cleanup.ts +5 -0
- package/scripts/src/commands/git-commit.ts +107 -0
- package/scripts/src/commands/index.ts +6 -0
- package/scripts/src/commands/release.ts +12 -0
- package/scripts/src/commands/router.ts +90 -0
- package/scripts/src/commands/update-pkg.ts +5 -0
- package/scripts/src/config/index.ts +39 -0
- package/scripts/src/index.ts +110 -0
- package/scripts/src/locales/index.ts +84 -0
- package/scripts/src/shared/index.ts +7 -0
- package/scripts/src/types/index.ts +31 -0
- package/README.md +0 -3
package/bin.ts
ADDED
package/dist/bin.d.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './reg';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通用表单正则(从 ops src/constants/reg.ts 抽出通用部分,业务字段正则保留各项目内)
|
|
3
|
+
* Developed collaboratively with vscode - 改动代码行数: 10行
|
|
4
|
+
*/
|
|
5
|
+
export declare const REG_USER_NAME: RegExp;
|
|
6
|
+
export declare const REG_USER_ACCOUNT: RegExp;
|
|
7
|
+
export declare const REG_PHONE: RegExp;
|
|
8
|
+
export declare const REG_PWD: RegExp;
|
|
9
|
+
export declare const REG_EMAIL: RegExp;
|
|
10
|
+
export declare const REG_CODE_SIX: RegExp;
|
|
11
|
+
export declare const REG_CODE_FOUR: RegExp;
|
|
12
|
+
export declare const REG_URL: RegExp;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/constants/reg.ts
|
|
2
|
+
/**
|
|
3
|
+
* 通用表单正则(从 ops src/constants/reg.ts 抽出通用部分,业务字段正则保留各项目内)
|
|
4
|
+
* Developed collaboratively with vscode - 改动代码行数: 10行
|
|
5
|
+
*/
|
|
6
|
+
var REG_USER_NAME = /^[a-zA-Z0-9!@#$%^&*()_+=-]{4,12}$/;
|
|
7
|
+
var REG_USER_ACCOUNT = /^[a-zA-Z0-9!@#$%^&*()_+=-]{4,12}$/;
|
|
8
|
+
var REG_PHONE = /^1[3-9]\d{9}$/;
|
|
9
|
+
var REG_PWD = /^(?![0-9]+$)(?![a-zA-Z]+$)(?![!@#$%^&*()_+=-]+$)[0-9A-Za-z!@#$%^&*()_+=-]{8,16}$/;
|
|
10
|
+
var REG_EMAIL = /^[\w.%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
11
|
+
var REG_CODE_SIX = /^\d{6}$/;
|
|
12
|
+
var REG_CODE_FOUR = /^\d{4}$/;
|
|
13
|
+
var REG_URL = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { REG_CODE_FOUR, REG_CODE_SIX, REG_EMAIL, REG_PHONE, REG_PWD, REG_URL, REG_USER_ACCOUNT, REG_USER_NAME };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as useBoolean } from './use-boolean';
|
|
2
|
+
import { default as useLoading } from './use-loading';
|
|
3
|
+
import { default as useCountDown } from './use-count-down';
|
|
4
|
+
import { default as useContext } from './use-context';
|
|
5
|
+
import { default as useSvgIconRender } from './use-svg-icon-render';
|
|
6
|
+
import { default as useTable } from './use-table';
|
|
7
|
+
export { useBoolean, useLoading, useCountDown, useContext, useSvgIconRender, useTable };
|
|
8
|
+
export type * from './use-table';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boolean
|
|
3
|
+
*
|
|
4
|
+
* @param initValue Init value
|
|
5
|
+
*/
|
|
6
|
+
export default function useBoolean(initValue?: boolean): {
|
|
7
|
+
bool: import('vue').Ref<boolean, boolean>;
|
|
8
|
+
setBool: (value: boolean) => void;
|
|
9
|
+
setTrue: () => void;
|
|
10
|
+
setFalse: () => void;
|
|
11
|
+
toggle: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type ContextName = string | {
|
|
2
|
+
name: string;
|
|
3
|
+
key: string | symbol;
|
|
4
|
+
};
|
|
5
|
+
type ContextValue<T> = T extends (...args: any[]) => any ? ReturnType<T> : T;
|
|
6
|
+
type ContextProvider<T> = T extends (...args: any[]) => any ? T : (arg: T) => T;
|
|
7
|
+
type ContextConsumer<Context> = <N extends string | null | undefined = undefined>(consumerName?: N, defaultValue?: Context) => N extends null | undefined ? Context | null : Context;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a context provider and consumer pair.
|
|
10
|
+
*
|
|
11
|
+
* @param contextName - The name of the context. This can be a string or an object with a `name` and `key` property.
|
|
12
|
+
* @param composable - An optional composable function that returns the context value. If not provided, the context value will be the first argument passed to the provider.
|
|
13
|
+
*/
|
|
14
|
+
export default function useContext<T>(contextName: ContextName, composable?: T extends (...args: any[]) => any ? T : never): [ContextProvider<T>, ContextConsumer<ContextValue<T>>];
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hook for implementing a countdown timer. It uses `requestAnimationFrame` for smooth and accurate timing,
|
|
3
|
+
* independent of the screen refresh rate.
|
|
4
|
+
*
|
|
5
|
+
* @param initialSeconds - The total number of seconds for the countdown.
|
|
6
|
+
*/
|
|
7
|
+
export default function useCountDown(initialSeconds: number): {
|
|
8
|
+
count: import('vue').ComputedRef<number>;
|
|
9
|
+
isCounting: import('vue').ComputedRef<boolean>;
|
|
10
|
+
start: (updatedSeconds?: number) => void;
|
|
11
|
+
stop: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { AxiosError, CreateAxiosDefaults, CustomAxiosRequestConfig, MappedType, RequestInstanceCommon, RequestOption, ResponseType } from '../request/index';
|
|
3
|
+
export type HookRequestInstanceResponseSuccessData<ApiData> = {
|
|
4
|
+
data: Ref<ApiData>;
|
|
5
|
+
error: Ref<null>;
|
|
6
|
+
};
|
|
7
|
+
export type HookRequestInstanceResponseFailData<ResponseData> = {
|
|
8
|
+
data: Ref<null>;
|
|
9
|
+
error: Ref<AxiosError<ResponseData>>;
|
|
10
|
+
};
|
|
11
|
+
export type HookRequestInstanceResponseData<ResponseData, ApiData> = {
|
|
12
|
+
loading: Ref<boolean>;
|
|
13
|
+
} & (HookRequestInstanceResponseSuccessData<ApiData> | HookRequestInstanceResponseFailData<ResponseData>);
|
|
14
|
+
export interface HookRequestInstance<ResponseData, ApiData, State extends Record<string, unknown>> extends RequestInstanceCommon<State> {
|
|
15
|
+
<T extends ApiData = ApiData, R extends ResponseType = 'json'>(config: CustomAxiosRequestConfig): HookRequestInstanceResponseData<ResponseData, MappedType<R, T>>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* create a hook request instance
|
|
19
|
+
*
|
|
20
|
+
* @param axiosConfig
|
|
21
|
+
* @param options
|
|
22
|
+
*/
|
|
23
|
+
export default function createHookRequest<ResponseData, ApiData, State extends Record<string, unknown>>(axiosConfig?: CreateAxiosDefaults, options?: Partial<RequestOption<ResponseData, ApiData, State>>): HookRequestInstance<ResponseData, ApiData, State>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Component } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Svg icon render hook
|
|
4
|
+
*
|
|
5
|
+
* @param SvgIcon Svg icon component
|
|
6
|
+
*/
|
|
7
|
+
export interface IconConfig {
|
|
8
|
+
/** Local icon name */
|
|
9
|
+
localIcon?: string;
|
|
10
|
+
/** Icon color */
|
|
11
|
+
color?: string;
|
|
12
|
+
/** Icon size */
|
|
13
|
+
fontSize?: number;
|
|
14
|
+
}
|
|
15
|
+
export default function useSvgIconRender(SvgIcon: Component): {
|
|
16
|
+
SvgIconVNode: (config: IconConfig) => (() => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}>) | undefined;
|
|
19
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Ref, VNodeChild } from 'vue';
|
|
2
|
+
export interface PaginationData<T> {
|
|
3
|
+
data: T[];
|
|
4
|
+
pageNum: number;
|
|
5
|
+
total: number;
|
|
6
|
+
}
|
|
7
|
+
type GetApiData<ApiData, Pagination extends boolean> = Pagination extends true ? PaginationData<ApiData> : ApiData[];
|
|
8
|
+
type Transform<ResponseData, ApiData, Pagination extends boolean> = (response: ResponseData) => GetApiData<ApiData, Pagination>;
|
|
9
|
+
export type TableColumnCheckTitle = string | ((...args: any) => VNodeChild);
|
|
10
|
+
export type TableColumnCheck = {
|
|
11
|
+
titleText?: string;
|
|
12
|
+
key: string;
|
|
13
|
+
title: TableColumnCheckTitle;
|
|
14
|
+
checked: boolean;
|
|
15
|
+
visible: boolean;
|
|
16
|
+
fixed: 'left' | 'right' | 'unFixed';
|
|
17
|
+
};
|
|
18
|
+
export interface UseTableOptions<ResponseData, ApiData, Column, Pagination extends boolean> {
|
|
19
|
+
/**
|
|
20
|
+
* api function to get table data
|
|
21
|
+
*/
|
|
22
|
+
api: () => Promise<ResponseData>;
|
|
23
|
+
/**
|
|
24
|
+
* whether to enable pagination
|
|
25
|
+
*/
|
|
26
|
+
pagination?: Pagination;
|
|
27
|
+
/**
|
|
28
|
+
* transform api response to table data
|
|
29
|
+
*/
|
|
30
|
+
transform: Transform<ResponseData, ApiData, Pagination>;
|
|
31
|
+
/**
|
|
32
|
+
* columns factory
|
|
33
|
+
*/
|
|
34
|
+
columns: () => Column[];
|
|
35
|
+
/**
|
|
36
|
+
* get column checks
|
|
37
|
+
*/
|
|
38
|
+
getColumnChecks: (columns: Column[]) => TableColumnCheck[];
|
|
39
|
+
/**
|
|
40
|
+
* get columns
|
|
41
|
+
*/
|
|
42
|
+
getColumns: (columns: Column[], checks: TableColumnCheck[]) => Column[];
|
|
43
|
+
/**
|
|
44
|
+
* callback when response fetched
|
|
45
|
+
*/
|
|
46
|
+
onFetched?: (data: GetApiData<ApiData, Pagination>) => void | Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* whether to get data immediately
|
|
49
|
+
*
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
immediate?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export default function useTable<ResponseData, ApiData, Column, Pagination extends boolean>(options: UseTableOptions<ResponseData, ApiData, Column, Pagination>): {
|
|
55
|
+
loading: Ref<boolean, boolean>;
|
|
56
|
+
empty: Ref<boolean, boolean>;
|
|
57
|
+
data: Ref<ApiData[], ApiData[]>;
|
|
58
|
+
columns: import('vue').ComputedRef<Column[]>;
|
|
59
|
+
columnChecks: Ref<TableColumnCheck[], TableColumnCheck[]>;
|
|
60
|
+
reloadColumns: () => void;
|
|
61
|
+
getData: () => Promise<void>;
|
|
62
|
+
};
|
|
63
|
+
export {};
|
package/dist/hooks.d.ts
ADDED
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { computed, h, inject, onScopeDispose, provide, ref } from "vue";
|
|
2
|
+
import { useRafFn } from "@vueuse/core";
|
|
3
|
+
//#region src/hooks/use-boolean.ts
|
|
4
|
+
/**
|
|
5
|
+
* Boolean
|
|
6
|
+
*
|
|
7
|
+
* @param initValue Init value
|
|
8
|
+
*/
|
|
9
|
+
function useBoolean(initValue = false) {
|
|
10
|
+
const bool = ref(initValue);
|
|
11
|
+
function setBool(value) {
|
|
12
|
+
bool.value = value;
|
|
13
|
+
}
|
|
14
|
+
function setTrue() {
|
|
15
|
+
setBool(true);
|
|
16
|
+
}
|
|
17
|
+
function setFalse() {
|
|
18
|
+
setBool(false);
|
|
19
|
+
}
|
|
20
|
+
function toggle() {
|
|
21
|
+
setBool(!bool.value);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
bool,
|
|
25
|
+
setBool,
|
|
26
|
+
setTrue,
|
|
27
|
+
setFalse,
|
|
28
|
+
toggle
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/hooks/use-loading.ts
|
|
33
|
+
/**
|
|
34
|
+
* Loading
|
|
35
|
+
*
|
|
36
|
+
* @param initValue Init value
|
|
37
|
+
*/
|
|
38
|
+
function useLoading(initValue = false) {
|
|
39
|
+
const { bool: loading, setTrue: startLoading, setFalse: endLoading } = useBoolean(initValue);
|
|
40
|
+
return {
|
|
41
|
+
loading,
|
|
42
|
+
startLoading,
|
|
43
|
+
endLoading
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/hooks/use-count-down.ts
|
|
48
|
+
/**
|
|
49
|
+
* A hook for implementing a countdown timer. It uses `requestAnimationFrame` for smooth and accurate timing,
|
|
50
|
+
* independent of the screen refresh rate.
|
|
51
|
+
*
|
|
52
|
+
* @param initialSeconds - The total number of seconds for the countdown.
|
|
53
|
+
*/
|
|
54
|
+
function useCountDown(initialSeconds) {
|
|
55
|
+
const remainingSeconds = ref(0);
|
|
56
|
+
const count = computed(() => Math.ceil(remainingSeconds.value));
|
|
57
|
+
const isCounting = computed(() => remainingSeconds.value > 0);
|
|
58
|
+
const { pause, resume } = useRafFn(({ delta }) => {
|
|
59
|
+
if (remainingSeconds.value <= 0) {
|
|
60
|
+
remainingSeconds.value = 0;
|
|
61
|
+
pause();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const secondsPassed = delta / 1e3;
|
|
65
|
+
remainingSeconds.value -= secondsPassed;
|
|
66
|
+
if (remainingSeconds.value <= 0) {
|
|
67
|
+
remainingSeconds.value = 0;
|
|
68
|
+
pause();
|
|
69
|
+
}
|
|
70
|
+
}, { immediate: false });
|
|
71
|
+
/**
|
|
72
|
+
* Starts the countdown.
|
|
73
|
+
*
|
|
74
|
+
* @param [updatedSeconds=initialSeconds] - Optionally, start with a new duration. Default is `initialSeconds`
|
|
75
|
+
*/
|
|
76
|
+
function start(updatedSeconds = initialSeconds) {
|
|
77
|
+
remainingSeconds.value = updatedSeconds;
|
|
78
|
+
resume();
|
|
79
|
+
}
|
|
80
|
+
/** Stops the countdown and resets the remaining time to 0. */
|
|
81
|
+
function stop() {
|
|
82
|
+
remainingSeconds.value = 0;
|
|
83
|
+
pause();
|
|
84
|
+
}
|
|
85
|
+
onScopeDispose(() => {
|
|
86
|
+
pause();
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
count,
|
|
90
|
+
isCounting,
|
|
91
|
+
start,
|
|
92
|
+
stop
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/hooks/use-context.ts
|
|
97
|
+
/**
|
|
98
|
+
* Creates a context provider and consumer pair.
|
|
99
|
+
*
|
|
100
|
+
* @param contextName - The name of the context. This can be a string or an object with a `name` and `key` property.
|
|
101
|
+
* @param composable - An optional composable function that returns the context value. If not provided, the context value will be the first argument passed to the provider.
|
|
102
|
+
*/
|
|
103
|
+
function useContext(contextName, composable) {
|
|
104
|
+
const name = typeof contextName === "string" ? contextName : contextName.name;
|
|
105
|
+
const key = typeof contextName === "string" ? Symbol(contextName) : contextName.key;
|
|
106
|
+
/**
|
|
107
|
+
* Injects the context value.
|
|
108
|
+
*
|
|
109
|
+
* @param consumerName - The name of the component that is consuming the context. If provided, the component must be
|
|
110
|
+
* used within the context provider.
|
|
111
|
+
* @param defaultValue - The default value to return if the context is not provided.
|
|
112
|
+
* @returns The context value.
|
|
113
|
+
*/
|
|
114
|
+
const useInject = (consumerName, defaultValue) => {
|
|
115
|
+
const value = inject(key, defaultValue) ?? null;
|
|
116
|
+
if (consumerName != null && value === null) throw new Error(`\`${consumerName}\` must be used within \`${name}\``);
|
|
117
|
+
return value;
|
|
118
|
+
};
|
|
119
|
+
const useProvide = (...args) => {
|
|
120
|
+
const value = composable?.(...args) ?? args[0];
|
|
121
|
+
provide(key, value);
|
|
122
|
+
return value;
|
|
123
|
+
};
|
|
124
|
+
return [useProvide, useInject];
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/hooks/use-svg-icon-render.ts
|
|
128
|
+
function useSvgIconRender(SvgIcon) {
|
|
129
|
+
/**
|
|
130
|
+
* Svg icon VNode
|
|
131
|
+
*
|
|
132
|
+
* @param config
|
|
133
|
+
*/
|
|
134
|
+
const SvgIconVNode = (config) => {
|
|
135
|
+
const { color, fontSize, localIcon } = config;
|
|
136
|
+
const style = {};
|
|
137
|
+
if (color) style.color = color;
|
|
138
|
+
if (fontSize) style.fontSize = `${fontSize}px`;
|
|
139
|
+
if (!localIcon) return;
|
|
140
|
+
return () => h(SvgIcon, {
|
|
141
|
+
localIcon,
|
|
142
|
+
style
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
return { SvgIconVNode };
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/hooks/use-table.ts
|
|
149
|
+
function useTable(options) {
|
|
150
|
+
const { loading, startLoading, endLoading } = useLoading();
|
|
151
|
+
const { bool: empty, setBool: setEmpty } = useBoolean();
|
|
152
|
+
const { api, pagination, transform, columns, getColumnChecks, getColumns, onFetched, immediate = true } = options;
|
|
153
|
+
const data = ref([]);
|
|
154
|
+
const columnChecks = ref(getColumnChecks(columns()));
|
|
155
|
+
const $columns = computed(() => getColumns(columns(), columnChecks.value));
|
|
156
|
+
function reloadColumns() {
|
|
157
|
+
const currentChecks = columnChecks.value;
|
|
158
|
+
const checkMap = new Map(currentChecks.map((col) => [col.key, col.checked]));
|
|
159
|
+
const fixedMap = new Map(currentChecks.map((col) => [col.key, col.fixed]));
|
|
160
|
+
const defaultChecks = getColumnChecks(columns());
|
|
161
|
+
const defaultMap = new Map(defaultChecks.map((col) => [col.key, col]));
|
|
162
|
+
const result = [];
|
|
163
|
+
const usedKeys = /* @__PURE__ */ new Set();
|
|
164
|
+
for (const col of currentChecks) {
|
|
165
|
+
const defaultCol = defaultMap.get(col.key);
|
|
166
|
+
if (defaultCol) {
|
|
167
|
+
result.push({
|
|
168
|
+
...defaultCol,
|
|
169
|
+
checked: checkMap.get(col.key) ?? defaultCol.checked,
|
|
170
|
+
fixed: (fixedMap.get(col.key) !== "unFixed" ? fixedMap.get(col.key) : void 0) ?? defaultCol.fixed
|
|
171
|
+
});
|
|
172
|
+
usedKeys.add(col.key);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const col of defaultChecks) if (!usedKeys.has(col.key)) result.push(col);
|
|
176
|
+
columnChecks.value = result;
|
|
177
|
+
}
|
|
178
|
+
async function getData() {
|
|
179
|
+
try {
|
|
180
|
+
startLoading();
|
|
181
|
+
const transformed = transform(await api());
|
|
182
|
+
data.value = getTableData(transformed, pagination);
|
|
183
|
+
setEmpty(data.value.length === 0);
|
|
184
|
+
await onFetched?.(transformed);
|
|
185
|
+
} finally {
|
|
186
|
+
endLoading();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (immediate) getData();
|
|
190
|
+
return {
|
|
191
|
+
loading,
|
|
192
|
+
empty,
|
|
193
|
+
data,
|
|
194
|
+
columns: $columns,
|
|
195
|
+
columnChecks,
|
|
196
|
+
reloadColumns,
|
|
197
|
+
getData
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function getTableData(data, pagination) {
|
|
201
|
+
if (pagination) return data.data;
|
|
202
|
+
return data;
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
export { useBoolean, useContext, useCountDown, useLoading, useSvgIconRender, useTable };
|
package/dist/index.d.ts
ADDED