@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,209 +0,0 @@
1
- // 虚拟列表加载
2
- import { debounce } from 'lodash';
3
- import { DependencyList, useCallback, useEffect, useRef, useState } from 'react';
4
- import { PAGE_SIZE } from '../constants';
5
-
6
- export interface IPaginationResult<T> {
7
- /**
8
- * 数据
9
- *
10
- * @memberof IPaginationResult
11
- */
12
- dataSource: T[];
13
- /**
14
- * 加载状态
15
- *
16
- * @memberof IPaginationResult
17
- */
18
- loading?: boolean;
19
- /**
20
- * 是否完成了一次请求
21
- *
22
- * @memberof IPaginationResult
23
- */
24
- isFirstComplete: boolean;
25
- /**
26
- * 分页信息
27
- *
28
- * @memberof IPaginationResult
29
- */
30
- paginationProps: {
31
- current: number;
32
- pageSize: number;
33
- total: number;
34
- };
35
- /**
36
- * reset 是否重置查询
37
- *
38
- * @memberof IPaginationResult
39
- */
40
- refresh: (reset?: boolean) => Promise<void>;
41
- debounceRefresh: (reset?: boolean) => void;
42
- /* 快速逃避方案 */
43
- setDataSource: (data: T[]) => void;
44
- setTotal: (total: number) => void;
45
- }
46
-
47
- interface IServerParams {
48
- offset: number;
49
- limit: number;
50
- current: number;
51
- }
52
-
53
- type IInfoBack<T> = { dataSource: T[]; total: number };
54
-
55
- type IInfoServer<T> = (params: IServerParams) => IInfoBack<T> | Promise<IInfoBack<T>>;
56
-
57
- interface IInfoOption<T> {
58
- /**
59
- * 第一次是否执行server
60
- *
61
- */
62
- isReady?: boolean;
63
- /**
64
- * 默认的数据
65
- *
66
- */
67
- dataSource?: T[];
68
- /**
69
- * 默认当前第几页
70
- *
71
- */
72
- current?: number;
73
- /**
74
- * 默认一页几条数据
75
- *
76
- */
77
- pageSize?: number;
78
- }
79
-
80
- export const useVirtualList = <T>(
81
- server: IInfoServer<T>,
82
- deps?: DependencyList, // 依赖条件 数据更新默认执行server
83
- option?: IInfoOption<T>,
84
- ): IPaginationResult<T> => {
85
- const {
86
- isReady = true,
87
- dataSource: propDataSource = [],
88
- current: propCurrent = 1,
89
- pageSize: propPageSize = PAGE_SIZE,
90
- } = option || {};
91
-
92
- // 是否完成了一次请求
93
- const [isFirstComplete, setIsFirstComplete] = useState(false);
94
- // 分页
95
- const [current, setCurrent] = useState(propCurrent);
96
- const [pageSize, setPageSize] = useState(propPageSize);
97
- const [total, setTotal] = useState(0);
98
-
99
- // 表格
100
- const [isLoading, setIsLoading] = useState(false);
101
- const [dataSource, setDataSource] = useState(propDataSource);
102
-
103
- const currentRef = useRef(current);
104
- const pageSizeRef = useRef(pageSize);
105
-
106
- // 在状态更新时同步更新ref
107
- const setCurrentAndRef = (val: number) => {
108
- setCurrent(val);
109
- currentRef.current = val;
110
- };
111
-
112
- const setPageSizeAndRef = (val: number) => {
113
- setPageSize(val);
114
- pageSizeRef.current = val;
115
- };
116
-
117
- // 计数器
118
- const seq = useRef(0);
119
- const doSearch = async (reset?: boolean) => {
120
- if (!isReady) {
121
- return;
122
- }
123
- let _current = currentRef.current;
124
- let _pageSize = pageSizeRef.current;
125
- setIsLoading(true);
126
-
127
- seq.current += 1;
128
- const _seq = seq.current;
129
- try {
130
- // 发送请求
131
- let offset = Math.round((_current - 1) * _pageSize);
132
- if (offset < 0) {
133
- offset = 0;
134
- }
135
- if (_pageSize < 1) {
136
- _pageSize = 1;
137
- }
138
- let { dataSource: data0, total: total0 } = await server({
139
- limit: _pageSize,
140
- offset,
141
- current: _current,
142
- });
143
- if (_seq !== seq.current) return;
144
- if (pageSize * (_current - 1) >= total0 && _current !== 1) {
145
- const totalPage = Math.ceil(total0 / pageSize);
146
- ({ dataSource: data0, total: total0 } = await server({
147
- limit: _pageSize,
148
- offset: Math.round((totalPage - 1) * _pageSize),
149
- current: _current,
150
- }));
151
- if (_seq !== seq.current) return;
152
- _current = totalPage;
153
- // message.error('数据源发生变化,该页没有数据,自动加载最后一页');
154
- }
155
- const d = reset ? data0 : dataSource.concat(data0 as T[]);
156
- setDataSource(d);
157
- setCurrentAndRef(_current);
158
- setPageSizeAndRef(_pageSize);
159
- setTotal(total0);
160
- } catch (error) {
161
- console.error('fetch err', error);
162
- if (_seq !== seq.current) return;
163
- }
164
- setIsFirstComplete(true);
165
- setIsLoading(false);
166
- };
167
-
168
- // 加载下一页数据
169
- const refresh = async (reset?: boolean) => {
170
- if (reset) {
171
- setDataSource([]);
172
- setCurrentAndRef(propCurrent);
173
- setPageSizeAndRef(propPageSize);
174
- } else {
175
- const curTotal = pageSize * current;
176
- if (total && total <= curTotal) return;
177
- setCurrentAndRef(current + 1);
178
- }
179
- await doSearch(reset);
180
- };
181
-
182
- // 防抖 加载下一页数据
183
- const debounceRefresh = useCallback(debounce(refresh, 500), [refresh]);
184
-
185
- /* 重置逻辑 */
186
- const _deps = [...(deps || []), isReady];
187
-
188
- useEffect(() => {
189
- if (!isReady) return;
190
- debounceRefresh(true);
191
- }, _deps);
192
-
193
- return {
194
- loading: isLoading,
195
- dataSource,
196
- paginationProps: {
197
- current,
198
- pageSize,
199
- total,
200
- },
201
- isFirstComplete,
202
- refresh: async (reset?: boolean) => {
203
- await refresh(reset);
204
- },
205
- debounceRefresh,
206
- setDataSource,
207
- setTotal,
208
- };
209
- };
package/src/index.tsx DELETED
@@ -1,4 +0,0 @@
1
- export * from './components';
2
- export * from './constants';
3
- export * from './hooks';
4
- export * from './utils';
package/src/utils/calc.ts DELETED
@@ -1,92 +0,0 @@
1
- class CMX {
2
- /**
3
- ** 加
4
- **/
5
- add = function (arg1: number, arg2: number) {
6
- let r1, r2, m, c;
7
- try {
8
- r1 = arg1.toString().split('.')[1].length;
9
- } catch (e) {
10
- r1 = 0;
11
- }
12
- try {
13
- r2 = arg2.toString().split('.')[1].length;
14
- } catch (e) {
15
- r2 = 0;
16
- }
17
- c = Math.abs(r1 - r2);
18
- m = Math.pow(10, Math.max(r1, r2));
19
- if (c > 0) {
20
- let cm = Math.pow(10, c);
21
- if (r1 > r2) {
22
- arg1 = Number(arg1.toString().replace('.', ''));
23
- arg2 = Number(arg2.toString().replace('.', '')) * cm;
24
- } else {
25
- arg1 = Number(arg1.toString().replace('.', '')) * cm;
26
- arg2 = Number(arg2.toString().replace('.', ''));
27
- }
28
- } else {
29
- arg1 = Number(arg1?.toString().replace('.', ''));
30
- arg2 = Number(arg2?.toString().replace('.', ''));
31
- }
32
- return (arg1 + arg2) / m;
33
- };
34
- /**
35
- ** 减
36
- **/
37
- sub = function (arg1: number, arg2: number) {
38
- let r1, r2, m, n;
39
- try {
40
- r1 = arg1.toString().split('.')[1].length;
41
- } catch (e) {
42
- r1 = 0;
43
- }
44
- try {
45
- r2 = arg2.toString().split('.')[1].length;
46
- } catch (e) {
47
- r2 = 0;
48
- }
49
- m = Math.pow(10, Math.max(r1, r2)); //last modify by deeka //动态控制精度长度
50
- n = r1 >= r2 ? r1 : r2;
51
- return Number(((arg1 * m - arg2 * m) / m).toFixed(n));
52
- };
53
-
54
- /**
55
- ** 乘
56
- **/
57
- mul = function (arg1: number, arg2: number) {
58
- let m = 0,
59
- s1 = arg1.toString(),
60
- s2 = arg2.toString();
61
- try {
62
- m += s1.split('.')[1].length;
63
- } catch (e) { }
64
- try {
65
- m += s2.split('.')[1].length;
66
- } catch (e) { }
67
- return (
68
- (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m)
69
- );
70
- };
71
-
72
- /**
73
- ** 除
74
- **/
75
- div = function (arg1: number, arg2: number) {
76
- let t1 = 0,
77
- t2 = 0,
78
- r1,
79
- r2;
80
- try {
81
- t1 = arg1.toString().split('.')[1].length;
82
- } catch (e) { }
83
- try {
84
- t2 = arg2.toString().split('.')[1].length;
85
- } catch (e) { }
86
- r1 = Number(arg1.toString().replace('.', ''));
87
- r2 = Number(arg2.toString().replace('.', ''));
88
- return (r1 / r2) * Math.pow(10, t2 - t1);
89
- };
90
- }
91
-
92
- export const cmx = new CMX();
@@ -1,5 +0,0 @@
1
- export * from './calc';
2
- export * from './nextTick';
3
- export * from './openModal';
4
- export * from './util';
5
- export * from './version';
@@ -1,89 +0,0 @@
1
- type NextTickCallback = () => void;
2
- type NextTickPromiseResolver = () => void;
3
-
4
- class NextTick {
5
- private callbacks: NextTickCallback[] = [];
6
- private pending = false;
7
- private timerFunc: () => void;
8
-
9
- constructor() {
10
- this.timerFunc = this.determineTimerFunc();
11
- }
12
-
13
- private determineTimerFunc(): () => void {
14
- if (typeof Promise !== 'undefined') {
15
- const p = Promise.resolve();
16
- return () => p.then(this.flushCallbacks.bind(this));
17
- }
18
-
19
- if (typeof MutationObserver !== 'undefined' && typeof window !== 'undefined') {
20
- let counter = 1;
21
- const observer = new MutationObserver(this.flushCallbacks.bind(this));
22
- const textNode = document.createTextNode(String(counter));
23
- observer.observe(textNode, { characterData: true });
24
-
25
- return () => {
26
- counter = (counter + 1) % 2;
27
- textNode.data = String(counter);
28
- };
29
- }
30
-
31
- // // 仅在 Node.js 环境中使用 setImmediate
32
- // if (typeof global !== 'undefined' && typeof setImmediate !== 'undefined') {
33
- // return () => setImmediate(this.flushCallbacks.bind(this));
34
- // }
35
-
36
- return () => setTimeout(this.flushCallbacks.bind(this), 0);
37
- }
38
-
39
- private flushCallbacks(): void {
40
- this.pending = false;
41
- const copies = this.callbacks.slice(0);
42
- this.callbacks.length = 0;
43
- for (let i = 0; i < copies.length; i++) {
44
- copies[i]();
45
- }
46
- }
47
-
48
- public nextTick<T = void>(callback?: (this: T) => void, ctx?: T): Promise<void> | void {
49
- let _resolve: NextTickPromiseResolver | undefined;
50
-
51
- this.callbacks.push(() => {
52
- if (callback) {
53
- try {
54
- callback.call(ctx as T);
55
- } catch (e) {
56
- console.error('Error in nextTick:', e);
57
- }
58
- } else if (_resolve) {
59
- _resolve();
60
- }
61
- });
62
-
63
- if (!this.pending) {
64
- this.pending = true;
65
- this.timerFunc();
66
- }
67
-
68
- if (!callback && typeof Promise !== 'undefined') {
69
- return new Promise(resolve => {
70
- _resolve = resolve;
71
- });
72
- }
73
- }
74
-
75
- public static nextTick<T = void>(callback?: (this: T) => void, ctx?: T): Promise<void> | void {
76
- return NextTick.instance.nextTick(callback, ctx);
77
- }
78
-
79
- private static _instance: NextTick;
80
- public static get instance(): NextTick {
81
- if (!this._instance) {
82
- this._instance = new NextTick();
83
- }
84
- return this._instance;
85
- }
86
- }
87
-
88
- const nextTick = NextTick.instance.nextTick.bind(NextTick.instance);
89
- export { NextTick, nextTick };
@@ -1,137 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { ModalProps } from 'antd';
3
- import React, { ComponentType } from 'react';
4
- import * as ReactDOMClient from 'react-dom/client';
5
- const { createRoot } = ReactDOMClient;
6
- type Root = ReactDOMClient.Root;
7
-
8
- const destroyFns: Array<() => void> = [];
9
- let modalContainer: HTMLDivElement | null = null;
10
- let root: Root | null = null;
11
-
12
- interface IModalBaseClosedParams {
13
- cancel?: boolean;
14
- ok?: boolean;
15
- }
16
-
17
- export interface IModalBaseProps extends ModalProps {
18
- onClosed?: (params?: IModalBaseClosedParams) => void;
19
- }
20
-
21
- export interface IModalControls<T = any> {
22
- destroy: (params?: IModalBaseClosedParams) => void;
23
- update: (configUpdate: Partial<T> | ((prevConfig: T) => T)) => void;
24
- }
25
-
26
- function getOrCreateContainer(): HTMLDivElement {
27
- if (!modalContainer) {
28
- modalContainer = document.createElement('div');
29
- document.body.appendChild(modalContainer);
30
- }
31
- return modalContainer;
32
- }
33
-
34
- function openModal<ITModalProps extends IModalBaseProps = IModalBaseProps>(
35
- DialogComponent: ComponentType<ITModalProps>,
36
- initialConfig: ITModalProps
37
- ): IModalControls<ITModalProps> {
38
- const container = getOrCreateContainer();
39
-
40
- let currentConfig = {
41
- open: true,
42
- ...initialConfig,
43
- // 默认自动关闭
44
- onClosed:
45
- initialConfig.onClosed ||
46
- ((params?: IModalBaseClosedParams) => {
47
- unifiedDestroy(params);
48
- }),
49
- } as ITModalProps;
50
-
51
- if (!root) {
52
- try {
53
- root = createRoot(container);
54
- } catch (error) {
55
- console.error('Failed to create root:', error);
56
- return {
57
- destroy: () => {},
58
- update: () => {},
59
- };
60
- }
61
- }
62
-
63
- const cleanup = () => {
64
- if (root) {
65
- root.unmount();
66
- root = null;
67
- }
68
-
69
- if (modalContainer && modalContainer.parentNode) {
70
- modalContainer.parentNode.removeChild(modalContainer);
71
- modalContainer = null;
72
- }
73
- };
74
-
75
- const destroy = (params?: IModalBaseClosedParams) => {
76
- if (typeof currentConfig.onClosed === 'function') {
77
- currentConfig.onClosed(params);
78
- }
79
-
80
- // 从 destroyFns 中移除
81
- const index = destroyFns.indexOf(destroy);
82
- if (index !== -1) {
83
- destroyFns.splice(index, 1);
84
- }
85
-
86
- // 销毁 modal
87
- cleanup();
88
- };
89
-
90
- const render = (props: ITModalProps) => {
91
- if (root) {
92
- root.render(<DialogComponent {...props} />);
93
- }
94
- };
95
-
96
- const update = (
97
- configUpdate:
98
- | Partial<ITModalProps>
99
- | ((prevConfig: ITModalProps) => ITModalProps)
100
- ) => {
101
- currentConfig =
102
- typeof configUpdate === 'function'
103
- ? configUpdate(currentConfig)
104
- : { ...currentConfig, ...configUpdate };
105
- render(currentConfig);
106
- };
107
-
108
- // 统一的销毁函数
109
- const unifiedDestroy = (params?: IModalBaseClosedParams) => {
110
- // 如果当前配置是打开的,关闭
111
- if (currentConfig.open) {
112
- currentConfig = {
113
- ...currentConfig,
114
- open: false,
115
- onClosed: (closedParams?: IModalBaseClosedParams) => {
116
- if (initialConfig.onClosed) {
117
- initialConfig.onClosed(closedParams || params);
118
- }
119
- destroy(closedParams || params);
120
- },
121
- };
122
- render(currentConfig);
123
- } else {
124
- console.warn('Modal is already closed.');
125
- }
126
- };
127
-
128
- render(currentConfig);
129
- destroyFns.push(unifiedDestroy);
130
-
131
- return {
132
- destroy: unifiedDestroy,
133
- update,
134
- };
135
- }
136
-
137
- export { openModal };
package/src/utils/util.ts DELETED
@@ -1,37 +0,0 @@
1
- export const noop = () => {};
2
-
3
- // 生成类名
4
- export const getClassName = (key1: string, key2: string) => {
5
- const cn = key1;
6
- let str = key1;
7
- if (key2.includes(' ')) {
8
- str = '';
9
- const nArr = key2?.split(' ');
10
- for (const i of nArr) {
11
- str += ` ${cn}-${i}`;
12
- }
13
- } else if (key2) {
14
- str = `${key1}-${key2}`;
15
- }
16
- return str;
17
- };
18
-
19
- // 根据路径获取数据
20
- export const getFieldsByPath = (data: any, path: string) => {
21
- const arr = path?.split('.');
22
- let res = data;
23
- for (const i of arr) {
24
- res = res[i];
25
- }
26
- return res;
27
- };
28
-
29
- // 删除空值
30
- export const removeNull = (obj: any) => {
31
- for (const key in obj) {
32
- if (obj[key] === null) {
33
- delete obj[key];
34
- }
35
- }
36
- return obj;
37
- };