@mi-avalon/libs 0.0.25 → 0.0.27

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.
@@ -55,7 +55,7 @@ export class MFormItemConst {
55
55
  return _jsx(Checkbox.Group, { disabled: item.disabled, ...item.props });
56
56
  };
57
57
  static upload = (item) => {
58
- return (_jsx(Upload, { defaultFileList: item.initialValue, ...item.props, children: item.children || (_jsxs(Button, { children: [_jsx(UploadOutlined, {}), " \u70B9\u51FB\u4E0A\u4F20"] })) }));
58
+ return (_jsx(Upload, { ...item.props, children: item.children || (_jsxs(Button, { children: [_jsx(UploadOutlined, {}), " \u70B9\u51FB\u4E0A\u4F20"] })) }));
59
59
  };
60
60
  static mentions = (item) => {
61
61
  return (_jsx(Mentions, { ...item.props, placeholder: item.placeholder || MFormItemConst.getDefaultPlaceholder(item) }));
@@ -1,13 +1,13 @@
1
1
  import { ThemeConfig } from 'antd';
2
2
  import React, { Component } from 'react';
3
- import { IModalBaseProps } from '../../utils';
3
+ import { IModalBaseProps, IModalControls } from '../../utils';
4
4
  export type IMiModalProps = IModalBaseProps & {
5
5
  mode?: string;
6
6
  };
7
7
  export declare class MiModal extends Component<IMiModalProps> {
8
8
  static setMode: (mode: string) => void;
9
9
  static setThemeConfig: (fn: (m: string) => ThemeConfig) => void;
10
- static open: (props: IMiModalProps) => import("../../utils").IModalControls<IMiModalProps>;
10
+ static open: (props: IMiModalProps) => IModalControls<IMiModalProps>;
11
11
  getTheme(): ThemeConfig;
12
12
  handleCancel: (e: React.MouseEvent<HTMLButtonElement>) => void;
13
13
  handleOk: (e: React.MouseEvent<HTMLButtonElement>) => void;
@@ -1,9 +1,6 @@
1
- import { ThemeConfig } from 'antd';
2
- interface ThemeContextType {
3
- theme?: ThemeConfig;
4
- }
5
- export declare const MiThemeProvider: import("react").Provider<ThemeContextType>;
6
- export declare function useMiThemeConfig(): ThemeContextType;
1
+ import { ConfigProviderProps } from 'antd';
2
+ export declare const MiThemeProvider: import("react").Provider<ConfigProviderProps>;
3
+ export declare function useMiThemeConfig(): ConfigProviderProps;
7
4
  interface IProps {
8
5
  children: React.ReactNode;
9
6
  }
@@ -8,4 +8,6 @@ export declare const DATE_FORMAT: {
8
8
  YMD_000: string;
9
9
  YMD_end: string;
10
10
  YMD_Hm: string;
11
+ YMD_SLASH: string;
12
+ YMD_SLASH_Hms: string;
11
13
  };
@@ -8,4 +8,6 @@ export const DATE_FORMAT = {
8
8
  YMD_000: 'YYYY-MM-DD 00:00:00',
9
9
  YMD_end: 'YYYY-MM-DD 23:59:59',
10
10
  YMD_Hm: 'YYYYMMDD HHmm',
11
+ YMD_SLASH: 'YYYY/MM/DD',
12
+ YMD_SLASH_Hms: 'YYYY/MM/DD HH:mm:ss',
11
13
  };
@@ -1,24 +1,90 @@
1
1
  export declare class PatternType {
2
+ /**
3
+ * 整数
4
+ */
2
5
  static readonly integerRegex: RegExp;
6
+ /**
7
+ * 正整数
8
+ */
3
9
  static readonly positiveIntegerRegex: RegExp;
10
+ /**
11
+ * 负整数
12
+ */
4
13
  static readonly negativeIntegerRegex: RegExp;
14
+ /**
15
+ * 浮点数
16
+ */
5
17
  static readonly floatRegex: RegExp;
18
+ /**
19
+ * 字母
20
+ */
6
21
  static readonly letter: RegExp;
22
+ /**
23
+ * 汉字
24
+ */
7
25
  static readonly chinese: RegExp;
26
+ /**
27
+ * 数字
28
+ */
8
29
  static readonly number: RegExp;
30
+ /**
31
+ * 用户名 字母开头,允许字母数字下划线,长度4-16
32
+ */
9
33
  static readonly username: RegExp;
34
+ /**
35
+ * 强用户名 必须包含大小写字母和数字,6-20位
36
+ */
10
37
  static readonly strongUsername: RegExp;
38
+ /**
39
+ * 密码 至少8位,包含字母和数字
40
+ */
11
41
  static readonly password: RegExp;
42
+ /**
43
+ * 强密码 至少8位,包含大小写字母、数字和特殊字符
44
+ */
12
45
  static readonly strongPassword: RegExp;
46
+ /**
47
+ * 中国大陆的手机号
48
+ */
13
49
  static readonly phone: RegExp;
50
+ /**
51
+ * 带区号的手机号
52
+ */
14
53
  static readonly phoneWithAreaCode: RegExp;
54
+ /**
55
+ * 邮箱
56
+ */
15
57
  static readonly email: RegExp;
58
+ /**
59
+ * 身份证
60
+ */
16
61
  static readonly idCard: RegExp;
62
+ /**
63
+ * 银行卡
64
+ */
17
65
  static readonly bankCard: RegExp;
66
+ /**
67
+ * 邮政编码
68
+ */
18
69
  static readonly zipCode: RegExp;
70
+ /**
71
+ * IP
72
+ */
19
73
  static readonly ip: RegExp;
74
+ /**
75
+ * URL
76
+ */
20
77
  static readonly url: RegExp;
78
+ /**
79
+ * 车牌
80
+ */
21
81
  static readonly carNumber: RegExp;
82
+ /**
83
+ * 时间 hh:mm:ss
84
+ */
22
85
  static readonly time: RegExp;
86
+ /**
87
+ * 日期 YYYY-MM-DD
88
+ */
23
89
  static readonly date: RegExp;
24
90
  }
@@ -1,46 +1,90 @@
1
1
  export class PatternType {
2
- // 整数
2
+ /**
3
+ * 整数
4
+ */
3
5
  static integerRegex = /^-?\d+$/;
4
- // 正整数
6
+ /**
7
+ * 正整数
8
+ */
5
9
  static positiveIntegerRegex = /^[1-9]\d*$/;
6
- // 负整数
10
+ /**
11
+ * 负整数
12
+ */
7
13
  static negativeIntegerRegex = /^-[1-9]\d*$/;
8
- // 浮点数
14
+ /**
15
+ * 浮点数
16
+ */
9
17
  static floatRegex = /^-?\d+(\.\d+)?$/;
10
- // 字母
18
+ /**
19
+ * 字母
20
+ */
11
21
  static letter = /^[a-zA-Z]+$/;
12
- // 汉字
22
+ /**
23
+ * 汉字
24
+ */
13
25
  static chinese = /^[\u4e00-\u9fa5]+$/;
14
- // 数字
26
+ /**
27
+ * 数字
28
+ */
15
29
  static number = /^[0-9]*$/;
16
- // 用户名 字母开头,允许字母数字下划线,长度4-16
30
+ /**
31
+ * 用户名 字母开头,允许字母数字下划线,长度4-16
32
+ */
17
33
  static username = /^[a-zA-Z]\w{3,15}$/;
18
- // 强用户名 必须包含大小写字母和数字,6-20位
34
+ /**
35
+ * 强用户名 必须包含大小写字母和数字,6-20位
36
+ */
19
37
  static strongUsername = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{6,20}$/;
20
- // 密码 至少8位,包含字母和数字
38
+ /**
39
+ * 密码 至少8位,包含字母和数字
40
+ */
21
41
  static password = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/;
22
- // 强密码 至少8位,包含大小写字母、数字和特殊字符
42
+ /**
43
+ * 强密码 至少8位,包含大小写字母、数字和特殊字符
44
+ */
23
45
  static strongPassword = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
24
- // 中国大陆的手机号
46
+ /**
47
+ * 中国大陆的手机号
48
+ */
25
49
  static phone = /^1[3-9]\d{9}$/;
26
- // 带区号的手机号
50
+ /**
51
+ * 带区号的手机号
52
+ */
27
53
  static phoneWithAreaCode = /^\+?\d{2,3}-?\d{8,11}$/;
28
- // 邮箱
54
+ /**
55
+ * 邮箱
56
+ */
29
57
  static email = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
30
- // 身份证
58
+ /**
59
+ * 身份证
60
+ */
31
61
  static idCard = /^[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)$/;
32
- // 银行卡
62
+ /**
63
+ * 银行卡
64
+ */
33
65
  static bankCard = /^[1-9]\d{3,30}$/;
34
- // 邮政编码
66
+ /**
67
+ * 邮政编码
68
+ */
35
69
  static zipCode = /^[1-9]\d{5}$/;
36
- // IP
70
+ /**
71
+ * IP
72
+ */
37
73
  static ip = /^(\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])$/;
38
- // URL
74
+ /**
75
+ * URL
76
+ */
39
77
  static url = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/;
40
- // 车牌
78
+ /**
79
+ * 车牌
80
+ */
41
81
  static carNumber = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/;
42
- // 时间 hh:mm:ss
82
+ /**
83
+ * 时间 hh:mm:ss
84
+ */
43
85
  static time = /^([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/;
44
- // 日期 YYYY-MM-DD
86
+ /**
87
+ * 日期 YYYY-MM-DD
88
+ */
45
89
  static date = /^(\d{4})-(\d{2})-(\d{2})$/;
46
90
  }
@@ -65,8 +65,7 @@ option) => {
65
65
  setTotal(_total);
66
66
  }
67
67
  catch (error) {
68
- // eslint-disable-next-line no-console
69
- console.error('fetch err', error);
68
+ console.error('usePagination error', error);
70
69
  if (_seq !== seq.current)
71
70
  return;
72
71
  }
@@ -105,6 +104,9 @@ option) => {
105
104
  current,
106
105
  pageSize,
107
106
  total,
107
+ showTotal(t) {
108
+ return `共 ${t} 条`;
109
+ },
108
110
  onChange,
109
111
  onShowSizeChange,
110
112
  };
@@ -1,38 +1,13 @@
1
1
  import { DependencyList } from 'react';
2
2
  export interface IPaginationResult<T> {
3
- /**
4
- * 数据
5
- *
6
- * @memberof IPaginationResult
7
- */
8
3
  dataSource: T[];
9
- /**
10
- * 加载状态
11
- *
12
- * @memberof IPaginationResult
13
- */
14
4
  loading?: boolean;
15
- /**
16
- * 是否完成了一次请求
17
- *
18
- * @memberof IPaginationResult
19
- */
20
5
  isFirstComplete: boolean;
21
- /**
22
- * 分页信息
23
- *
24
- * @memberof IPaginationResult
25
- */
26
6
  paginationProps: {
27
7
  current: number;
28
8
  pageSize: number;
29
9
  total: number;
30
10
  };
31
- /**
32
- * reset 是否重置查询
33
- *
34
- * @memberof IPaginationResult
35
- */
36
11
  refresh: (reset?: boolean) => Promise<void>;
37
12
  debounceRefresh: (reset?: boolean) => void;
38
13
  setDataSource: (data: T[]) => void;
@@ -70,6 +45,5 @@ interface IInfoOption<T> {
70
45
  */
71
46
  pageSize?: number;
72
47
  }
73
- export declare const useVirtualList: <T>(server: IInfoServer<T>, deps?: DependencyList, // 依赖条件 数据更新默认执行server
74
- option?: IInfoOption<T>) => IPaginationResult<T>;
48
+ export declare const useVirtualList: <T>(server: IInfoServer<T>, deps?: DependencyList, option?: IInfoOption<T>) => IPaginationResult<T>;
75
49
  export {};
@@ -1,33 +1,31 @@
1
1
  // 虚拟列表加载
2
- import { useCallback, useEffect, useRef, useState, } from 'react';
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { PAGE_SIZE } from '../constants';
4
4
  import { debounce } from '../utils';
5
- export const useVirtualList = (server, deps, // 依赖条件 数据更新默认执行server
6
- option) => {
5
+ export const useVirtualList = (server, deps, option) => {
7
6
  const { isReady = true, dataSource: propDataSource = [], current: propCurrent = 1, pageSize: propPageSize = PAGE_SIZE, } = option || {};
8
- // 是否完成了一次请求
9
7
  const [isFirstComplete, setIsFirstComplete] = useState(false);
10
- // 分页
11
8
  const [current, setCurrent] = useState(propCurrent);
12
9
  const [pageSize, setPageSize] = useState(propPageSize);
13
10
  const [total, setTotal] = useState(0);
14
- // 表格
15
11
  const [isLoading, setIsLoading] = useState(false);
16
- const [dataSource, setDataSource] = useState(propDataSource);
12
+ const [dataSource, setDataSourceState] = useState(propDataSource);
17
13
  const currentRef = useRef(current);
18
14
  const pageSizeRef = useRef(pageSize);
15
+ const seq = useRef(0);
19
16
  // 在状态更新时同步更新ref
20
- const setCurrentAndRef = (val) => {
17
+ const setCurrentAndRef = useCallback((val) => {
21
18
  setCurrent(val);
22
19
  currentRef.current = val;
23
- };
24
- const setPageSizeAndRef = (val) => {
20
+ }, []);
21
+ const setPageSizeAndRef = useCallback((val) => {
25
22
  setPageSize(val);
26
23
  pageSizeRef.current = val;
27
- };
28
- // 计数器
29
- const seq = useRef(0);
30
- const doSearch = async (reset) => {
24
+ }, []);
25
+ const setDataSource = useCallback((data) => {
26
+ setDataSourceState(data);
27
+ }, []);
28
+ const doSearch = useCallback(async (reset) => {
31
29
  if (!isReady) {
32
30
  return;
33
31
  }
@@ -37,51 +35,54 @@ option) => {
37
35
  seq.current += 1;
38
36
  const _seq = seq.current;
39
37
  try {
40
- // 发送请求
41
- let offset = Math.round((_current - 1) * _pageSize);
42
- if (offset < 0) {
43
- offset = 0;
44
- }
45
- if (_pageSize < 1) {
46
- _pageSize = 1;
47
- }
48
- let { dataSource: data0, total: total0 } = await server({
38
+ let offset = Math.max(0, Math.round((_current - 1) * _pageSize));
39
+ _pageSize = Math.max(1, _pageSize);
40
+ let result = await server({
49
41
  limit: _pageSize,
50
42
  offset,
51
43
  current: _current,
52
44
  });
53
45
  if (_seq !== seq.current)
54
46
  return;
47
+ let { dataSource: data0, total: total0 } = result;
48
+ // 处理数据源变化的情况
55
49
  if (pageSize * (_current - 1) >= total0 && _current !== 1) {
56
- const totalPage = Math.ceil(total0 / pageSize);
57
- ({ dataSource: data0, total: total0 } = await server({
50
+ const totalPage = Math.max(1, Math.ceil(total0 / pageSize));
51
+ offset = Math.max(0, Math.round((totalPage - 1) * _pageSize));
52
+ result = await server({
58
53
  limit: _pageSize,
59
- offset: Math.round((totalPage - 1) * _pageSize),
60
- current: _current,
61
- }));
54
+ offset,
55
+ current: totalPage,
56
+ });
62
57
  if (_seq !== seq.current)
63
58
  return;
59
+ data0 = result.dataSource;
60
+ total0 = result.total;
64
61
  _current = totalPage;
65
- // message.error('数据源发生变化,该页没有数据,自动加载最后一页');
66
62
  }
67
- const d = reset ? data0 : dataSource.concat(data0);
68
- setDataSource(d);
63
+ const newData = reset ? data0 : [...dataSource, ...data0];
64
+ // 批量更新状态以减少渲染次数
65
+ setDataSourceState(newData);
69
66
  setCurrentAndRef(_current);
70
67
  setPageSizeAndRef(_pageSize);
71
68
  setTotal(total0);
69
+ setIsFirstComplete(true);
72
70
  }
73
71
  catch (error) {
74
- console.error('fetch err', error);
72
+ console.error('useVirtualList error', error);
75
73
  if (_seq !== seq.current)
76
74
  return;
77
75
  }
78
- setIsFirstComplete(true);
79
- setIsLoading(false);
80
- };
76
+ finally {
77
+ if (_seq === seq.current) {
78
+ setIsLoading(false);
79
+ }
80
+ }
81
+ }, [isReady, server, dataSource, setCurrentAndRef, setPageSizeAndRef]);
81
82
  // 加载下一页数据
82
- const refresh = async (reset) => {
83
+ const refresh = useCallback(async (reset) => {
83
84
  if (reset) {
84
- setDataSource([]);
85
+ setDataSourceState([]);
85
86
  setCurrentAndRef(propCurrent);
86
87
  setPageSizeAndRef(propPageSize);
87
88
  }
@@ -92,16 +93,27 @@ option) => {
92
93
  setCurrentAndRef(current + 1);
93
94
  }
94
95
  await doSearch(reset);
95
- };
96
- // 防抖 加载下一页数据
97
- const debounceRefresh = useCallback(debounce(refresh, 500), [refresh]);
98
- /* 重置逻辑 */
99
- const _deps = [...(deps || []), isReady];
96
+ }, [
97
+ current,
98
+ doSearch,
99
+ pageSize,
100
+ propCurrent,
101
+ propPageSize,
102
+ setCurrentAndRef,
103
+ setPageSizeAndRef,
104
+ total,
105
+ ]);
106
+ // 防抖刷新函数
107
+ const debounceRefresh = useCallback(debounce((reset) => {
108
+ refresh(reset);
109
+ }, 500), [refresh]);
110
+ // 使用useMemo优化依赖项
111
+ const memoizedDeps = useMemo(() => [...(deps || []), isReady], [deps, isReady]);
100
112
  useEffect(() => {
101
113
  if (!isReady)
102
114
  return;
103
115
  debounceRefresh(true);
104
- }, _deps);
116
+ }, memoizedDeps); // 使用memoized依赖项
105
117
  return {
106
118
  loading: isLoading,
107
119
  dataSource,
@@ -111,9 +123,7 @@ option) => {
111
123
  total,
112
124
  },
113
125
  isFirstComplete,
114
- refresh: async (reset) => {
115
- await refresh(reset);
116
- },
126
+ refresh,
117
127
  debounceRefresh,
118
128
  setDataSource,
119
129
  setTotal,