@tdesign/uniapp 0.7.3 → 0.8.0
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/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/action-sheet/README.md +1 -1
- package/dist/action-sheet/action-sheet.vue +158 -150
- package/dist/action-sheet/props.ts +2 -2
- package/dist/action-sheet/type.ts +1 -1
- package/dist/avatar/avatar.vue +89 -87
- package/dist/avatar-group/avatar-group.vue +69 -67
- package/dist/back-top/back-top.vue +60 -58
- package/dist/badge/badge.vue +69 -59
- package/dist/button/button.vue +121 -116
- package/dist/button/props.ts +2 -2
- package/dist/button/type.ts +1 -1
- package/dist/calendar/calendar-header.vue +4 -4
- package/dist/calendar/calendar.vue +308 -297
- package/dist/calendar/template.vue +1 -1
- package/dist/cascader/README.en-US.md +2 -1
- package/dist/cascader/README.md +2 -1
- package/dist/cascader/cascader.vue +340 -328
- package/dist/cascader/props.ts +6 -1
- package/dist/cascader/type.ts +6 -0
- package/dist/cell/cell.vue +127 -121
- package/dist/cell-group/cell-group.vue +32 -30
- package/dist/check-tag/check-tag.vue +73 -71
- package/dist/checkbox/checkbox.vue +127 -127
- package/dist/checkbox/props.ts +6 -6
- package/dist/checkbox/type.ts +3 -3
- package/dist/checkbox-group/checkbox-group.vue +175 -173
- package/dist/checkbox-group/props.ts +6 -6
- package/dist/checkbox-group/type.ts +4 -4
- package/dist/col/col.vue +26 -24
- package/dist/collapse/collapse.vue +83 -81
- package/dist/collapse-panel/collapse-panel.vue +121 -119
- package/dist/collapse-panel/props.ts +4 -4
- package/dist/collapse-panel/type.ts +2 -2
- package/dist/color-picker/README.md +1 -1
- package/dist/color-picker/color-picker.vue +324 -322
- package/dist/color-picker/props.ts +2 -2
- package/dist/color-picker/template.vue +14 -10
- package/dist/common/common.ts +1 -0
- package/dist/common/style/theme/index.css +5 -5
- package/dist/common/utils.js +7 -2
- package/dist/common/validator.js +172 -0
- package/dist/config-provider/README.en-US.md +184 -0
- package/dist/config-provider/README.md +234 -0
- package/dist/config-provider/config-provider.vue +105 -0
- package/dist/config-provider/config-store.js +70 -0
- package/dist/config-provider/props.ts +16 -0
- package/dist/config-provider/reactive-state.js +39 -0
- package/dist/config-provider/type.ts +401 -0
- package/dist/config-provider/use-config.js +29 -0
- package/dist/config-provider/utils.js +29 -0
- package/dist/count-down/count-down.vue +98 -97
- package/dist/date-time-picker/date-time-picker.vue +410 -395
- package/dist/demo/demo.vue +1 -0
- package/dist/dialog/dialog.vue +175 -173
- package/dist/divider/divider.vue +38 -36
- package/dist/draggable/draggable.vue +60 -58
- package/dist/drawer/README.md +1 -1
- package/dist/drawer/drawer.vue +48 -46
- package/dist/dropdown-item/dropdown-item.vue +209 -207
- package/dist/dropdown-item/props.ts +4 -4
- package/dist/dropdown-item/type.ts +3 -3
- package/dist/dropdown-menu/dropdown-menu.vue +93 -99
- package/dist/empty/empty.vue +43 -42
- package/dist/fab/fab.vue +88 -86
- package/dist/footer/footer.vue +36 -34
- package/dist/form/README.en-US.md +17 -24
- package/dist/form/README.md +18 -25
- package/dist/form/form.css +1 -166
- package/dist/form/form.vue +251 -236
- package/dist/form/props.ts +2 -21
- package/dist/form/type.ts +7 -70
- package/dist/form-item/README.en-US.md +4 -5
- package/dist/form-item/README.md +4 -5
- package/dist/form-item/form-item.css +69 -96
- package/dist/form-item/form-item.vue +315 -336
- package/dist/form-item/form-model.ts +125 -173
- package/dist/form-item/props.ts +4 -17
- package/dist/form-item/type.ts +43 -1
- package/dist/grid/grid.vue +53 -51
- package/dist/grid-item/grid-item.vue +121 -119
- package/dist/guide/README.md +1 -1
- package/dist/guide/guide.vue +281 -277
- package/dist/icon/README.md +2 -4
- package/dist/icon/icon.vue +78 -76
- package/dist/image/README.md +1 -1
- package/dist/image/image.vue +103 -101
- package/dist/image-viewer/image-viewer.vue +160 -158
- package/dist/image-viewer/props.ts +2 -2
- package/dist/image-viewer/type.ts +1 -1
- package/dist/index.js +3 -0
- package/dist/indexes/indexes.vue +264 -267
- package/dist/indexes-anchor/indexes-anchor.vue +41 -41
- package/dist/input/input.vue +192 -192
- package/dist/input/props.ts +6 -6
- package/dist/input/type.ts +3 -3
- package/dist/link/link.vue +73 -71
- package/dist/loading/loading.vue +59 -59
- package/dist/locale/ar_KW.ts +157 -0
- package/dist/locale/en_US.ts +146 -0
- package/dist/locale/it_IT.ts +145 -0
- package/dist/locale/ja_JP.ts +132 -0
- package/dist/locale/ko_KR.ts +132 -0
- package/dist/locale/ru_RU.ts +157 -0
- package/dist/locale/zh_CN.ts +133 -0
- package/dist/locale/zh_TW.ts +132 -0
- package/dist/message/message.vue +181 -173
- package/dist/message/props.ts +2 -2
- package/dist/message/type.ts +1 -1
- package/dist/message-item/message-item.vue +192 -184
- package/dist/mixins/using-config.js +39 -0
- package/dist/navbar/navbar.vue +201 -199
- package/dist/notice-bar/notice-bar.vue +175 -171
- package/dist/notice-bar/props.ts +2 -2
- package/dist/notice-bar/type.ts +1 -1
- package/dist/npm/dayjs/esm/locale/ar.js +81 -0
- package/dist/npm/dayjs/esm/locale/it.js +39 -0
- package/dist/overlay/overlay.vue +50 -48
- package/dist/picker/picker.vue +168 -161
- package/dist/picker-item/picker-item.vue +269 -269
- package/dist/popover/README.md +1 -1
- package/dist/popover/popover.vue +262 -261
- package/dist/popover/props.ts +4 -4
- package/dist/popover/type.ts +2 -2
- package/dist/popup/popup.vue +46 -45
- package/dist/progress/README.md +1 -1
- package/dist/progress/progress.vue +76 -76
- package/dist/pull-down-refresh/props.ts +2 -2
- package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
- package/dist/pull-down-refresh/type.ts +1 -1
- package/dist/qrcode/README.md +1 -1
- package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
- package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
- package/dist/qrcode/qrcode.vue +93 -87
- package/dist/radio/props.ts +6 -6
- package/dist/radio/radio.vue +118 -120
- package/dist/radio/type.ts +3 -3
- package/dist/radio-group/props.ts +4 -4
- package/dist/radio-group/radio-group.vue +136 -134
- package/dist/radio-group/type.ts +4 -4
- package/dist/rate/computed.js +2 -2
- package/dist/rate/props.ts +4 -4
- package/dist/rate/rate.vue +155 -154
- package/dist/rate/type.ts +2 -2
- package/dist/result/result.vue +41 -39
- package/dist/row/row.vue +38 -36
- package/dist/scroll-view/scroll-view.vue +24 -22
- package/dist/search/props.ts +2 -2
- package/dist/search/search.vue +127 -125
- package/dist/search/type.ts +1 -1
- package/dist/side-bar/side-bar.vue +57 -55
- package/dist/side-bar-item/side-bar-item.vue +86 -86
- package/dist/skeleton/skeleton.vue +126 -124
- package/dist/slider/README.md +1 -1
- package/dist/slider/props.ts +2 -2
- package/dist/slider/slider.vue +457 -457
- package/dist/slider/type.ts +1 -1
- package/dist/step-item/step-item.vue +77 -75
- package/dist/stepper/props.ts +2 -2
- package/dist/stepper/stepper.vue +168 -149
- package/dist/stepper/type.ts +1 -1
- package/dist/steps/props.ts +2 -2
- package/dist/steps/steps.vue +83 -81
- package/dist/steps/type.ts +1 -1
- package/dist/sticky/sticky.vue +104 -102
- package/dist/swipe-cell/swipe-cell.vue +91 -89
- package/dist/swiper/README.md +1 -1
- package/dist/swiper/swiper.vue +91 -89
- package/dist/swiper-nav/swiper-nav.vue +38 -36
- package/dist/switch/props.ts +2 -2
- package/dist/switch/switch.vue +62 -62
- package/dist/switch/type.ts +1 -1
- package/dist/tab-bar/tab-bar.vue +88 -86
- package/dist/tab-bar-item/tab-bar-item.vue +85 -82
- package/dist/tab-panel/tab-panel.vue +66 -64
- package/dist/tabs/tabs.vue +294 -287
- package/dist/tag/tag.vue +79 -77
- package/dist/textarea/props.ts +6 -6
- package/dist/textarea/textarea.vue +127 -126
- package/dist/textarea/type.ts +3 -3
- package/dist/toast/toast.vue +107 -106
- package/dist/transition/transition.vue +30 -28
- package/dist/tree-select/tree-select.vue +151 -151
- package/dist/types/config-provider.d.ts +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/popover.d.ts +7 -0
- package/dist/upload/README.en-US.md +13 -14
- package/dist/upload/README.md +11 -12
- package/dist/upload/props.ts +2 -4
- package/dist/upload/type.ts +12 -11
- package/dist/upload/upload.css +1 -1
- package/dist/upload/upload.vue +672 -512
- package/dist/watermark/watermark.vue +151 -149
- package/global.d.ts +2 -0
- package/package.json +15 -3
- package/dist/form/form-item-props.ts +0 -56
|
@@ -1,198 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
interface ValidateResult {
|
|
3
|
-
result: boolean;
|
|
4
|
-
message?: string;
|
|
5
|
-
type?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// 工具函数:安全获取rule属性的实际值
|
|
9
|
-
function getRuleValue(field: any, key?: string): any {
|
|
10
|
-
if (field && typeof field === 'object' && 'type' in field) {
|
|
11
|
-
// 针对type字段,过滤掉'error'和'warning'
|
|
12
|
-
if (key === 'type') {
|
|
13
|
-
const { value } = field;
|
|
14
|
-
if (value === 'error' || value === 'warning') {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
return field.value;
|
|
20
|
-
}
|
|
21
|
-
// type字段只允许string
|
|
22
|
-
if (key === 'type') {
|
|
23
|
-
if (field === 'error' || field === 'warning') {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return field;
|
|
28
|
-
}
|
|
1
|
+
import { isNumber, isBoolean, isObject, isEmpty, isDate, isEmail, isURL } from '../common/validator';
|
|
29
2
|
|
|
30
|
-
// 验证状态枚举
|
|
31
3
|
export const ValidateStatus = {
|
|
32
4
|
TO_BE_VALIDATED: 0,
|
|
33
5
|
SUCCESS: 1,
|
|
34
6
|
FAIL: 2,
|
|
35
7
|
};
|
|
36
8
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// 如果值为空且不是必填,则跳过其他验证
|
|
53
|
-
if (value === undefined || value === null || value === '' || value.length === 0) {
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 列表最小值验证
|
|
58
|
-
const min = getRuleValue(rule.min);
|
|
59
|
-
if (min !== undefined) {
|
|
60
|
-
const val = Array.isArray(value) ? value.length : Number(value);
|
|
61
|
-
if (val < Number(min)) {
|
|
62
|
-
result.result = false;
|
|
63
|
-
result.message = getRuleValue(rule.message) || `不能小于 ${min}`;
|
|
64
|
-
result.type = 'error';
|
|
65
|
-
return result;
|
|
9
|
+
/**
|
|
10
|
+
* 计算字符串字符的长度并可以截取字符串。
|
|
11
|
+
* @param str 传入字符串
|
|
12
|
+
* @param maxCharacter 规定最大字符串长度
|
|
13
|
+
* @returns 当没有传入maxCharacter时返回字符串字符长度,当传入maxCharacter时返回截取之后的字符串和长度。
|
|
14
|
+
*/
|
|
15
|
+
function getCharacterLength(str: string, maxCharacter?: number) {
|
|
16
|
+
const hasMaxCharacter = isNumber(maxCharacter);
|
|
17
|
+
if (!str || str.length === 0) {
|
|
18
|
+
if (hasMaxCharacter) {
|
|
19
|
+
return {
|
|
20
|
+
length: 0,
|
|
21
|
+
characters: str,
|
|
22
|
+
};
|
|
66
23
|
}
|
|
24
|
+
return 0;
|
|
67
25
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
result.message = getRuleValue(rule.message) || `不能大于 ${max}`;
|
|
76
|
-
result.type = 'error';
|
|
77
|
-
return result;
|
|
26
|
+
let len = 0;
|
|
27
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
28
|
+
let currentStringLength = 0;
|
|
29
|
+
if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
|
|
30
|
+
currentStringLength = 2;
|
|
31
|
+
} else {
|
|
32
|
+
currentStringLength = 1;
|
|
78
33
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (len > Number(maxLength)) {
|
|
85
|
-
result.result = false;
|
|
86
|
-
result.message = getRuleValue(rule.message) || `长度不能超过 ${maxLength}`;
|
|
87
|
-
result.type = 'error';
|
|
88
|
-
return result;
|
|
34
|
+
if (hasMaxCharacter && len + currentStringLength > maxCharacter) {
|
|
35
|
+
return {
|
|
36
|
+
length: len,
|
|
37
|
+
characters: str.slice(0, i),
|
|
38
|
+
};
|
|
89
39
|
}
|
|
40
|
+
len += currentStringLength;
|
|
90
41
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (len < Number(minLength)) {
|
|
97
|
-
result.result = false;
|
|
98
|
-
result.message = getRuleValue(rule.message) || `长度不能少于 ${minLength}`;
|
|
99
|
-
result.type = 'error';
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
42
|
+
if (hasMaxCharacter) {
|
|
43
|
+
return {
|
|
44
|
+
length: len,
|
|
45
|
+
characters: str,
|
|
46
|
+
};
|
|
102
47
|
}
|
|
48
|
+
return len;
|
|
49
|
+
}
|
|
103
50
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return result;
|
|
113
|
-
}
|
|
51
|
+
// `{} / [] / '' / undefined / null` 等内容被认为是空; 0 和 false 被认为是正常数据,部分数据的值就是 0 或者 false
|
|
52
|
+
export function isValueEmpty(val: any): boolean {
|
|
53
|
+
const type: string = Object.prototype.toString.call(val);
|
|
54
|
+
const typeMap: Record<string, any> = {
|
|
55
|
+
Date: '[object Date]',
|
|
56
|
+
};
|
|
57
|
+
if (type === typeMap.Date) {
|
|
58
|
+
return false;
|
|
114
59
|
}
|
|
60
|
+
return isObject(val) ? isEmpty(val) : ['', undefined, null].includes(val);
|
|
61
|
+
}
|
|
115
62
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
63
|
+
const VALIDATE_MAP = {
|
|
64
|
+
date: isDate,
|
|
65
|
+
url: isURL,
|
|
66
|
+
email: isEmail,
|
|
67
|
+
required: (val: any): boolean => !isValueEmpty(val),
|
|
68
|
+
whitespace: (val: any): boolean => !(/^\s+$/.test(val) || val === ''),
|
|
69
|
+
boolean: (val: any): boolean => isBoolean(val),
|
|
70
|
+
max: (val: any, num: number): boolean => (isNumber(val) ? val <= num : (getCharacterLength(val) as number) <= num),
|
|
71
|
+
min: (val: any, num: number): boolean => (isNumber(val) ? val >= num : (getCharacterLength(val) as number) >= num),
|
|
72
|
+
len: (val: any, num: number): boolean => getCharacterLength(val) === num,
|
|
73
|
+
number: (val: any): boolean => isNumber(val),
|
|
74
|
+
enum: (val: any, strs: Array<string>): boolean => strs.includes(val),
|
|
75
|
+
idcard: (val: any): boolean => /^(\d{18,18}|\d{15,15}|\d{17,17}x)$/i.test(val),
|
|
76
|
+
telnumber: (val: any): boolean => /^1[3-9]\d{9}$/.test(val),
|
|
77
|
+
pattern: (val: any, regexp: RegExp | string): boolean => {
|
|
78
|
+
const reg = typeof regexp === 'string' ? new RegExp(regexp) : regexp;
|
|
79
|
+
return reg.test(val);
|
|
80
|
+
},
|
|
81
|
+
// 自定义校验规则,可能是异步校验
|
|
82
|
+
validator: (
|
|
83
|
+
val: any,
|
|
84
|
+
validate: Function,
|
|
85
|
+
context?: { formData: any; name: string },
|
|
86
|
+
): any => validate(val, context),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 校验某一条数据的某一条规则,一种校验规则不满足则不再进行校验。
|
|
91
|
+
* @param value 值
|
|
92
|
+
* @param rule 校验规则
|
|
93
|
+
* @param context 表单上下文,包含 formData 和 name,供自定义校验器使用
|
|
94
|
+
* @returns 两种校验结果,一种是内置校验规则的校验结果,二种是自定义校验规则(validator)的校验结果
|
|
95
|
+
*/
|
|
96
|
+
export async function validateOneRule(
|
|
97
|
+
value: any,
|
|
98
|
+
rule: any,
|
|
99
|
+
context?: { formData: any; name: string },
|
|
100
|
+
): Promise<any> {
|
|
101
|
+
let validateResult: any = { result: true };
|
|
102
|
+
const keys = Object.keys(rule);
|
|
103
|
+
let vOptions: any;
|
|
104
|
+
let vValidateFun: any;
|
|
105
|
+
let isValidatorRule = false;
|
|
106
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
107
|
+
const key = keys[i];
|
|
108
|
+
// 非必填选项,值为空,非自定义规则:无需校验,直接返回 true
|
|
109
|
+
if (!rule.required && isValueEmpty(value) && !rule.validator) {
|
|
110
|
+
return validateResult;
|
|
131
111
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
112
|
+
const validateRule = (VALIDATE_MAP as any)[key];
|
|
113
|
+
const ruleItem = rule[key];
|
|
114
|
+
// 找到一个校验规则,则无需再找,因为参数只允许对一个规则进行校验
|
|
115
|
+
if (validateRule && (ruleItem || ruleItem === 0)) {
|
|
116
|
+
// rule 值为 true 则表示没有校验参数,只是对值进行默认规则校验
|
|
117
|
+
vOptions = ruleItem === true ? undefined : ruleItem;
|
|
118
|
+
vValidateFun = validateRule;
|
|
119
|
+
isValidatorRule = key === 'validator';
|
|
120
|
+
break;
|
|
137
121
|
}
|
|
138
122
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
if (!isValid) {
|
|
147
|
-
result.result = false;
|
|
148
|
-
result.message = getRuleValue(rule.message) || `${type} 格式不正确`;
|
|
149
|
-
result.type = 'error';
|
|
150
|
-
return result;
|
|
151
|
-
}
|
|
152
|
-
} else if (type === 'url') {
|
|
153
|
-
try {
|
|
154
|
-
const url = new URL(String(value));
|
|
155
|
-
isValid = !!url;
|
|
156
|
-
} catch (err) {
|
|
157
|
-
isValid = false;
|
|
158
|
-
}
|
|
159
|
-
if (!isValid) {
|
|
160
|
-
result.result = false;
|
|
161
|
-
result.message = getRuleValue(rule.message) || `${type} 格式不正确`;
|
|
162
|
-
result.type = 'error';
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
} else if (type === 'number') {
|
|
166
|
-
isValid = !Number.isNaN(Number(value));
|
|
167
|
-
if (!isValid) {
|
|
168
|
-
result.result = false;
|
|
169
|
-
result.message = getRuleValue(rule.message) || `${type} 格式不正确`;
|
|
170
|
-
result.type = 'error';
|
|
171
|
-
return result;
|
|
172
|
-
}
|
|
123
|
+
if (vValidateFun) {
|
|
124
|
+
validateResult = isValidatorRule
|
|
125
|
+
? await vValidateFun(value, vOptions, context)
|
|
126
|
+
: await vValidateFun(value, vOptions);
|
|
127
|
+
// 如果校验不通过,则返回校验不通过的规则
|
|
128
|
+
if (isBoolean(validateResult)) {
|
|
129
|
+
return { ...rule, result: validateResult };
|
|
173
130
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (validator) {
|
|
178
|
-
const validateResult = await validator(value);
|
|
179
|
-
if (!validateResult) {
|
|
180
|
-
result.result = false;
|
|
181
|
-
result.message = getRuleValue(rule.message) || '验证失败';
|
|
182
|
-
result.type = 'error';
|
|
183
|
-
return result;
|
|
131
|
+
// 校验结果为对象,只有自定义校验规则会存在这种情况
|
|
132
|
+
if (isObject(validateResult)) {
|
|
133
|
+
return validateResult;
|
|
184
134
|
}
|
|
185
135
|
}
|
|
186
|
-
return
|
|
136
|
+
return validateResult;
|
|
187
137
|
}
|
|
188
138
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return results;
|
|
139
|
+
/**
|
|
140
|
+
* 单个数据进行全规则校验
|
|
141
|
+
* 保留 validateRules 别名以兼容已有调用
|
|
142
|
+
*/
|
|
143
|
+
export async function validate(value: any, rules: any[], context?: { formData: any; name: string }): Promise<any[]> {
|
|
144
|
+
const all = rules.map(rule => validateOneRule(value, rule, context));
|
|
145
|
+
const r = await Promise.all(all);
|
|
146
|
+
return r;
|
|
198
147
|
}
|
|
148
|
+
|
|
149
|
+
// 兼容已有导入
|
|
150
|
+
export const validateRules = validate;
|
package/dist/form-item/props.ts
CHANGED
|
@@ -8,19 +8,6 @@ import type { TdFormItemProps } from './type';
|
|
|
8
8
|
export default {
|
|
9
9
|
/** 是否显示右侧箭头 */
|
|
10
10
|
arrow: Boolean,
|
|
11
|
-
/** 表单内容对齐方式,优先级高于 Form.contentAlign */
|
|
12
|
-
contentAlign: {
|
|
13
|
-
type: String,
|
|
14
|
-
validator(val: TdFormItemProps['contentAlign']): boolean {
|
|
15
|
-
if (!val) return true;
|
|
16
|
-
return ['left', 'right'].includes(val);
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
/** label 原生属性 */
|
|
20
|
-
for: {
|
|
21
|
-
type: String,
|
|
22
|
-
default: '',
|
|
23
|
-
},
|
|
24
11
|
/** 表单项说明内容 */
|
|
25
12
|
help: {
|
|
26
13
|
type: String,
|
|
@@ -49,8 +36,8 @@ export default {
|
|
|
49
36
|
},
|
|
50
37
|
/** 是否显示必填符号(*),优先级高于 Form.requiredMark */
|
|
51
38
|
requiredMark: {
|
|
52
|
-
type: Boolean,
|
|
53
|
-
default:
|
|
39
|
+
type: [Boolean, null],
|
|
40
|
+
default: null as TdFormItemProps['requiredMark'],
|
|
54
41
|
},
|
|
55
42
|
/** 表单字段校验规则 */
|
|
56
43
|
rules: {
|
|
@@ -58,7 +45,7 @@ export default {
|
|
|
58
45
|
},
|
|
59
46
|
/** 校验不通过时,是否显示错误提示信息,优先级高于 `Form.showErrorMessage` */
|
|
60
47
|
showErrorMessage: {
|
|
61
|
-
type: Boolean,
|
|
62
|
-
default:
|
|
48
|
+
type: [Boolean, null],
|
|
49
|
+
default: null as TdFormItemProps['showErrorMessage'],
|
|
63
50
|
},
|
|
64
51
|
};
|
package/dist/form-item/type.ts
CHANGED
|
@@ -4,4 +4,46 @@
|
|
|
4
4
|
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
|
|
5
5
|
* */
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import type { FormRule } from '../form/type';
|
|
8
|
+
|
|
9
|
+
export interface TdFormItemProps {
|
|
10
|
+
/**
|
|
11
|
+
* 是否显示右侧箭头
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
arrow?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 表单项说明内容
|
|
17
|
+
*/
|
|
18
|
+
help?: string;
|
|
19
|
+
/**
|
|
20
|
+
* 字段标签名称
|
|
21
|
+
* @default ''
|
|
22
|
+
*/
|
|
23
|
+
label?: string;
|
|
24
|
+
/**
|
|
25
|
+
* 表单字段标签对齐方式:左对齐、右对齐、顶部对齐。默认使用 Form 的对齐方式,优先级高于 Form.labelAlign
|
|
26
|
+
*/
|
|
27
|
+
labelAlign?: 'left' | 'right' | 'top';
|
|
28
|
+
/**
|
|
29
|
+
* 可以整体设置标签宽度,优先级高于 Form.labelWidth
|
|
30
|
+
*/
|
|
31
|
+
labelWidth?: string | number;
|
|
32
|
+
/**
|
|
33
|
+
* 表单字段名称
|
|
34
|
+
* @default ''
|
|
35
|
+
*/
|
|
36
|
+
name?: string;
|
|
37
|
+
/**
|
|
38
|
+
* 是否显示必填符号(*),优先级高于 Form.requiredMark
|
|
39
|
+
*/
|
|
40
|
+
requiredMark?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* 表单字段校验规则
|
|
43
|
+
*/
|
|
44
|
+
rules?: Array<FormRule>;
|
|
45
|
+
/**
|
|
46
|
+
* 校验不通过时,是否显示错误提示信息,优先级高于 `Form.showErrorMessage`
|
|
47
|
+
*/
|
|
48
|
+
showErrorMessage?: boolean;
|
|
49
|
+
}
|
package/dist/grid/grid.vue
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view
|
|
3
|
-
:style="tools._style([customStyle])"
|
|
4
|
-
:class="tools.cls(classPrefix, [theme]) + ' ' + tClass"
|
|
3
|
+
:style="'' + tools._style([customStyle])"
|
|
4
|
+
:class="'' + tools.cls(classPrefix, [theme]) + ' ' + tClass"
|
|
5
5
|
>
|
|
6
6
|
<view
|
|
7
7
|
v-if="column > 0"
|
|
@@ -33,60 +33,62 @@ import { ParentMixin, RELATION_MAP } from '../common/relation';
|
|
|
33
33
|
const name = `${prefix}-grid`;
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
export default
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
data() {
|
|
47
|
-
return {
|
|
48
|
-
prefix,
|
|
49
|
-
classPrefix: name,
|
|
50
|
-
contentStyle: '',
|
|
51
|
-
tools,
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
watch: {
|
|
55
|
-
column: 'watchCallback',
|
|
56
|
-
hover: 'watchCallback',
|
|
57
|
-
align: 'watchCallback',
|
|
58
|
-
gutter: 'watchCallback',
|
|
59
|
-
border: 'watchCallback',
|
|
60
|
-
},
|
|
61
|
-
mounted() {
|
|
62
|
-
this.updateContentStyle();
|
|
63
|
-
},
|
|
64
|
-
methods: {
|
|
65
|
-
watchCallback() {
|
|
66
|
-
this.updateContentStyle();
|
|
67
|
-
this.doForChild(t => t.updateStyle?.());
|
|
36
|
+
export default {
|
|
37
|
+
...uniComponent({
|
|
38
|
+
name,
|
|
39
|
+
options: {
|
|
40
|
+
styleIsolation: 'shared',
|
|
41
|
+
},
|
|
42
|
+
externalClasses: ['t-class'],
|
|
43
|
+
mixins: [ParentMixin(RELATION_MAP.GridItem)],
|
|
44
|
+
props: {
|
|
45
|
+
...props,
|
|
68
46
|
},
|
|
69
|
-
|
|
70
|
-
|
|
47
|
+
data() {
|
|
48
|
+
return {
|
|
49
|
+
prefix,
|
|
50
|
+
classPrefix: name,
|
|
51
|
+
contentStyle: '',
|
|
52
|
+
tools,
|
|
53
|
+
};
|
|
71
54
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
55
|
+
watch: {
|
|
56
|
+
column: 'watchCallback',
|
|
57
|
+
hover: 'watchCallback',
|
|
58
|
+
align: 'watchCallback',
|
|
59
|
+
gutter: 'watchCallback',
|
|
60
|
+
border: 'watchCallback',
|
|
61
|
+
},
|
|
62
|
+
mounted() {
|
|
63
|
+
this.updateContentStyle();
|
|
77
64
|
},
|
|
65
|
+
methods: {
|
|
66
|
+
watchCallback() {
|
|
67
|
+
this.updateContentStyle();
|
|
68
|
+
this.doForChild(t => t.updateStyle?.());
|
|
69
|
+
},
|
|
70
|
+
doForChild(action) {
|
|
71
|
+
this.children?.forEach(action);
|
|
72
|
+
},
|
|
73
|
+
updateContentStyle() {
|
|
74
|
+
const contentStyles = [];
|
|
75
|
+
const marginStyle = this.getContentMargin();
|
|
76
|
+
marginStyle && contentStyles.push(marginStyle);
|
|
77
|
+
this.contentStyle = contentStyles.join(';');
|
|
78
|
+
},
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
// 判断需不需要在content上加负margin以实现gutter间距
|
|
81
|
+
getContentMargin() {
|
|
82
|
+
const { gutter } = this;
|
|
83
|
+
let { border } = this;
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
if (!border) return `margin-bottom:-${gutter}rpx; margin-right:-${gutter}rpx`;
|
|
86
|
+
if (!isObject(border)) border = {} ;
|
|
87
|
+
const { width = 2 } = border ;
|
|
88
|
+
return `margin-bottom:-${width}rpx; margin-right:-${width}rpx`;
|
|
89
|
+
},
|
|
88
90
|
},
|
|
89
|
-
},
|
|
90
|
-
}
|
|
91
|
+
}),
|
|
92
|
+
};
|
|
91
93
|
</script>
|
|
92
94
|
<style scoped src="./grid.css"></style>
|