@mi-avalon/libs 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/package.json +12 -5
  2. package/src/components/ItemsRow/index.scss +0 -18
  3. package/src/components/ItemsRow/index.tsx +0 -85
  4. package/src/components/MBreadcrumb/index.scss +0 -82
  5. package/src/components/MBreadcrumb/index.tsx +0 -93
  6. package/src/components/MDescriptions/index.tsx +0 -131
  7. package/src/components/MForm/MFormItemConst.tsx +0 -206
  8. package/src/components/MForm/index.scss +0 -13
  9. package/src/components/MForm/index.tsx +0 -97
  10. package/src/components/MForm/type.ts +0 -229
  11. package/src/components/MSearch/index.scss +0 -63
  12. package/src/components/MSearch/index.tsx +0 -173
  13. package/src/components/MTable/index.tsx +0 -22
  14. package/src/components/MiModal/index.tsx +0 -106
  15. package/src/components/ThemeContext/CompThemeProvider.tsx +0 -19
  16. package/src/components/ThemeContext/index.ts +0 -20
  17. package/src/components/index.ts +0 -9
  18. package/src/constants/date.ts +0 -11
  19. package/src/constants/index.ts +0 -3
  20. package/src/constants/pageInfo.ts +0 -1
  21. package/src/constants/pattern.ts +0 -53
  22. package/src/hooks/index.ts +0 -7
  23. package/src/hooks/useFuncRequest.ts +0 -100
  24. package/src/hooks/useInterval.ts +0 -50
  25. package/src/hooks/usePagination.ts +0 -184
  26. package/src/hooks/useQuery.ts +0 -6
  27. package/src/hooks/useReactive.ts +0 -26
  28. package/src/hooks/useTimeout.ts +0 -50
  29. package/src/hooks/useVirtualList.ts +0 -209
  30. package/src/index.tsx +0 -4
  31. package/src/utils/calc.ts +0 -92
  32. package/src/utils/index.ts +0 -5
  33. package/src/utils/nextTick.ts +0 -89
  34. package/src/utils/openModal.tsx +0 -137
  35. package/src/utils/util.ts +0 -37
  36. package/src/utils/version.ts +0 -206
