@mi-avalon/libs 1.0.2 → 1.0.4
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/dist/components/ItemsRow/index.d.ts +10 -2
- package/dist/components/ItemsRow/index.js +26 -10
- package/dist/components/MForm/MFormItemConst.js +9 -1
- package/dist/components/MForm/index.d.ts +2 -4
- package/dist/components/MForm/index.js +62 -21
- package/dist/constants/date.d.ts +42 -11
- package/dist/constants/date.js +29 -0
- package/dist/constants/pattern.d.ts +96 -89
- package/dist/constants/pattern.js +134 -89
- package/dist/hooks/useFuncRequest.d.ts +1 -0
- package/dist/hooks/useFuncRequest.js +9 -7
- package/dist/hooks/useInterval.d.ts +2 -2
- package/dist/hooks/useInterval.js +5 -2
- package/dist/hooks/useQuery.d.ts +1 -3
- package/dist/hooks/useQuery.js +51 -4
- package/dist/hooks/useTimeout.js +11 -4
- package/dist/index.es.js +6803 -6596
- package/dist/index.umd.js +82 -82
- package/dist/utils/util.d.ts +55 -5
- package/dist/utils/util.js +245 -46
- package/package.json +2 -2
|
@@ -15,7 +15,7 @@ export interface IRowItem {
|
|
|
15
15
|
/**
|
|
16
16
|
* 如果没有指定Render,则是按钮的onClick
|
|
17
17
|
*/
|
|
18
|
-
onClick?: (e:
|
|
18
|
+
onClick?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
19
19
|
/**
|
|
20
20
|
* 其他按钮属性
|
|
21
21
|
*/
|
|
@@ -24,6 +24,10 @@ export interface IRowItem {
|
|
|
24
24
|
* item 的className
|
|
25
25
|
*/
|
|
26
26
|
className?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 唯一标识,用于React key
|
|
29
|
+
*/
|
|
30
|
+
key?: React.Key;
|
|
27
31
|
/**
|
|
28
32
|
* 自定义渲染
|
|
29
33
|
*/
|
|
@@ -38,5 +42,9 @@ export interface IItemRowProps {
|
|
|
38
42
|
style?: React.CSSProperties;
|
|
39
43
|
className?: string;
|
|
40
44
|
offsetTop?: number;
|
|
45
|
+
/**
|
|
46
|
+
* @description 容器测试ID,用于测试
|
|
47
|
+
*/
|
|
48
|
+
testId?: string;
|
|
41
49
|
}
|
|
42
|
-
export declare const ItemsRow:
|
|
50
|
+
export declare const ItemsRow: React.NamedExoticComponent<IItemRowProps>;
|
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Button } from 'antd';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useMemo } from 'react';
|
|
3
5
|
import { getClassName } from '../../utils';
|
|
4
6
|
import { CompThemeProvider } from '../ThemeContext';
|
|
5
7
|
const classname = (n = '') => {
|
|
6
8
|
const cn = 'items-row';
|
|
7
9
|
return getClassName(cn, n);
|
|
8
10
|
};
|
|
9
|
-
export const ItemsRow = (props) => {
|
|
10
|
-
|
|
11
|
+
export const ItemsRow = React.memo((props) => {
|
|
12
|
+
const { items, className, style, testId } = props;
|
|
13
|
+
// 优化:使用 useMemo 缓存渲染的子项
|
|
14
|
+
const renderedItems = useMemo(() => {
|
|
15
|
+
if (!items)
|
|
16
|
+
return null;
|
|
17
|
+
return items.map((item, index) => {
|
|
18
|
+
// 使用更好的 key 策略
|
|
19
|
+
const itemKey = item.key || item.label || index;
|
|
20
|
+
const itemClassName = `${classname('item')} ${item.className || ''}`.trim();
|
|
21
|
+
if (item.render) {
|
|
22
|
+
return (_jsx("span", { className: itemClassName, children: item.render() }, itemKey));
|
|
23
|
+
}
|
|
24
|
+
return (_jsx(Button, { className: itemClassName, ...item.btnProps, type: item.type || 'primary', onClick: item.onClick, children: item.label }, itemKey));
|
|
25
|
+
});
|
|
26
|
+
}, [items]);
|
|
27
|
+
if (!items) {
|
|
11
28
|
return null;
|
|
12
29
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
30
|
+
// 优化:使用 useMemo 缓存容器类名
|
|
31
|
+
const containerClassName = useMemo(() => {
|
|
32
|
+
return `${classname()} ${className || ''}`.trim();
|
|
33
|
+
}, [className]);
|
|
34
|
+
return (_jsx(CompThemeProvider, { children: _jsx("div", { className: containerClassName, style: style, "data-testid": testId, children: renderedItems }) }));
|
|
35
|
+
});
|
|
36
|
+
ItemsRow.displayName = 'ItemsRow';
|
|
@@ -56,7 +56,15 @@ export class MFormItemConst {
|
|
|
56
56
|
return _jsx(Checkbox.Group, { disabled: item.disabled, ...item.props });
|
|
57
57
|
};
|
|
58
58
|
static upload = (item) => {
|
|
59
|
-
|
|
59
|
+
// 确保fileList是数组类型,防止forEach错误
|
|
60
|
+
const uploadProps = {
|
|
61
|
+
...item.props,
|
|
62
|
+
};
|
|
63
|
+
// 如果fileList存在但不是数组,转换为数组
|
|
64
|
+
if (uploadProps.fileList && !Array.isArray(uploadProps.fileList)) {
|
|
65
|
+
uploadProps.fileList = [uploadProps.fileList];
|
|
66
|
+
}
|
|
67
|
+
return (_jsx(Upload, { ...uploadProps, children: item.children || (_jsxs(Button, { children: [_jsx(UploadOutlined, {}), " \u70B9\u51FB\u4E0A\u4F20"] })) }));
|
|
60
68
|
};
|
|
61
69
|
static mentions = (item) => {
|
|
62
70
|
return (_jsx(Mentions, { ...item.props, placeholder: item.placeholder || MFormItemConst.getDefaultPlaceholder(item) }));
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import './index.scss';
|
|
2
3
|
import type { IMFormProps } from './type';
|
|
3
|
-
declare
|
|
4
|
-
declare namespace MForm {
|
|
5
|
-
var displayName: string;
|
|
6
|
-
}
|
|
4
|
+
declare const MForm: React.NamedExoticComponent<IMFormProps>;
|
|
7
5
|
export default MForm;
|
|
8
6
|
export * from './MFormItemConst';
|
|
9
7
|
export * from './type';
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
* 表单组件
|
|
4
4
|
*/
|
|
5
5
|
import { Col, Form, Row } from 'antd';
|
|
6
|
+
import React, { useCallback, useMemo } from 'react';
|
|
6
7
|
import { getClassName } from '../../utils';
|
|
7
8
|
import { CompThemeProvider } from '../ThemeContext';
|
|
8
9
|
import './index.scss';
|
|
@@ -11,11 +12,12 @@ const classname = (n = '') => {
|
|
|
11
12
|
const cn = 'm-form';
|
|
12
13
|
return getClassName(cn, n);
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
+
const MForm = React.memo((props) => {
|
|
15
16
|
const { formProps, formItems = [], column = 1, form, itemLayout, formRowProps } = props;
|
|
16
|
-
|
|
17
|
+
// 优化:缓存渲染函数
|
|
18
|
+
const renderItem = useCallback((item, formInstance) => {
|
|
17
19
|
if (item.render) {
|
|
18
|
-
return item.render(
|
|
20
|
+
return item.render(formInstance);
|
|
19
21
|
}
|
|
20
22
|
const func = MFormItemConst[item.type];
|
|
21
23
|
if (item && item.type && func) {
|
|
@@ -23,28 +25,67 @@ function MForm(props) {
|
|
|
23
25
|
return renderFunc(item);
|
|
24
26
|
}
|
|
25
27
|
return _jsx("div", { className: 'error-message', children: "Invalid form item configuration" });
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
+
}, []);
|
|
29
|
+
// 优化:缓存表单项布局配置
|
|
30
|
+
const formItemLayout = useMemo(() => ({
|
|
31
|
+
styles: {
|
|
32
|
+
label: MFormItemConst.defaultLabelStyle,
|
|
33
|
+
content: MFormItemConst.defaultContentStyle,
|
|
34
|
+
},
|
|
35
|
+
...itemLayout,
|
|
36
|
+
}), [itemLayout]);
|
|
37
|
+
// 优化:缓存渲染表单项的函数
|
|
38
|
+
const renderFormItem = useCallback((item) => {
|
|
28
39
|
const { show = true } = item;
|
|
29
40
|
if (!show)
|
|
30
41
|
return null;
|
|
31
|
-
const rules =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
+
const rules = useMemo(() => {
|
|
43
|
+
const rulesArray = [...(item.rules || [])];
|
|
44
|
+
if (item.required) {
|
|
45
|
+
rulesArray.push({ required: true, message: item.required });
|
|
46
|
+
}
|
|
47
|
+
return rulesArray;
|
|
48
|
+
}, [item.rules, item.required]);
|
|
49
|
+
// 为Upload类型的表单项默认添加valuePropName="fileList"和值转换逻辑
|
|
50
|
+
const formItemProps = useMemo(() => {
|
|
51
|
+
const props = { ...item.formItemProps };
|
|
52
|
+
if (item.type === 'upload') {
|
|
53
|
+
// 如果用户没有明确设置valuePropName,则默认使用fileList
|
|
54
|
+
if (!props.valuePropName) {
|
|
55
|
+
props.valuePropName = 'fileList';
|
|
56
|
+
}
|
|
57
|
+
// 添加getValueProps确保传递给Upload的fileList始终是数组
|
|
58
|
+
if (!props.getValueProps) {
|
|
59
|
+
props.getValueProps = (value) => {
|
|
60
|
+
// 确保fileList始终是数组
|
|
61
|
+
return {
|
|
62
|
+
fileList: Array.isArray(value) ? value : [],
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return props;
|
|
68
|
+
}, [item.formItemProps, item.type]);
|
|
69
|
+
const mergedFormItemLayout = useMemo(() => ({
|
|
70
|
+
...formItemLayout,
|
|
42
71
|
...item.itemLayout,
|
|
43
|
-
};
|
|
44
|
-
return (_jsx(Col, { span: item.span || 24 / column, children: _jsxs(Row, { className: 'item-row', children: [_jsx("div", { className: classname('item-wrapper'), children: _jsx(Form.Item, { label: item.label, name: item.id, rules: rules, initialValue: item.initialValue, ...
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
}), [formItemLayout, item.itemLayout]);
|
|
73
|
+
return (_jsx(Col, { span: item.span || 24 / column, children: _jsxs(Row, { className: 'item-row', children: [_jsx("div", { className: classname('item-wrapper'), children: _jsx(Form.Item, { label: item.label, name: item.id, rules: rules, initialValue: item.initialValue, ...mergedFormItemLayout, ...formItemProps, children: renderItem(item, form) }) }), item.suffix] }) }, `col-${item.id}`));
|
|
74
|
+
}, [column, form, formItemLayout, renderItem]);
|
|
75
|
+
// 优化:缓存表单容器类名
|
|
76
|
+
const formClassName = useMemo(() => {
|
|
77
|
+
return `${classname()} ${formProps?.className || ''}`.trim();
|
|
78
|
+
}, [formProps?.className]);
|
|
79
|
+
// 优化:缓存网格容器类名
|
|
80
|
+
const gridClassName = useMemo(() => {
|
|
81
|
+
return `${classname('grid')} ${formRowProps?.className || ''}`.trim();
|
|
82
|
+
}, [formRowProps?.className]);
|
|
83
|
+
// 优化:缓存渲染的表单项
|
|
84
|
+
const renderedFormItems = useMemo(() => {
|
|
85
|
+
return formItems.map(item => renderFormItem(item));
|
|
86
|
+
}, [formItems, renderFormItem]);
|
|
87
|
+
return (_jsx(CompThemeProvider, { children: _jsx(Form, { form: form, ...formProps, className: formClassName, children: _jsx(Row, { gutter: MFormItemConst.defaultRowGutter, ...formRowProps, className: gridClassName, children: renderedFormItems }) }) }));
|
|
88
|
+
});
|
|
48
89
|
MForm.displayName = 'MForm';
|
|
49
90
|
export default MForm;
|
|
50
91
|
export * from './MFormItemConst';
|
package/dist/constants/date.d.ts
CHANGED
|
@@ -1,13 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 日期格式常量 - 增强版本,提供更好的类型安全
|
|
3
|
+
*/
|
|
1
4
|
export declare const DATE_FORMAT: {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
/** 年月日时分秒: 2024-01-01 12:30:45 */
|
|
6
|
+
readonly YMD_Hms: "YYYY-MM-DD HH:mm:ss";
|
|
7
|
+
/** 年月日: 2024-01-01 */
|
|
8
|
+
readonly YMD: "YYYY-MM-DD";
|
|
9
|
+
/** 紧凑年月日: 20240101 */
|
|
10
|
+
readonly YMD2: "YYYYMMDD";
|
|
11
|
+
/** 点号分隔年月日: 2024.1.1 */
|
|
12
|
+
readonly YMD_POINT: "YYYY.M.DD";
|
|
13
|
+
/** 时分秒: 12:30:45 */
|
|
14
|
+
readonly Hms: "HH:mm:ss";
|
|
15
|
+
/** 时分: 12:30 */
|
|
16
|
+
readonly Hm: "HH:mm";
|
|
17
|
+
/** 年月日开始时间: 2024-01-01 00:00:00 */
|
|
18
|
+
readonly YMD_000: "YYYY-MM-DD 00:00:00";
|
|
19
|
+
/** 年月日结束时间: 2024-01-01 23:59:59 */
|
|
20
|
+
readonly YMD_end: "YYYY-MM-DD 23:59:59";
|
|
21
|
+
/** 紧凑年月日时分: 20240101 1230 */
|
|
22
|
+
readonly YMD_Hm: "YYYYMMDD HHmm";
|
|
23
|
+
/** 斜杠分隔年月日: 2024/01/01 */
|
|
24
|
+
readonly YMD_SLASH: "YYYY/MM/DD";
|
|
25
|
+
/** 斜杠分隔年月日时分秒: 2024/01/01 12:30:45 */
|
|
26
|
+
readonly YMD_SLASH_Hms: "YYYY/MM/DD HH:mm:ss";
|
|
27
|
+
};
|
|
28
|
+
/** 日期格式类型 */
|
|
29
|
+
export type DateFormat = typeof DATE_FORMAT[keyof typeof DATE_FORMAT];
|
|
30
|
+
/**
|
|
31
|
+
* 常用日期格式别名,便于使用
|
|
32
|
+
*/
|
|
33
|
+
export declare const DATE_ALIASES: {
|
|
34
|
+
/** 默认完整日期时间 */
|
|
35
|
+
readonly DEFAULT: "YYYY-MM-DD HH:mm:ss";
|
|
36
|
+
/** 仅日期 */
|
|
37
|
+
readonly DATE: "YYYY-MM-DD";
|
|
38
|
+
/** 仅时间 */
|
|
39
|
+
readonly TIME: "HH:mm:ss";
|
|
40
|
+
/** 紧凑格式 */
|
|
41
|
+
readonly COMPACT: "YYYYMMDD";
|
|
42
|
+
/** 斜杠格式 */
|
|
43
|
+
readonly SLASH: "YYYY/MM/DD";
|
|
13
44
|
};
|
package/dist/constants/date.js
CHANGED
|
@@ -1,13 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 日期格式常量 - 增强版本,提供更好的类型安全
|
|
3
|
+
*/
|
|
1
4
|
export const DATE_FORMAT = {
|
|
5
|
+
/** 年月日时分秒: 2024-01-01 12:30:45 */
|
|
2
6
|
YMD_Hms: 'YYYY-MM-DD HH:mm:ss',
|
|
7
|
+
/** 年月日: 2024-01-01 */
|
|
3
8
|
YMD: 'YYYY-MM-DD',
|
|
9
|
+
/** 紧凑年月日: 20240101 */
|
|
4
10
|
YMD2: 'YYYYMMDD',
|
|
11
|
+
/** 点号分隔年月日: 2024.1.1 */
|
|
5
12
|
YMD_POINT: 'YYYY.M.DD',
|
|
13
|
+
/** 时分秒: 12:30:45 */
|
|
6
14
|
Hms: 'HH:mm:ss',
|
|
15
|
+
/** 时分: 12:30 */
|
|
7
16
|
Hm: 'HH:mm',
|
|
17
|
+
/** 年月日开始时间: 2024-01-01 00:00:00 */
|
|
8
18
|
YMD_000: 'YYYY-MM-DD 00:00:00',
|
|
19
|
+
/** 年月日结束时间: 2024-01-01 23:59:59 */
|
|
9
20
|
YMD_end: 'YYYY-MM-DD 23:59:59',
|
|
21
|
+
/** 紧凑年月日时分: 20240101 1230 */
|
|
10
22
|
YMD_Hm: 'YYYYMMDD HHmm',
|
|
23
|
+
/** 斜杠分隔年月日: 2024/01/01 */
|
|
11
24
|
YMD_SLASH: 'YYYY/MM/DD',
|
|
25
|
+
/** 斜杠分隔年月日时分秒: 2024/01/01 12:30:45 */
|
|
12
26
|
YMD_SLASH_Hms: 'YYYY/MM/DD HH:mm:ss',
|
|
13
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* 常用日期格式别名,便于使用
|
|
30
|
+
*/
|
|
31
|
+
export const DATE_ALIASES = {
|
|
32
|
+
/** 默认完整日期时间 */
|
|
33
|
+
DEFAULT: DATE_FORMAT.YMD_Hms,
|
|
34
|
+
/** 仅日期 */
|
|
35
|
+
DATE: DATE_FORMAT.YMD,
|
|
36
|
+
/** 仅时间 */
|
|
37
|
+
TIME: DATE_FORMAT.Hms,
|
|
38
|
+
/** 紧凑格式 */
|
|
39
|
+
COMPACT: DATE_FORMAT.YMD2,
|
|
40
|
+
/** 斜杠格式 */
|
|
41
|
+
SLASH: DATE_FORMAT.YMD_SLASH,
|
|
42
|
+
};
|
|
@@ -1,90 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
static readonly
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*
|
|
60
|
-
*/
|
|
61
|
-
static
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*
|
|
72
|
-
*/
|
|
73
|
-
static
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
|
-
static
|
|
86
|
-
/**
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 正则表达式模式常量 - 增强版本,提供验证函数和类型安全
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 正则表达式类型定义
|
|
6
|
+
*/
|
|
7
|
+
export type PatternType = 'integer' | 'positiveInteger' | 'negativeInteger' | 'float' | 'letter' | 'chinese' | 'number' | 'username' | 'strongUsername' | 'password' | 'strongPassword' | 'phone' | 'phoneWithAreaCode' | 'email' | 'idCard' | 'bankCard' | 'zipCode' | 'ip' | 'url' | 'carNumber' | 'time' | 'date';
|
|
8
|
+
export declare class PatternValidator {
|
|
9
|
+
static readonly patterns: {
|
|
10
|
+
/** 整数 */
|
|
11
|
+
readonly integer: RegExp;
|
|
12
|
+
/** 正整数 */
|
|
13
|
+
readonly positiveInteger: RegExp;
|
|
14
|
+
/** 负整数 */
|
|
15
|
+
readonly negativeInteger: RegExp;
|
|
16
|
+
/** 浮点数 */
|
|
17
|
+
readonly float: RegExp;
|
|
18
|
+
/** 字母 */
|
|
19
|
+
readonly letter: RegExp;
|
|
20
|
+
/** 汉字 */
|
|
21
|
+
readonly chinese: RegExp;
|
|
22
|
+
/** 数字 */
|
|
23
|
+
readonly number: RegExp;
|
|
24
|
+
/** 用户名:字母开头,允许字母数字下划线,长度4-16 */
|
|
25
|
+
readonly username: RegExp;
|
|
26
|
+
/** 强用户名:必须包含大小写字母和数字,6-20位 */
|
|
27
|
+
readonly strongUsername: RegExp;
|
|
28
|
+
/** 密码:至少8位,包含字母和数字 */
|
|
29
|
+
readonly password: RegExp;
|
|
30
|
+
/** 强密码:至少8位,包含大小写字母、数字和特殊字符 */
|
|
31
|
+
readonly strongPassword: RegExp;
|
|
32
|
+
/** 中国大陆手机号 */
|
|
33
|
+
readonly phone: RegExp;
|
|
34
|
+
/** 带区号的手机号 */
|
|
35
|
+
readonly phoneWithAreaCode: RegExp;
|
|
36
|
+
/** 邮箱 */
|
|
37
|
+
readonly email: RegExp;
|
|
38
|
+
/** 身份证 */
|
|
39
|
+
readonly idCard: RegExp;
|
|
40
|
+
/** 银行卡 */
|
|
41
|
+
readonly bankCard: RegExp;
|
|
42
|
+
/** 邮政编码 */
|
|
43
|
+
readonly zipCode: RegExp;
|
|
44
|
+
/** IP地址 */
|
|
45
|
+
readonly ip: RegExp;
|
|
46
|
+
/** URL */
|
|
47
|
+
readonly url: RegExp;
|
|
48
|
+
/** 车牌号 */
|
|
49
|
+
readonly carNumber: RegExp;
|
|
50
|
+
/** 时间格式 hh:mm:ss */
|
|
51
|
+
readonly time: RegExp;
|
|
52
|
+
/** 日期格式 YYYY-MM-DD */
|
|
53
|
+
readonly date: RegExp;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* 验证字符串是否匹配指定模式
|
|
57
|
+
* @param type 模式类型
|
|
58
|
+
* @param value 要验证的值
|
|
59
|
+
* @returns 是否匹配
|
|
60
|
+
*/
|
|
61
|
+
static validate(type: PatternType, value: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 获取指定模式的正则表达式
|
|
64
|
+
* @param type 模式类型
|
|
65
|
+
* @returns 正则表达式
|
|
66
|
+
*/
|
|
67
|
+
static getPattern(type: PatternType): RegExp;
|
|
68
|
+
/**
|
|
69
|
+
* 验证邮箱(特殊处理,支持更复杂的验证)
|
|
70
|
+
* @param email 邮箱地址
|
|
71
|
+
* @returns 是否有效
|
|
72
|
+
*/
|
|
73
|
+
static validateEmail(email: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 验证手机号(支持更多运营商)
|
|
76
|
+
* @param phone 手机号
|
|
77
|
+
* @returns 是否有效
|
|
78
|
+
*/
|
|
79
|
+
static validatePhone(phone: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* 验证身份证(包含校验位验证)
|
|
82
|
+
* @param idCard 身份证号
|
|
83
|
+
* @returns 是否有效
|
|
84
|
+
*/
|
|
85
|
+
static validateIdCard(idCard: string): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* 创建自定义验证函数
|
|
88
|
+
* @param pattern 正则表达式
|
|
89
|
+
* @param errorMessage 错误消息
|
|
90
|
+
* @returns 验证函数
|
|
91
|
+
*/
|
|
92
|
+
static createValidator(pattern: RegExp, errorMessage?: string): (value: string) => {
|
|
93
|
+
valid: boolean;
|
|
94
|
+
message?: string;
|
|
95
|
+
};
|
|
90
96
|
}
|
|
97
|
+
export declare const PatternType: typeof PatternValidator;
|