@@ -1,20 +0,0 @@
1
- import { theme, ThemeConfig } from 'antd';
2
- import { createContext, useContext } from 'react';
3
-
4
- interface ThemeContextType {
5
- theme?: ThemeConfig;
6
- }
7
-
8
- const ThemeContext = createContext<ThemeContextType>({
9
- theme: {
10
- cssVar: true,
11
- algorithm: [theme.defaultAlgorithm],
12
- },
13
- });
14
- export const MiThemeProvider = ThemeContext.Provider;
15
-
16
- export function useMiThemeConfig() {
17
- return useContext(ThemeContext);
18
- }
19
-
20
- export * from './CompThemeProvider';
@@ -1,9 +0,0 @@
1
- export { default as ItemRow } from './ItemsRow';
2
- export { default as MBreadcrumb } from './MBreadcrumb';
3
- export { default as MDescriptions } from './MDescriptions';
4
- export * from './MForm';
5
- export { default as MForm } from './MForm';
6
- export { default as MiModal } from './MiModal';
7
- export { default as MSearch } from './MSearch';
8
- export { default as MTable } from './MTable';
9
- export * from './ThemeContext';
@@ -1,11 +0,0 @@
1
- export const DATE_FORMAT = {
2
- YMD_Hms: 'YYYY-MM-DD HH:mm:ss',
3
- YMD: 'YYYY-MM-DD',
4
- YMD2: 'YYYYMMDD',
5
- YMD_POINT: 'YYYY.M.DD',
6
- Hms: 'HH:mm:ss',
7
- Hm: 'HH:mm',
8
- YMD_000: 'YYYY-MM-DD 00:00:00',
9
- YMD_end: 'YYYY-MM-DD 23:59:59',
10
- YMD_Hm: 'YYYYMMDD HHmm',
11
- };
@@ -1,3 +0,0 @@
1
- export * from './date';
2
- export * from './pageInfo';
3
- export * from './pattern';
@@ -1 +0,0 @@
1
- export const PAGE_SIZE = 10;
@@ -1,53 +0,0 @@
1
- export class PatternType {
2
- // 整数
3
- static readonly integerRegex = /^-?\d+$/;
4
- // 正整数
5
- static readonly positiveIntegerRegex = /^[1-9]\d*$/;
6
- // 负整数
7
- static readonly negativeIntegerRegex = /^-[1-9]\d*$/;
8
- // 浮点数
9
- static readonly floatRegex = /^-?\d+(\.\d+)?$/;
10
- // 字母
11
- static readonly letter = /^[a-zA-Z]+$/;
12
- // 汉字
13
- static readonly chinese = /^[\u4e00-\u9fa5]+$/;
14
- // 数字
15
- static readonly number = /^[0-9]*$/;
16
-
17
- // 用户名 字母开头,允许字母数字下划线,长度4-16
18
- static readonly username = /^[a-zA-Z]\w{3,15}$/;
19
- // 强用户名 必须包含大小写字母和数字,6-20位
20
- static readonly strongUsername = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{6,20}$/;
21
-
22
- // 密码 至少8位,包含字母和数字
23
- static readonly password = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/;
24
- // 强密码 至少8位,包含大小写字母、数字和特殊字符
25
- static readonly strongPassword =
26
- /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
27
-
28
- // 中国大陆的手机号
29
- static readonly phone = /^1[3-9]\d{9}$/;
30
- // 带区号的手机号
31
- static readonly phoneWithAreaCode = /^\+?\d{2,3}-?\d{8,11}$/;
32
- // 邮箱
33
- static readonly email = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
34
- // 身份证
35
- static readonly idCard =
36
- /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
37
- // 银行卡
38
- static readonly bankCard = /^[1-9]\d{3,30}$/;
39
- // 邮政编码
40
- static readonly zipCode = /^[1-9]\d{5}$/;
41
- // IP
42
- static readonly ip =
43
- /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
44
- // URL
45
- static readonly url = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/;
46
- // 车牌
47
- static readonly carNumber =
48
- /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/;
49
- // 时间 hh:mm:ss
50
- static readonly time = /^([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/;
51
- // 日期 YYYY-MM-DD
52
- static readonly date = /^(\d{4})-(\d{2})-(\d{2})$/;
53
- }
@@ -1,7 +0,0 @@
1
- export * from './useFuncRequest';
2
- export * from './useInterval';
3
- export * from './usePagination';
4
- export * from './useQuery';
5
- export * from './useReactive';
6
- export * from './useTimeout';
7
- export * from './useVirtualList';
@@ -1,100 +0,0 @@
1
- import { useEffect, useRef, useState } from 'react';
2
-
3
- type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
4
-
5
- export type UseFuncRequestOptions<
6
- T extends (...args: any[]) => Promise<any>
7
- > = {
8
- // 自动执行时的参数
9
- autoRunArgs?: Parameters<T>;
10
- // 开始执行前的回调函数 false 不执行 true 执行
11
- onBefore?: (...args: Parameters<T>) => boolean | Promise<boolean>;
12
- // 执行成功后的回调函数
13
- onSuccess?: (data: UnwrapPromise<ReturnType<T>>) => void | Promise<void>;
14
- // 执行失败后的回调函数
15
- onError?: (error: Error) => void | Promise<void>;
16
- // 结束后的回调函数
17
- onFinally?: () => void | Promise<void>;
18
- };
19
-
20
- export function useFuncRequest<T extends (...args: any[]) => Promise<any>>(
21
- // 异步函数
22
- asyncFunc: T,
23
- // 配置项
24
- options?: UseFuncRequestOptions<T>
25
- ) {
26
- const [loading, setLoading] = useState(false);
27
- const [error, setError] = useState<Error | null>(null);
28
- const [data, setData] = useState<UnwrapPromise<ReturnType<T>> | null>(null);
29
- const abortControllerRef = useRef<AbortController>(undefined);
30
- const requestIdRef = useRef(0);
31
-
32
- const cancel = () => {
33
- abortControllerRef.current?.abort();
34
- setLoading(false);
35
- setError(null);
36
- };
37
-
38
- const run = async (...args: Parameters<T>) => {
39
- const currentRequestId = ++requestIdRef.current;
40
- cancel();
41
-
42
- const abortController = new AbortController();
43
- abortControllerRef.current = abortController;
44
-
45
- try {
46
- setLoading(true);
47
- setError(null);
48
- if (options?.onBefore) {
49
- const beforeRes = await options?.onBefore?.(...args);
50
- if (!beforeRes) {
51
- cancel();
52
- return;
53
- }
54
- }
55
-
56
- // 安全传递 AbortSignal
57
- const funcArgs =
58
- args.length >= asyncFunc.length
59
- ? args
60
- : [...args, { signal: abortController.signal }];
61
-
62
- const res = await asyncFunc(...(funcArgs as Parameters<T>));
63
-
64
- if (
65
- !abortController.signal.aborted &&
66
- currentRequestId === requestIdRef.current
67
- ) {
68
- setData(res);
69
- await options?.onSuccess?.(res);
70
- }
71
- return res;
72
- } catch (err) {
73
- if (
74
- !abortController.signal.aborted &&
75
- currentRequestId === requestIdRef.current
76
- ) {
77
- setError(err as Error);
78
- await options?.onError?.(err as Error);
79
- }
80
- throw err;
81
- } finally {
82
- if (
83
- !abortController.signal.aborted &&
84
- currentRequestId === requestIdRef.current
85
- ) {
86
- setLoading(false);
87
- await options?.onFinally?.();
88
- }
89
- }
90
- };
91
-
92
- useEffect(() => {
93
- if (options?.autoRunArgs) {
94
- run(...options.autoRunArgs).catch(() => {});
95
- }
96
- return cancel;
97
- }, [JSON.stringify(options?.autoRunArgs)]);
98
-
99
- return { run, cancel, loading, error, data };
100
- }
@@ -1,50 +0,0 @@
1
- import { useCallback, useEffect, useRef } from 'react';
2
-
3
- type Callback = () => void;
4
-
5
- interface UseTimeoutReturn {
6
- start: Callback;
7
- isRunning: boolean;
8
- clear: Callback;
9
- }
10
-
11
- function useInterval(
12
- callback: Callback,
13
- delay: number | null,
14
- immediate: boolean = false
15
- ): UseTimeoutReturn {
16
- const timerRef = useRef<ReturnType<typeof setInterval>>(undefined);
17
- const savedCallback = useRef(callback);
18
-
19
- // Update callback ref if callback changes
20
- useEffect(() => {
21
- savedCallback.current = callback;
22
- }, [callback]);
23
-
24
- const clear = useCallback(() => {
25
- if (timerRef.current) {
26
- clearInterval(timerRef.current);
27
- timerRef.current = undefined;
28
- }
29
- }, []);
30
-
31
- const start = useCallback(() => {
32
- clear();
33
- if (delay !== null && delay !== undefined) {
34
- timerRef.current = setInterval(() => savedCallback.current(), delay);
35
- }
36
- }, [delay, clear]);
37
-
38
- useEffect(() => {
39
- if (immediate) {
40
- savedCallback.current();
41
- }
42
- start();
43
-
44
- return clear;
45
- }, [delay, start, clear, immediate]);
46
-
47
- return { start, clear, isRunning: !!timerRef.current };
48
- }
49
-
50
- export { useInterval };
@@ -1,184 +0,0 @@
1
- import { debounce } from 'lodash';
2
- import { useCallback, useEffect, useRef, useState } from 'react';
3
-
4
- interface IPaginationProps {
5
- current: number;
6
- pageSize: number;
7
- total: number;
8
- onChange: (page: number, pageSize: number) => Promise<void>;
9
- onShowSizeChange: (size: number, current: number) => Promise<void>;
10
- showTotal?: (t: number) => React.ReactNode;
11
- showQuickJumper?: boolean;
12
- showSizeChanger?: boolean;
13
- }
14
-
15
- interface PaginationResult<T> {
16
- tableProps: {
17
- loading?: boolean;
18
- dataSource: T[];
19
- };
20
- loading?: boolean;
21
- dataSource: T[];
22
- paginationProps: IPaginationProps;
23
- isFirstComplete: boolean;
24
- refresh: (resetPage?: boolean) => Promise<void>;
25
- debounceRefresh: (resetPage?: boolean) => void;
26
- setDataSource: (data: T[]) => void;
27
- }
28
-
29
- interface IServerParams {
30
- offset: number;
31
- limit: number;
32
- current: number;
33
- }
34
-
35
- type IInfoBack<T> = { dataSource: T[]; total: number };
36
-
37
- type IInfoServer<T> = (params: IServerParams) => IInfoBack<T> | Promise<IInfoBack<T>>;
38
-
39
- interface IInfoOption<T> {
40
- isReady?: boolean;
41
- dataSource?: T[];
42
- current?: number;
43
- pageSize?: number;
44
- }
45
-
46
- export const usePagination = <T>(
47
- server: IInfoServer<T>,
48
- deps?: any[], // 依赖条件 数据更新默认执行server
49
- option?: IInfoOption<T>,
50
- ): PaginationResult<T> => {
51
- const {
52
- isReady = true,
53
- dataSource: propDataSource = [],
54
- current: propCurrent = 1,
55
- pageSize: propPageSize = 10,
56
- } = option || {};
57
-
58
- const [current, setCurrent] = useState(propCurrent);
59
- const [pageSize, setPageSize] = useState(propPageSize);
60
- const [dataSource, setDataSource] = useState<T[]>(propDataSource);
61
- const [total, setTotal] = useState(0);
62
- const [loading, setLoading] = useState(false);
63
- const [isFirstComplete, setIsFirstComplete] = useState(false);
64
- const currentRef = useRef(current);
65
- const pageSizeRef = useRef(pageSize);
66
-
67
- // 在状态更新时同步更新ref
68
- const setCurrentAndRef = (val: number) => {
69
- setCurrent(val);
70
- currentRef.current = val;
71
- };
72
-
73
- const setPageSizeAndRef = (val: number) => {
74
- setPageSize(val);
75
- pageSizeRef.current = val;
76
- };
77
-
78
- // 计数器
79
- const seq = useRef(0);
80
-
81
- const doSearch = async () => {
82
- if (!isReady) {
83
- return;
84
- }
85
- let _current = currentRef.current;
86
- let _pageSize = pageSizeRef.current;
87
- setLoading(true);
88
-
89
- seq.current++;
90
- const _seq = seq.current;
91
- try {
92
- // 发送请求
93
- let offset = Math.round((_current - 1) * _pageSize);
94
- if (offset < 0) {
95
- offset = 0;
96
- }
97
- if (_pageSize < 1) {
98
- _pageSize = 1;
99
- }
100
- let { dataSource: data_source, total: _total } = await server({
101
- limit: _pageSize,
102
- offset,
103
- current: _current,
104
- });
105
-
106
- if (_seq !== seq.current) return;
107
- if (pageSize * (_current - 1) >= _total && _current !== 1) {
108
- _current = 1;
109
- const totalPage = Math.ceil(_total / pageSize);
110
- ({ dataSource: data_source, total: _total } = await server({
111
- limit: _pageSize,
112
- offset,
113
- current: _current,
114
- }));
115
- if (_seq !== seq.current) return;
116
- _current = totalPage;
117
- }
118
- setDataSource(data_source);
119
- setCurrentAndRef(_current);
120
- setPageSizeAndRef(_pageSize);
121
- setTotal(_total);
122
- } catch (error) {
123
- // eslint-disable-next-line no-console
124
- console.error('fetch err', error);
125
- if (_seq !== seq.current) return;
126
- } finally {
127
- setIsFirstComplete(true);
128
- setLoading(false);
129
- }
130
- };
131
-
132
- const refresh = async (resetPage?: boolean) => {
133
- if (resetPage) {
134
- setDataSource([]);
135
- setCurrentAndRef(propCurrent);
136
- setPageSizeAndRef(propPageSize);
137
- }
138
- await doSearch();
139
- };
140
-
141
- const debounceRefresh = useCallback(debounce(refresh, 500), [refresh]);
142
-
143
- /* 重置逻辑 */
144
- const _deps = [...(deps || []), isReady];
145
-
146
- useEffect(() => {
147
- if (!isReady) return;
148
- debounceRefresh(true);
149
- }, _deps);
150
-
151
- const onChange = async (page: number, pageSize: number) => {
152
- setCurrentAndRef(page);
153
- setPageSizeAndRef(pageSize);
154
- await refresh();
155
- };
156
-
157
- const onShowSizeChange = async (size: number, current: number) => {
158
- setPageSizeAndRef(size);
159
- setCurrentAndRef(current);
160
- await refresh();
161
- };
162
-
163
- const paginationProps: IPaginationProps = {
164
- current,
165
- pageSize,
166
- total,
167
- onChange,
168
- onShowSizeChange,
169
- };
170
-
171
- return {
172
- tableProps: {
173
- loading,
174
- dataSource,
175
- },
176
- loading,
177
- dataSource,
178
- paginationProps,
179
- isFirstComplete,
180
- refresh,
181
- debounceRefresh,
182
- setDataSource,
183
- };
184
- };
@@ -1,6 +0,0 @@
1
- export function useQuery() {
2
- const search = window.location.href.split('?')[1] || '';
3
- const params = new URLSearchParams(search);
4
- const query = Object.fromEntries(params.entries());
5
- return query;
6
- }
@@ -1,26 +0,0 @@
1
- import { useCallback, useRef, useState } from 'react';
2
-
3
- const useReactive = <T extends object>(initialState: T) => {
4
- const [state, setState] = useState<T>(initialState);
5
- const stateRef = useRef<T>(state);
6
-
7
- const updateState = useCallback((newState: Partial<T> | ((prev: T) => Partial<T>)) => {
8
- setState(prev => {
9
- const updatedPart = typeof newState === 'function' ? newState(prev) : newState;
10
- const newFullState = { ...prev, ...updatedPart };
11
- stateRef.current = newFullState; // 同步更新ref
12
- return newFullState;
13
- });
14
- }, []);
15
-
16
- const getState = useCallback(() => stateRef.current, []);
17
-
18
- const resetState = useCallback(() => {
19
- setState(initialState);
20
- stateRef.current = initialState;
21
- }, [initialState]);
22
-
23
- return [state, updateState, getState, resetState] as const;
24
- };
25
-
26
- export { useReactive };
@@ -1,50 +0,0 @@
1
- import { useCallback, useEffect, useRef } from 'react';
2
-
3
- type Callback = () => void;
4
-
5
- interface UseTimeoutReturn {
6
- start: Callback;
7
- isRunning: boolean;
8
- clear: Callback;
9
- }
10
-
11
- function useTimeout(
12
- callback: Callback,
13
- delay: number | null,
14
- immediate: boolean = false
15
- ): UseTimeoutReturn {
16
- const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
17
- const savedCallback = useRef(callback);
18
-
19
- // Update callback ref if callback changes
20
- useEffect(() => {
21
- savedCallback.current = callback;
22
- }, [callback]);
23
-
24
- const clear = useCallback(() => {
25
- if (timerRef.current) {
26
- clearTimeout(timerRef.current);
27
- timerRef.current = undefined;
28
- }
29
- }, []);
30
-
31
- const start = useCallback(() => {
32
- clear();
33
- if (delay !== null && delay !== undefined) {
34
- timerRef.current = setTimeout(() => savedCallback.current(), delay);
35
- }
36
- }, [delay, clear]);
37
-
38
- useEffect(() => {
39
- if (immediate) {
40
- savedCallback.current();
41
- }
42
- start();
43
-
44
- return clear;
45
- }, [delay, start, clear, immediate]);
46
-
47
- return { start, clear, isRunning: !!timerRef.current };
48
- }
49
-
50
- export { useTimeout };