@tmagic/form 1.8.0-beta.17 → 1.8.0-beta.19
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/es/Form.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/es/FormBox.vue_vue_type_script_setup_true_lang.js +7 -1
- package/dist/es/FormDialog.vue_vue_type_script_setup_true_lang.js +6 -0
- package/dist/es/FormDrawer.vue_vue_type_script_setup_true_lang.js +6 -0
- package/dist/es/utils/form.js +4 -3
- package/dist/es/utils/typeMatch.js +98 -21
- package/dist/tmagic-form.umd.cjs +126 -26
- package/package.json +4 -4
- package/src/Form.vue +13 -3
- package/src/FormBox.vue +4 -0
- package/src/FormDialog.vue +4 -0
- package/src/FormDrawer.vue +4 -0
- package/src/utils/form.ts +7 -4
- package/src/utils/typeMatch.ts +135 -31
- package/types/index.d.ts +65 -12
|
@@ -21,6 +21,10 @@ var Form_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
21
21
|
parentValues: { default: () => ({}) },
|
|
22
22
|
labelWidth: { default: "200px" },
|
|
23
23
|
typeMatchValid: { type: Boolean },
|
|
24
|
+
validateOnInit: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: false
|
|
27
|
+
},
|
|
24
28
|
disabled: {
|
|
25
29
|
type: Boolean,
|
|
26
30
|
default: false
|
|
@@ -218,7 +222,7 @@ var Form_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
218
222
|
}).then((value) => {
|
|
219
223
|
values.value = value;
|
|
220
224
|
initialized.value = !props.isCompare;
|
|
221
|
-
nextTick(() => {
|
|
225
|
+
if (props.validateOnInit) nextTick(() => {
|
|
222
226
|
tMagicFormRef.value?.validate();
|
|
223
227
|
});
|
|
224
228
|
});
|
|
@@ -14,6 +14,10 @@ var FormBox_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
14
14
|
height: {},
|
|
15
15
|
labelWidth: {},
|
|
16
16
|
typeMatchValid: { type: Boolean },
|
|
17
|
+
validateOnInit: {
|
|
18
|
+
type: Boolean,
|
|
19
|
+
default: false
|
|
20
|
+
},
|
|
17
21
|
disabled: { type: Boolean },
|
|
18
22
|
size: {},
|
|
19
23
|
confirmText: { default: "确定" },
|
|
@@ -90,6 +94,7 @@ var FormBox_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
90
94
|
"use-field-text-in-error": __props.useFieldTextInError,
|
|
91
95
|
"extend-state": __props.extendState,
|
|
92
96
|
"type-match-valid": __props.typeMatchValid,
|
|
97
|
+
"validate-on-init": __props.validateOnInit,
|
|
93
98
|
onChange: changeHandler
|
|
94
99
|
}, null, 8, [
|
|
95
100
|
"size",
|
|
@@ -103,7 +108,8 @@ var FormBox_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
103
108
|
"prevent-submit-default",
|
|
104
109
|
"use-field-text-in-error",
|
|
105
110
|
"extend-state",
|
|
106
|
-
"type-match-valid"
|
|
111
|
+
"type-match-valid",
|
|
112
|
+
"validate-on-init"
|
|
107
113
|
]), renderSlot(_ctx.$slots, "default")]),
|
|
108
114
|
_: 3
|
|
109
115
|
})], 4), createElementVNode("div", {
|
|
@@ -13,6 +13,10 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
13
13
|
width: {},
|
|
14
14
|
labelWidth: {},
|
|
15
15
|
typeMatchValid: { type: Boolean },
|
|
16
|
+
validateOnInit: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
default: false
|
|
19
|
+
},
|
|
16
20
|
fullscreen: { type: Boolean },
|
|
17
21
|
disabled: { type: Boolean },
|
|
18
22
|
title: {},
|
|
@@ -203,6 +207,7 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
203
207
|
"prevent-submit-default": __props.preventSubmitDefault,
|
|
204
208
|
"use-field-text-in-error": __props.useFieldTextInError,
|
|
205
209
|
"type-match-valid": __props.typeMatchValid,
|
|
210
|
+
"validate-on-init": __props.validateOnInit,
|
|
206
211
|
"extend-state": __props.extendState,
|
|
207
212
|
theme: effectiveTheme.value,
|
|
208
213
|
onChange: changeHandler
|
|
@@ -219,6 +224,7 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
219
224
|
"prevent-submit-default",
|
|
220
225
|
"use-field-text-in-error",
|
|
221
226
|
"type-match-valid",
|
|
227
|
+
"validate-on-init",
|
|
222
228
|
"extend-state",
|
|
223
229
|
"theme"
|
|
224
230
|
]), renderSlot(_ctx.$slots, "default")], 4)) : createCommentVNode("v-if", true)]),
|
|
@@ -13,6 +13,10 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
13
13
|
width: {},
|
|
14
14
|
labelWidth: {},
|
|
15
15
|
typeMatchValid: { type: Boolean },
|
|
16
|
+
validateOnInit: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
default: false
|
|
19
|
+
},
|
|
16
20
|
disabled: { type: Boolean },
|
|
17
21
|
closeOnPressEscape: {
|
|
18
22
|
type: Boolean,
|
|
@@ -180,6 +184,7 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
180
184
|
"prevent-submit-default": __props.preventSubmitDefault,
|
|
181
185
|
"use-field-text-in-error": __props.useFieldTextInError,
|
|
182
186
|
"type-match-valid": __props.typeMatchValid,
|
|
187
|
+
"validate-on-init": __props.validateOnInit,
|
|
183
188
|
"extend-state": __props.extendState,
|
|
184
189
|
theme: effectiveTheme.value,
|
|
185
190
|
onChange: changeHandler
|
|
@@ -195,6 +200,7 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
195
200
|
"prevent-submit-default",
|
|
196
201
|
"use-field-text-in-error",
|
|
197
202
|
"type-match-valid",
|
|
203
|
+
"validate-on-init",
|
|
198
204
|
"extend-state",
|
|
199
205
|
"theme"
|
|
200
206
|
]), renderSlot(_ctx.$slots, "default")], 512)) : createCommentVNode("v-if", true)]),
|
package/dist/es/utils/form.js
CHANGED
|
@@ -20,15 +20,16 @@ var adaptFormValidator = (validator) => {
|
|
|
20
20
|
const callback = (error) => {
|
|
21
21
|
if (settled) return;
|
|
22
22
|
settled = true;
|
|
23
|
-
|
|
23
|
+
const first = Array.isArray(error) ? error[0] : error;
|
|
24
|
+
if (first) resolve({
|
|
24
25
|
result: false,
|
|
25
|
-
message: typeof
|
|
26
|
+
message: typeof first === "string" ? first : first.message
|
|
26
27
|
});
|
|
27
28
|
else resolve(true);
|
|
28
29
|
};
|
|
29
30
|
try {
|
|
30
31
|
const result = validator(void 0, value, callback);
|
|
31
|
-
if (result
|
|
32
|
+
if (result && typeof result.then === "function") Promise.resolve(result).then(() => {
|
|
32
33
|
if (!settled) callback();
|
|
33
34
|
}, (err) => {
|
|
34
35
|
callback(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -361,6 +361,11 @@ var validateBuiltinTypeMatch = (value, fieldType, mForm, props, message) => {
|
|
|
361
361
|
return;
|
|
362
362
|
}
|
|
363
363
|
};
|
|
364
|
+
/**
|
|
365
|
+
* 校验取值与字段 type 是否匹配;通过返回 undefined,否则返回错误文案。
|
|
366
|
+
*
|
|
367
|
+
* 命中的自定义规则是异步校验器时返回 Promise,内置规则始终同步返回。
|
|
368
|
+
*/
|
|
364
369
|
var validateTypeMatch = (value, mForm, props, message) => {
|
|
365
370
|
if (isEmptyValue(value) || isEmptyArray(value)) return;
|
|
366
371
|
if (!props.config?.name) return;
|
|
@@ -376,34 +381,106 @@ var validateTypeMatch = (value, mForm, props, message) => {
|
|
|
376
381
|
});
|
|
377
382
|
return validateBuiltinTypeMatch(value, fieldType, mForm, props, message);
|
|
378
383
|
};
|
|
384
|
+
var toError = (error) => error instanceof Error ? error : /* @__PURE__ */ new Error(`${error}`);
|
|
379
385
|
var createTypeMatchValidator = (mForm, props, rule) => {
|
|
380
386
|
const originalValidator = typeof rule.validator === "function" ? rule.validator : void 0;
|
|
387
|
+
/**
|
|
388
|
+
* 每次校验取一个自增序号,只有最新一轮的结论会被采用。
|
|
389
|
+
*
|
|
390
|
+
* 旧值的在途校验不能用自己的结论结算:它可能晚于新校验结束,用过期结论覆盖新结论
|
|
391
|
+
* (表单取最后结束的那次结果);也不能在新校验开始时无条件按通过结算,否则
|
|
392
|
+
* `form.validate()` 会对一个还没校验过的值返回成功。因此所有尚未结算的调用都登记在
|
|
393
|
+
* pendingSettlers 中,等最新一轮出结论后用同一个结论一起结算。
|
|
394
|
+
*
|
|
395
|
+
* 不比较取值本身:配了 names 或取值为对象/数组时拿到的是同一个引用,就地修改后比较不出变化。
|
|
396
|
+
*/
|
|
397
|
+
let generation = 0;
|
|
398
|
+
let pendingSettlers = [];
|
|
381
399
|
return (asyncValidatorRule, value, callback, source, options) => {
|
|
382
400
|
const actualValue = props.config?.names ? props.model : value;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
401
|
+
generation += 1;
|
|
402
|
+
const currentGeneration = generation;
|
|
403
|
+
/** 已有更新的一轮校验开始,本轮结论作废 */
|
|
404
|
+
const isStale = () => currentGeneration !== generation;
|
|
405
|
+
pendingSettlers.push((args) => callback(...args));
|
|
406
|
+
/**
|
|
407
|
+
* 结算本轮与被本轮取代的所有在途校验。
|
|
408
|
+
*
|
|
409
|
+
* async-validator 的 callback 不幂等:重复调用会让它的内部计数提前满足、错误信息重复;
|
|
410
|
+
* 原始 validator 写成 async 时很容易既调 callback 又返回 Promise,故所有回调都收敛到这里,
|
|
411
|
+
* 由「取出即出队」保证每个调用的 callback 只会被调用一次。
|
|
412
|
+
*/
|
|
413
|
+
const conclude = (...args) => {
|
|
414
|
+
if (isStale()) return;
|
|
415
|
+
const settlers = pendingSettlers;
|
|
416
|
+
pendingSettlers = [];
|
|
417
|
+
for (const settle of settlers) settle(args);
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* 执行原始 validator 并把结果统一转成 callback。
|
|
421
|
+
*
|
|
422
|
+
* async-validator 只解析同步返回给它的返回值(true / false / Error / 错误数组 / Promise,
|
|
423
|
+
* 抛错转成错误信息),异步路径已脱离它的调用栈,这些约定会失效导致校验永不结束,故复刻一份。
|
|
424
|
+
*/
|
|
425
|
+
const settleWithOriginalValidator = () => {
|
|
426
|
+
if (isStale()) return;
|
|
427
|
+
if (!originalValidator) {
|
|
428
|
+
conclude();
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
let result;
|
|
432
|
+
try {
|
|
433
|
+
result = originalValidator({
|
|
434
|
+
rule: asyncValidatorRule,
|
|
435
|
+
value: actualValue,
|
|
436
|
+
callback: conclude,
|
|
437
|
+
source,
|
|
438
|
+
options
|
|
439
|
+
}, {
|
|
440
|
+
values: mForm?.initValues || {},
|
|
441
|
+
model: props.model,
|
|
442
|
+
parent: mForm?.parentValues || {},
|
|
443
|
+
formValue: mForm?.values || props.model,
|
|
444
|
+
prop: props.prop,
|
|
445
|
+
config: props.config
|
|
446
|
+
}, mForm);
|
|
447
|
+
} catch (err) {
|
|
448
|
+
conclude(toError(err));
|
|
387
449
|
return;
|
|
388
450
|
}
|
|
389
|
-
|
|
390
|
-
|
|
451
|
+
if (isPromise(result)) result.then(() => conclude(), (err) => conclude(toError(err)));
|
|
452
|
+
else if (result === true) conclude();
|
|
453
|
+
else if (result === false) {
|
|
454
|
+
const field = asyncValidatorRule?.fullField || asyncValidatorRule?.field || props.prop;
|
|
455
|
+
conclude(new Error(rule.message || `${field} fails`));
|
|
456
|
+
} else if (result instanceof Error || Array.isArray(result)) conclude(result);
|
|
457
|
+
};
|
|
458
|
+
const skipFailedTypeMatch = (err) => {
|
|
459
|
+
console.error(err);
|
|
460
|
+
settleWithOriginalValidator();
|
|
461
|
+
};
|
|
462
|
+
let error;
|
|
463
|
+
try {
|
|
464
|
+
error = validateTypeMatch(actualValue, mForm, props, rule.message);
|
|
465
|
+
} catch (err) {
|
|
466
|
+
skipFailedTypeMatch(err);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (isPromise(error)) {
|
|
470
|
+
error.then((asyncMessage) => {
|
|
471
|
+
if (asyncMessage) {
|
|
472
|
+
conclude(new Error(asyncMessage));
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
settleWithOriginalValidator();
|
|
476
|
+
}, skipFailedTypeMatch);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (error) {
|
|
480
|
+
conclude(new Error(error));
|
|
481
|
+
return;
|
|
391
482
|
}
|
|
392
|
-
|
|
393
|
-
rule: asyncValidatorRule,
|
|
394
|
-
value: actualValue,
|
|
395
|
-
callback,
|
|
396
|
-
source,
|
|
397
|
-
options
|
|
398
|
-
}, {
|
|
399
|
-
values: mForm?.initValues || {},
|
|
400
|
-
model: props.model,
|
|
401
|
-
parent: mForm?.parentValues || {},
|
|
402
|
-
formValue: mForm?.values || props.model,
|
|
403
|
-
prop: props.prop,
|
|
404
|
-
config: props.config
|
|
405
|
-
}, mForm);
|
|
406
|
-
callback();
|
|
483
|
+
settleWithOriginalValidator();
|
|
407
484
|
};
|
|
408
485
|
};
|
|
409
486
|
//#endregion
|
package/dist/tmagic-form.umd.cjs
CHANGED
|
@@ -3088,6 +3088,11 @@
|
|
|
3088
3088
|
return;
|
|
3089
3089
|
}
|
|
3090
3090
|
};
|
|
3091
|
+
/**
|
|
3092
|
+
* 校验取值与字段 type 是否匹配;通过返回 undefined,否则返回错误文案。
|
|
3093
|
+
*
|
|
3094
|
+
* 命中的自定义规则是异步校验器时返回 Promise,内置规则始终同步返回。
|
|
3095
|
+
*/
|
|
3091
3096
|
var validateTypeMatch = (value, mForm, props, message) => {
|
|
3092
3097
|
if (isEmptyValue(value) || isEmptyArray(value)) return;
|
|
3093
3098
|
if (!props.config?.name) return;
|
|
@@ -3103,34 +3108,106 @@
|
|
|
3103
3108
|
});
|
|
3104
3109
|
return validateBuiltinTypeMatch(value, fieldType, mForm, props, message);
|
|
3105
3110
|
};
|
|
3111
|
+
var toError = (error) => error instanceof Error ? error : /* @__PURE__ */ new Error(`${error}`);
|
|
3106
3112
|
var createTypeMatchValidator = (mForm, props, rule) => {
|
|
3107
3113
|
const originalValidator = typeof rule.validator === "function" ? rule.validator : void 0;
|
|
3114
|
+
/**
|
|
3115
|
+
* 每次校验取一个自增序号,只有最新一轮的结论会被采用。
|
|
3116
|
+
*
|
|
3117
|
+
* 旧值的在途校验不能用自己的结论结算:它可能晚于新校验结束,用过期结论覆盖新结论
|
|
3118
|
+
* (表单取最后结束的那次结果);也不能在新校验开始时无条件按通过结算,否则
|
|
3119
|
+
* `form.validate()` 会对一个还没校验过的值返回成功。因此所有尚未结算的调用都登记在
|
|
3120
|
+
* pendingSettlers 中,等最新一轮出结论后用同一个结论一起结算。
|
|
3121
|
+
*
|
|
3122
|
+
* 不比较取值本身:配了 names 或取值为对象/数组时拿到的是同一个引用,就地修改后比较不出变化。
|
|
3123
|
+
*/
|
|
3124
|
+
let generation = 0;
|
|
3125
|
+
let pendingSettlers = [];
|
|
3108
3126
|
return (asyncValidatorRule, value, callback, source, options) => {
|
|
3109
3127
|
const actualValue = props.config?.names ? props.model : value;
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3128
|
+
generation += 1;
|
|
3129
|
+
const currentGeneration = generation;
|
|
3130
|
+
/** 已有更新的一轮校验开始,本轮结论作废 */
|
|
3131
|
+
const isStale = () => currentGeneration !== generation;
|
|
3132
|
+
pendingSettlers.push((args) => callback(...args));
|
|
3133
|
+
/**
|
|
3134
|
+
* 结算本轮与被本轮取代的所有在途校验。
|
|
3135
|
+
*
|
|
3136
|
+
* async-validator 的 callback 不幂等:重复调用会让它的内部计数提前满足、错误信息重复;
|
|
3137
|
+
* 原始 validator 写成 async 时很容易既调 callback 又返回 Promise,故所有回调都收敛到这里,
|
|
3138
|
+
* 由「取出即出队」保证每个调用的 callback 只会被调用一次。
|
|
3139
|
+
*/
|
|
3140
|
+
const conclude = (...args) => {
|
|
3141
|
+
if (isStale()) return;
|
|
3142
|
+
const settlers = pendingSettlers;
|
|
3143
|
+
pendingSettlers = [];
|
|
3144
|
+
for (const settle of settlers) settle(args);
|
|
3145
|
+
};
|
|
3146
|
+
/**
|
|
3147
|
+
* 执行原始 validator 并把结果统一转成 callback。
|
|
3148
|
+
*
|
|
3149
|
+
* async-validator 只解析同步返回给它的返回值(true / false / Error / 错误数组 / Promise,
|
|
3150
|
+
* 抛错转成错误信息),异步路径已脱离它的调用栈,这些约定会失效导致校验永不结束,故复刻一份。
|
|
3151
|
+
*/
|
|
3152
|
+
const settleWithOriginalValidator = () => {
|
|
3153
|
+
if (isStale()) return;
|
|
3154
|
+
if (!originalValidator) {
|
|
3155
|
+
conclude();
|
|
3114
3156
|
return;
|
|
3115
3157
|
}
|
|
3116
|
-
|
|
3117
|
-
|
|
3158
|
+
let result;
|
|
3159
|
+
try {
|
|
3160
|
+
result = originalValidator({
|
|
3161
|
+
rule: asyncValidatorRule,
|
|
3162
|
+
value: actualValue,
|
|
3163
|
+
callback: conclude,
|
|
3164
|
+
source,
|
|
3165
|
+
options
|
|
3166
|
+
}, {
|
|
3167
|
+
values: mForm?.initValues || {},
|
|
3168
|
+
model: props.model,
|
|
3169
|
+
parent: mForm?.parentValues || {},
|
|
3170
|
+
formValue: mForm?.values || props.model,
|
|
3171
|
+
prop: props.prop,
|
|
3172
|
+
config: props.config
|
|
3173
|
+
}, mForm);
|
|
3174
|
+
} catch (err) {
|
|
3175
|
+
conclude(toError(err));
|
|
3176
|
+
return;
|
|
3177
|
+
}
|
|
3178
|
+
if (isPromise(result)) result.then(() => conclude(), (err) => conclude(toError(err)));
|
|
3179
|
+
else if (result === true) conclude();
|
|
3180
|
+
else if (result === false) {
|
|
3181
|
+
const field = asyncValidatorRule?.fullField || asyncValidatorRule?.field || props.prop;
|
|
3182
|
+
conclude(new Error(rule.message || `${field} fails`));
|
|
3183
|
+
} else if (result instanceof Error || Array.isArray(result)) conclude(result);
|
|
3184
|
+
};
|
|
3185
|
+
const skipFailedTypeMatch = (err) => {
|
|
3186
|
+
console.error(err);
|
|
3187
|
+
settleWithOriginalValidator();
|
|
3188
|
+
};
|
|
3189
|
+
let error;
|
|
3190
|
+
try {
|
|
3191
|
+
error = validateTypeMatch(actualValue, mForm, props, rule.message);
|
|
3192
|
+
} catch (err) {
|
|
3193
|
+
skipFailedTypeMatch(err);
|
|
3194
|
+
return;
|
|
3118
3195
|
}
|
|
3119
|
-
if (
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
}
|
|
3133
|
-
|
|
3196
|
+
if (isPromise(error)) {
|
|
3197
|
+
error.then((asyncMessage) => {
|
|
3198
|
+
if (asyncMessage) {
|
|
3199
|
+
conclude(new Error(asyncMessage));
|
|
3200
|
+
return;
|
|
3201
|
+
}
|
|
3202
|
+
settleWithOriginalValidator();
|
|
3203
|
+
}, skipFailedTypeMatch);
|
|
3204
|
+
return;
|
|
3205
|
+
}
|
|
3206
|
+
if (error) {
|
|
3207
|
+
conclude(new Error(error));
|
|
3208
|
+
return;
|
|
3209
|
+
}
|
|
3210
|
+
settleWithOriginalValidator();
|
|
3134
3211
|
};
|
|
3135
3212
|
};
|
|
3136
3213
|
//#endregion
|
|
@@ -3149,15 +3226,16 @@
|
|
|
3149
3226
|
const callback = (error) => {
|
|
3150
3227
|
if (settled) return;
|
|
3151
3228
|
settled = true;
|
|
3152
|
-
|
|
3229
|
+
const first = Array.isArray(error) ? error[0] : error;
|
|
3230
|
+
if (first) resolve({
|
|
3153
3231
|
result: false,
|
|
3154
|
-
message: typeof
|
|
3232
|
+
message: typeof first === "string" ? first : first.message
|
|
3155
3233
|
});
|
|
3156
3234
|
else resolve(true);
|
|
3157
3235
|
};
|
|
3158
3236
|
try {
|
|
3159
3237
|
const result = validator(void 0, value, callback);
|
|
3160
|
-
if (result
|
|
3238
|
+
if (result && typeof result.then === "function") Promise.resolve(result).then(() => {
|
|
3161
3239
|
if (!settled) callback();
|
|
3162
3240
|
}, (err) => {
|
|
3163
3241
|
callback(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -4047,6 +4125,10 @@
|
|
|
4047
4125
|
parentValues: { default: () => ({}) },
|
|
4048
4126
|
labelWidth: { default: "200px" },
|
|
4049
4127
|
typeMatchValid: { type: Boolean },
|
|
4128
|
+
validateOnInit: {
|
|
4129
|
+
type: Boolean,
|
|
4130
|
+
default: false
|
|
4131
|
+
},
|
|
4050
4132
|
disabled: {
|
|
4051
4133
|
type: Boolean,
|
|
4052
4134
|
default: false
|
|
@@ -4244,7 +4326,7 @@
|
|
|
4244
4326
|
}).then((value) => {
|
|
4245
4327
|
values.value = value;
|
|
4246
4328
|
initialized.value = !props.isCompare;
|
|
4247
|
-
(0, vue.nextTick)(() => {
|
|
4329
|
+
if (props.validateOnInit) (0, vue.nextTick)(() => {
|
|
4248
4330
|
tMagicFormRef.value?.validate();
|
|
4249
4331
|
});
|
|
4250
4332
|
});
|
|
@@ -4874,6 +4956,10 @@
|
|
|
4874
4956
|
width: {},
|
|
4875
4957
|
labelWidth: {},
|
|
4876
4958
|
typeMatchValid: { type: Boolean },
|
|
4959
|
+
validateOnInit: {
|
|
4960
|
+
type: Boolean,
|
|
4961
|
+
default: false
|
|
4962
|
+
},
|
|
4877
4963
|
fullscreen: { type: Boolean },
|
|
4878
4964
|
disabled: { type: Boolean },
|
|
4879
4965
|
title: {},
|
|
@@ -5064,6 +5150,7 @@
|
|
|
5064
5150
|
"prevent-submit-default": __props.preventSubmitDefault,
|
|
5065
5151
|
"use-field-text-in-error": __props.useFieldTextInError,
|
|
5066
5152
|
"type-match-valid": __props.typeMatchValid,
|
|
5153
|
+
"validate-on-init": __props.validateOnInit,
|
|
5067
5154
|
"extend-state": __props.extendState,
|
|
5068
5155
|
theme: effectiveTheme.value,
|
|
5069
5156
|
onChange: changeHandler
|
|
@@ -5080,6 +5167,7 @@
|
|
|
5080
5167
|
"prevent-submit-default",
|
|
5081
5168
|
"use-field-text-in-error",
|
|
5082
5169
|
"type-match-valid",
|
|
5170
|
+
"validate-on-init",
|
|
5083
5171
|
"extend-state",
|
|
5084
5172
|
"theme"
|
|
5085
5173
|
]), (0, vue.renderSlot)(_ctx.$slots, "default")], 4)) : (0, vue.createCommentVNode)("v-if", true)]),
|
|
@@ -5114,6 +5202,10 @@
|
|
|
5114
5202
|
width: {},
|
|
5115
5203
|
labelWidth: {},
|
|
5116
5204
|
typeMatchValid: { type: Boolean },
|
|
5205
|
+
validateOnInit: {
|
|
5206
|
+
type: Boolean,
|
|
5207
|
+
default: false
|
|
5208
|
+
},
|
|
5117
5209
|
disabled: { type: Boolean },
|
|
5118
5210
|
closeOnPressEscape: {
|
|
5119
5211
|
type: Boolean,
|
|
@@ -5281,6 +5373,7 @@
|
|
|
5281
5373
|
"prevent-submit-default": __props.preventSubmitDefault,
|
|
5282
5374
|
"use-field-text-in-error": __props.useFieldTextInError,
|
|
5283
5375
|
"type-match-valid": __props.typeMatchValid,
|
|
5376
|
+
"validate-on-init": __props.validateOnInit,
|
|
5284
5377
|
"extend-state": __props.extendState,
|
|
5285
5378
|
theme: effectiveTheme.value,
|
|
5286
5379
|
onChange: changeHandler
|
|
@@ -5296,6 +5389,7 @@
|
|
|
5296
5389
|
"prevent-submit-default",
|
|
5297
5390
|
"use-field-text-in-error",
|
|
5298
5391
|
"type-match-valid",
|
|
5392
|
+
"validate-on-init",
|
|
5299
5393
|
"extend-state",
|
|
5300
5394
|
"theme"
|
|
5301
5395
|
]), (0, vue.renderSlot)(_ctx.$slots, "default")], 512)) : (0, vue.createCommentVNode)("v-if", true)]),
|
|
@@ -5328,6 +5422,10 @@
|
|
|
5328
5422
|
height: {},
|
|
5329
5423
|
labelWidth: {},
|
|
5330
5424
|
typeMatchValid: { type: Boolean },
|
|
5425
|
+
validateOnInit: {
|
|
5426
|
+
type: Boolean,
|
|
5427
|
+
default: false
|
|
5428
|
+
},
|
|
5331
5429
|
disabled: { type: Boolean },
|
|
5332
5430
|
size: {},
|
|
5333
5431
|
confirmText: { default: "确定" },
|
|
@@ -5404,6 +5502,7 @@
|
|
|
5404
5502
|
"use-field-text-in-error": __props.useFieldTextInError,
|
|
5405
5503
|
"extend-state": __props.extendState,
|
|
5406
5504
|
"type-match-valid": __props.typeMatchValid,
|
|
5505
|
+
"validate-on-init": __props.validateOnInit,
|
|
5407
5506
|
onChange: changeHandler
|
|
5408
5507
|
}, null, 8, [
|
|
5409
5508
|
"size",
|
|
@@ -5417,7 +5516,8 @@
|
|
|
5417
5516
|
"prevent-submit-default",
|
|
5418
5517
|
"use-field-text-in-error",
|
|
5419
5518
|
"extend-state",
|
|
5420
|
-
"type-match-valid"
|
|
5519
|
+
"type-match-valid",
|
|
5520
|
+
"validate-on-init"
|
|
5421
5521
|
]), (0, vue.renderSlot)(_ctx.$slots, "default")]),
|
|
5422
5522
|
_: 3
|
|
5423
5523
|
})], 4), (0, vue.createElementVNode)("div", {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.8.0-beta.
|
|
2
|
+
"version": "1.8.0-beta.19",
|
|
3
3
|
"name": "@tmagic/form",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"vue": "^3.5.40",
|
|
54
54
|
"typescript": "^6.0.3",
|
|
55
|
-
"@tmagic/design": "1.8.0-beta.
|
|
56
|
-
"@tmagic/
|
|
57
|
-
"@tmagic/
|
|
55
|
+
"@tmagic/design": "1.8.0-beta.19",
|
|
56
|
+
"@tmagic/form-schema": "1.8.0-beta.19",
|
|
57
|
+
"@tmagic/utils": "1.8.0-beta.19"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"typescript": {
|
package/src/Form.vue
CHANGED
|
@@ -88,6 +88,13 @@ const props = withDefaults(
|
|
|
88
88
|
labelWidth?: string;
|
|
89
89
|
/** 是否开启类型匹配校验 */
|
|
90
90
|
typeMatchValid?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* 初始化(`config` / `initValues` 就绪)后是否立即执行一次表单校验。
|
|
93
|
+
*
|
|
94
|
+
* - `false`(默认):不自动校验,避免打开表单时就展示错误态;
|
|
95
|
+
* - `true`:初始化完成后在 `nextTick` 中调用 `validate()`。
|
|
96
|
+
*/
|
|
97
|
+
validateOnInit?: boolean;
|
|
91
98
|
disabled?: boolean;
|
|
92
99
|
height?: string;
|
|
93
100
|
stepActive?: string | number;
|
|
@@ -156,6 +163,7 @@ const props = withDefaults(
|
|
|
156
163
|
labelPosition: 'right',
|
|
157
164
|
keyProp: '__key',
|
|
158
165
|
useFieldTextInError: true,
|
|
166
|
+
validateOnInit: false,
|
|
159
167
|
},
|
|
160
168
|
);
|
|
161
169
|
|
|
@@ -353,9 +361,11 @@ watch(
|
|
|
353
361
|
// 非对比模式,初始化完成
|
|
354
362
|
initialized.value = !props.isCompare;
|
|
355
363
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
364
|
+
if (props.validateOnInit) {
|
|
365
|
+
nextTick(() => {
|
|
366
|
+
tMagicFormRef.value?.validate();
|
|
367
|
+
});
|
|
368
|
+
}
|
|
359
369
|
});
|
|
360
370
|
|
|
361
371
|
if (props.isCompare) {
|
package/src/FormBox.vue
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
:use-field-text-in-error="useFieldTextInError"
|
|
17
17
|
:extend-state="extendState"
|
|
18
18
|
:type-match-valid="typeMatchValid"
|
|
19
|
+
:validate-on-init="validateOnInit"
|
|
19
20
|
@change="changeHandler"
|
|
20
21
|
></Form>
|
|
21
22
|
<slot></slot>
|
|
@@ -59,6 +60,8 @@ const props = withDefaults(
|
|
|
59
60
|
labelWidth?: string;
|
|
60
61
|
/** 是否开启类型匹配校验 */
|
|
61
62
|
typeMatchValid?: boolean;
|
|
63
|
+
/** 透传给内部 `MForm`,初始化完成后是否立即校验(默认 `false`) */
|
|
64
|
+
validateOnInit?: boolean;
|
|
62
65
|
disabled?: boolean;
|
|
63
66
|
size?: 'small' | 'default' | 'large';
|
|
64
67
|
confirmText?: string;
|
|
@@ -74,6 +77,7 @@ const props = withDefaults(
|
|
|
74
77
|
values: () => ({}),
|
|
75
78
|
confirmText: '确定',
|
|
76
79
|
useFieldTextInError: true,
|
|
80
|
+
validateOnInit: false,
|
|
77
81
|
},
|
|
78
82
|
);
|
|
79
83
|
|
package/src/FormDialog.vue
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
:prevent-submit-default="preventSubmitDefault"
|
|
34
34
|
:use-field-text-in-error="useFieldTextInError"
|
|
35
35
|
:type-match-valid="typeMatchValid"
|
|
36
|
+
:validate-on-init="validateOnInit"
|
|
36
37
|
:extend-state="extendState"
|
|
37
38
|
:theme="effectiveTheme"
|
|
38
39
|
@change="changeHandler"
|
|
@@ -87,6 +88,8 @@ const props = withDefaults(
|
|
|
87
88
|
labelWidth?: string;
|
|
88
89
|
/** 是否开启类型匹配校验 */
|
|
89
90
|
typeMatchValid?: boolean;
|
|
91
|
+
/** 透传给内部 `MForm`,初始化完成后是否立即校验(默认 `false`) */
|
|
92
|
+
validateOnInit?: boolean;
|
|
90
93
|
fullscreen?: boolean;
|
|
91
94
|
disabled?: boolean;
|
|
92
95
|
title?: string;
|
|
@@ -122,6 +125,7 @@ const props = withDefaults(
|
|
|
122
125
|
showClose: true,
|
|
123
126
|
showCancel: true,
|
|
124
127
|
useFieldTextInError: true,
|
|
128
|
+
validateOnInit: false,
|
|
125
129
|
},
|
|
126
130
|
);
|
|
127
131
|
|
package/src/FormDrawer.vue
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
:prevent-submit-default="preventSubmitDefault"
|
|
31
31
|
:use-field-text-in-error="useFieldTextInError"
|
|
32
32
|
:type-match-valid="typeMatchValid"
|
|
33
|
+
:validate-on-init="validateOnInit"
|
|
33
34
|
:extend-state="extendState"
|
|
34
35
|
:theme="effectiveTheme"
|
|
35
36
|
@change="changeHandler"
|
|
@@ -78,6 +79,8 @@ const props = withDefaults(
|
|
|
78
79
|
labelWidth?: string;
|
|
79
80
|
/** 是否开启类型匹配校验 */
|
|
80
81
|
typeMatchValid?: boolean;
|
|
82
|
+
/** 透传给内部 `MForm`,初始化完成后是否立即校验(默认 `false`) */
|
|
83
|
+
validateOnInit?: boolean;
|
|
81
84
|
disabled?: boolean;
|
|
82
85
|
closeOnPressEscape?: boolean;
|
|
83
86
|
title?: string;
|
|
@@ -106,6 +109,7 @@ const props = withDefaults(
|
|
|
106
109
|
values: () => ({}),
|
|
107
110
|
confirmText: '确定',
|
|
108
111
|
useFieldTextInError: true,
|
|
112
|
+
validateOnInit: false,
|
|
109
113
|
},
|
|
110
114
|
);
|
|
111
115
|
|
package/src/utils/form.ts
CHANGED
|
@@ -60,13 +60,15 @@ export const adaptFormValidator = (validator: AsyncValidatorFn): AsyncValidatorF
|
|
|
60
60
|
const value = arg1;
|
|
61
61
|
return new Promise((resolve) => {
|
|
62
62
|
let settled = false;
|
|
63
|
-
const callback = (error?: Error | string) => {
|
|
63
|
+
const callback = (error?: Error | string | (Error | string)[]) => {
|
|
64
64
|
if (settled) return;
|
|
65
65
|
settled = true;
|
|
66
|
-
|
|
66
|
+
// async-validator 约定 callback 也可接收错误数组,TDesign 只能展示一条,取首条
|
|
67
|
+
const first = Array.isArray(error) ? error[0] : error;
|
|
68
|
+
if (first) {
|
|
67
69
|
resolve({
|
|
68
70
|
result: false,
|
|
69
|
-
message: typeof
|
|
71
|
+
message: typeof first === 'string' ? first : first.message,
|
|
70
72
|
});
|
|
71
73
|
} else {
|
|
72
74
|
resolve(true);
|
|
@@ -74,8 +76,9 @@ export const adaptFormValidator = (validator: AsyncValidatorFn): AsyncValidatorF
|
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
try {
|
|
79
|
+
// 异步 validator 会先返回 undefined,稍后再调 callback,这里不能当成 thenable 取值
|
|
77
80
|
const result = validator(undefined, value, callback);
|
|
78
|
-
if (result
|
|
81
|
+
if (result && typeof (result as PromiseLike<unknown>).then === 'function') {
|
|
79
82
|
Promise.resolve(result).then(
|
|
80
83
|
() => {
|
|
81
84
|
if (!settled) callback();
|
package/src/utils/typeMatch.ts
CHANGED
|
@@ -38,8 +38,15 @@ export interface TypeMatchValidateContext {
|
|
|
38
38
|
// #endregion TypeMatchValidateContext
|
|
39
39
|
|
|
40
40
|
// #region TypeMatchValidator
|
|
41
|
-
/**
|
|
42
|
-
|
|
41
|
+
/**
|
|
42
|
+
* 自定义 type 校验器:返回错误文案;通过则返回 undefined。
|
|
43
|
+
*
|
|
44
|
+
* 支持返回 Promise,用于需要异步确认取值是否合法的场景(如请求接口校验 id 是否存在)。
|
|
45
|
+
*/
|
|
46
|
+
export type TypeMatchValidator = (
|
|
47
|
+
value: any,
|
|
48
|
+
context: TypeMatchValidateContext,
|
|
49
|
+
) => string | undefined | Promise<string | undefined>;
|
|
43
50
|
// #endregion TypeMatchValidator
|
|
44
51
|
|
|
45
52
|
const typeMatchRuleRegistry = new Map<string, TypeMatchValidator>();
|
|
@@ -692,12 +699,17 @@ const validateBuiltinTypeMatch = (
|
|
|
692
699
|
return undefined;
|
|
693
700
|
};
|
|
694
701
|
|
|
702
|
+
/**
|
|
703
|
+
* 校验取值与字段 type 是否匹配;通过返回 undefined,否则返回错误文案。
|
|
704
|
+
*
|
|
705
|
+
* 命中的自定义规则是异步校验器时返回 Promise,内置规则始终同步返回。
|
|
706
|
+
*/
|
|
695
707
|
export const validateTypeMatch = (
|
|
696
708
|
value: any,
|
|
697
709
|
mForm: FormState | undefined,
|
|
698
710
|
props: any,
|
|
699
711
|
message?: string,
|
|
700
|
-
): string | undefined => {
|
|
712
|
+
): string | undefined | Promise<string | undefined> => {
|
|
701
713
|
if (isEmptyValue(value) || isEmptyArray(value)) {
|
|
702
714
|
return undefined;
|
|
703
715
|
}
|
|
@@ -724,43 +736,135 @@ export const validateTypeMatch = (
|
|
|
724
736
|
return validateBuiltinTypeMatch(value, fieldType, mForm, props, message);
|
|
725
737
|
};
|
|
726
738
|
|
|
739
|
+
const toError = (error: any): Error => (error instanceof Error ? error : new Error(`${error}`));
|
|
740
|
+
|
|
727
741
|
export const createTypeMatchValidator = (mForm: FormState | undefined, props: any, rule: Rule) => {
|
|
728
742
|
const originalValidator = typeof rule.validator === 'function' ? rule.validator : undefined;
|
|
729
743
|
|
|
744
|
+
/**
|
|
745
|
+
* 每次校验取一个自增序号,只有最新一轮的结论会被采用。
|
|
746
|
+
*
|
|
747
|
+
* 旧值的在途校验不能用自己的结论结算:它可能晚于新校验结束,用过期结论覆盖新结论
|
|
748
|
+
* (表单取最后结束的那次结果);也不能在新校验开始时无条件按通过结算,否则
|
|
749
|
+
* `form.validate()` 会对一个还没校验过的值返回成功。因此所有尚未结算的调用都登记在
|
|
750
|
+
* pendingSettlers 中,等最新一轮出结论后用同一个结论一起结算。
|
|
751
|
+
*
|
|
752
|
+
* 不比较取值本身:配了 names 或取值为对象/数组时拿到的是同一个引用,就地修改后比较不出变化。
|
|
753
|
+
*/
|
|
754
|
+
let generation = 0;
|
|
755
|
+
let pendingSettlers: ((args: any[]) => void)[] = [];
|
|
756
|
+
|
|
730
757
|
return (asyncValidatorRule: any, value: any, callback: Function, source: any, options: any) => {
|
|
731
758
|
const actualValue = props.config?.names ? props.model : value;
|
|
732
|
-
try {
|
|
733
|
-
const error = validateTypeMatch(actualValue, mForm, props, rule.message);
|
|
734
759
|
|
|
735
|
-
|
|
736
|
-
|
|
760
|
+
generation += 1;
|
|
761
|
+
const currentGeneration = generation;
|
|
762
|
+
/** 已有更新的一轮校验开始,本轮结论作废 */
|
|
763
|
+
const isStale = () => currentGeneration !== generation;
|
|
764
|
+
|
|
765
|
+
pendingSettlers.push((args: any[]) => callback(...args));
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* 结算本轮与被本轮取代的所有在途校验。
|
|
769
|
+
*
|
|
770
|
+
* async-validator 的 callback 不幂等:重复调用会让它的内部计数提前满足、错误信息重复;
|
|
771
|
+
* 原始 validator 写成 async 时很容易既调 callback 又返回 Promise,故所有回调都收敛到这里,
|
|
772
|
+
* 由「取出即出队」保证每个调用的 callback 只会被调用一次。
|
|
773
|
+
*/
|
|
774
|
+
const conclude = (...args: any[]) => {
|
|
775
|
+
if (isStale()) {
|
|
737
776
|
return;
|
|
738
777
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
778
|
+
|
|
779
|
+
const settlers = pendingSettlers;
|
|
780
|
+
pendingSettlers = [];
|
|
781
|
+
for (const settle of settlers) {
|
|
782
|
+
settle(args);
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* 执行原始 validator 并把结果统一转成 callback。
|
|
788
|
+
*
|
|
789
|
+
* async-validator 只解析同步返回给它的返回值(true / false / Error / 错误数组 / Promise,
|
|
790
|
+
* 抛错转成错误信息),异步路径已脱离它的调用栈,这些约定会失效导致校验永不结束,故复刻一份。
|
|
791
|
+
*/
|
|
792
|
+
const settleWithOriginalValidator = () => {
|
|
793
|
+
// 本轮结论已作废,不必再跑一遍原始 validator 触发副作用
|
|
794
|
+
if (isStale()) {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if (!originalValidator) {
|
|
799
|
+
conclude();
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
let result: any;
|
|
804
|
+
try {
|
|
805
|
+
result = originalValidator(
|
|
806
|
+
{ rule: asyncValidatorRule, value: actualValue, callback: conclude, source, options },
|
|
807
|
+
{
|
|
808
|
+
values: mForm?.initValues || {},
|
|
809
|
+
model: props.model,
|
|
810
|
+
parent: mForm?.parentValues || {},
|
|
811
|
+
formValue: mForm?.values || props.model,
|
|
812
|
+
prop: props.prop,
|
|
813
|
+
config: props.config,
|
|
814
|
+
},
|
|
815
|
+
mForm,
|
|
816
|
+
);
|
|
817
|
+
} catch (err) {
|
|
818
|
+
conclude(toError(err));
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
if (isPromise(result)) {
|
|
823
|
+
result.then(
|
|
824
|
+
() => conclude(),
|
|
825
|
+
(err: any) => conclude(toError(err)),
|
|
826
|
+
);
|
|
827
|
+
} else if (result === true) {
|
|
828
|
+
conclude();
|
|
829
|
+
} else if (result === false) {
|
|
830
|
+
const field = asyncValidatorRule?.fullField || asyncValidatorRule?.field || props.prop;
|
|
831
|
+
conclude(new Error(rule.message || `${field} fails`));
|
|
832
|
+
} else if (result instanceof Error || Array.isArray(result)) {
|
|
833
|
+
conclude(result);
|
|
834
|
+
}
|
|
835
|
+
// 其余返回值(undefined / void)按约定由 validator 自行调用 callback
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
// 校验器自身失败(如接口异常)不应阻塞用户,记录后按通过处理
|
|
839
|
+
const skipFailedTypeMatch = (err: any) => {
|
|
840
|
+
console.error(err);
|
|
841
|
+
settleWithOriginalValidator();
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
let error: string | undefined | Promise<string | undefined>;
|
|
845
|
+
try {
|
|
846
|
+
error = validateTypeMatch(actualValue, mForm, props, rule.message);
|
|
847
|
+
} catch (err) {
|
|
848
|
+
skipFailedTypeMatch(err);
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
if (isPromise(error)) {
|
|
853
|
+
error.then((asyncMessage) => {
|
|
854
|
+
if (asyncMessage) {
|
|
855
|
+
conclude(new Error(asyncMessage));
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
settleWithOriginalValidator();
|
|
859
|
+
}, skipFailedTypeMatch);
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
if (error) {
|
|
864
|
+
conclude(new Error(error));
|
|
865
|
+
return;
|
|
762
866
|
}
|
|
763
867
|
|
|
764
|
-
|
|
868
|
+
settleWithOriginalValidator();
|
|
765
869
|
};
|
|
766
870
|
};
|
package/types/index.d.ts
CHANGED
|
@@ -325,6 +325,13 @@ type __VLS_Props$30 = {
|
|
|
325
325
|
parentValues?: Record<string, any>;
|
|
326
326
|
labelWidth?: string; /** 是否开启类型匹配校验 */
|
|
327
327
|
typeMatchValid?: boolean;
|
|
328
|
+
/**
|
|
329
|
+
* 初始化(`config` / `initValues` 就绪)后是否立即执行一次表单校验。
|
|
330
|
+
*
|
|
331
|
+
* - `false`(默认):不自动校验,避免打开表单时就展示错误态;
|
|
332
|
+
* - `true`:初始化完成后在 `nextTick` 中调用 `validate()`。
|
|
333
|
+
*/
|
|
334
|
+
validateOnInit?: boolean;
|
|
328
335
|
disabled?: boolean;
|
|
329
336
|
height?: string;
|
|
330
337
|
stepActive?: string | number;
|
|
@@ -435,6 +442,7 @@ declare const __VLS_base$5: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
435
442
|
keyProp: string;
|
|
436
443
|
parentValues: Record<string, any>;
|
|
437
444
|
stepActive: string | number;
|
|
445
|
+
validateOnInit: boolean;
|
|
438
446
|
useFieldTextInError: boolean;
|
|
439
447
|
}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, false, {}, any>;
|
|
440
448
|
declare const __VLS_export$30: __VLS_WithSlots$5<typeof __VLS_base$5, __VLS_Slots$5>;
|
|
@@ -452,7 +460,8 @@ type __VLS_Props$29 = {
|
|
|
452
460
|
parentValues?: Object;
|
|
453
461
|
width?: string | number;
|
|
454
462
|
labelWidth?: string; /** 是否开启类型匹配校验 */
|
|
455
|
-
typeMatchValid?: boolean;
|
|
463
|
+
typeMatchValid?: boolean; /** 透传给内部 `MForm`,初始化完成后是否立即校验(默认 `false`) */
|
|
464
|
+
validateOnInit?: boolean;
|
|
456
465
|
fullscreen?: boolean;
|
|
457
466
|
disabled?: boolean;
|
|
458
467
|
title?: string;
|
|
@@ -496,6 +505,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
496
505
|
readonly parentValues?: Record<string, any> | undefined;
|
|
497
506
|
readonly labelWidth?: string | undefined;
|
|
498
507
|
readonly typeMatchValid?: boolean | undefined;
|
|
508
|
+
readonly validateOnInit?: boolean | undefined;
|
|
499
509
|
readonly disabled?: boolean | undefined;
|
|
500
510
|
readonly height?: string | undefined;
|
|
501
511
|
readonly stepActive?: string | number | undefined;
|
|
@@ -540,6 +550,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
540
550
|
parentValues?: Record<string, any>;
|
|
541
551
|
labelWidth?: string;
|
|
542
552
|
typeMatchValid?: boolean;
|
|
553
|
+
validateOnInit?: boolean;
|
|
543
554
|
disabled?: boolean;
|
|
544
555
|
height?: string;
|
|
545
556
|
stepActive?: string | number;
|
|
@@ -594,6 +605,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
594
605
|
keyProp: string;
|
|
595
606
|
parentValues: Record<string, any>;
|
|
596
607
|
stepActive: string | number;
|
|
608
|
+
validateOnInit: boolean;
|
|
597
609
|
useFieldTextInError: boolean;
|
|
598
610
|
}, {}, string, {}, import("@vue/runtime-core").GlobalComponents, import("@vue/runtime-core").GlobalDirectives, string, import("@vue/runtime-core").ComponentProvideOptions> & {
|
|
599
611
|
beforeCreate?: (() => void) | (() => void)[];
|
|
@@ -628,6 +640,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
628
640
|
keyProp: string;
|
|
629
641
|
parentValues: Record<string, any>;
|
|
630
642
|
stepActive: string | number;
|
|
643
|
+
validateOnInit: boolean;
|
|
631
644
|
useFieldTextInError: boolean;
|
|
632
645
|
}> & Omit<Readonly<{
|
|
633
646
|
config: schema_d_exports.FormConfig;
|
|
@@ -637,6 +650,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
637
650
|
parentValues?: Record<string, any>;
|
|
638
651
|
labelWidth?: string;
|
|
639
652
|
typeMatchValid?: boolean;
|
|
653
|
+
validateOnInit?: boolean;
|
|
640
654
|
disabled?: boolean;
|
|
641
655
|
height?: string;
|
|
642
656
|
stepActive?: string | number;
|
|
@@ -661,7 +675,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
661
675
|
"onField-input"?: ((...args: any[]) => any) | undefined;
|
|
662
676
|
"onField-change"?: ((...args: any[]) => any) | undefined;
|
|
663
677
|
"onUpdate:stepActive"?: ((...args: any[]) => any) | undefined;
|
|
664
|
-
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "useFieldTextInError")> & {
|
|
678
|
+
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "validateOnInit" | "useFieldTextInError")> & {
|
|
665
679
|
values: schema_d_exports.FormValue;
|
|
666
680
|
lastValuesProcessed: schema_d_exports.FormValue;
|
|
667
681
|
formState: schema_d_exports.FormState;
|
|
@@ -685,6 +699,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
685
699
|
readonly parentValues?: Record<string, any> | undefined;
|
|
686
700
|
readonly labelWidth?: string | undefined;
|
|
687
701
|
readonly typeMatchValid?: boolean | undefined;
|
|
702
|
+
readonly validateOnInit?: boolean | undefined;
|
|
688
703
|
readonly disabled?: boolean | undefined;
|
|
689
704
|
readonly height?: string | undefined;
|
|
690
705
|
readonly stepActive?: string | number | undefined;
|
|
@@ -729,6 +744,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
729
744
|
parentValues?: Record<string, any>;
|
|
730
745
|
labelWidth?: string;
|
|
731
746
|
typeMatchValid?: boolean;
|
|
747
|
+
validateOnInit?: boolean;
|
|
732
748
|
disabled?: boolean;
|
|
733
749
|
height?: string;
|
|
734
750
|
stepActive?: string | number;
|
|
@@ -783,6 +799,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
783
799
|
keyProp: string;
|
|
784
800
|
parentValues: Record<string, any>;
|
|
785
801
|
stepActive: string | number;
|
|
802
|
+
validateOnInit: boolean;
|
|
786
803
|
useFieldTextInError: boolean;
|
|
787
804
|
}, {}, string, {}, import("@vue/runtime-core").GlobalComponents, import("@vue/runtime-core").GlobalDirectives, string, import("@vue/runtime-core").ComponentProvideOptions> & {
|
|
788
805
|
beforeCreate?: (() => void) | (() => void)[];
|
|
@@ -817,6 +834,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
817
834
|
keyProp: string;
|
|
818
835
|
parentValues: Record<string, any>;
|
|
819
836
|
stepActive: string | number;
|
|
837
|
+
validateOnInit: boolean;
|
|
820
838
|
useFieldTextInError: boolean;
|
|
821
839
|
}> & Omit<Readonly<{
|
|
822
840
|
config: schema_d_exports.FormConfig;
|
|
@@ -826,6 +844,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
826
844
|
parentValues?: Record<string, any>;
|
|
827
845
|
labelWidth?: string;
|
|
828
846
|
typeMatchValid?: boolean;
|
|
847
|
+
validateOnInit?: boolean;
|
|
829
848
|
disabled?: boolean;
|
|
830
849
|
height?: string;
|
|
831
850
|
stepActive?: string | number;
|
|
@@ -850,7 +869,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
850
869
|
"onField-input"?: ((...args: any[]) => any) | undefined;
|
|
851
870
|
"onField-change"?: ((...args: any[]) => any) | undefined;
|
|
852
871
|
"onUpdate:stepActive"?: ((...args: any[]) => any) | undefined;
|
|
853
|
-
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "useFieldTextInError")> & {
|
|
872
|
+
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "validateOnInit" | "useFieldTextInError")> & {
|
|
854
873
|
values: schema_d_exports.FormValue;
|
|
855
874
|
lastValuesProcessed: schema_d_exports.FormValue;
|
|
856
875
|
formState: schema_d_exports.FormState;
|
|
@@ -887,6 +906,7 @@ declare const __VLS_base$4: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
887
906
|
destroyOnClose: boolean;
|
|
888
907
|
showClose: boolean;
|
|
889
908
|
config: schema_d_exports.FormConfig;
|
|
909
|
+
validateOnInit: boolean;
|
|
890
910
|
useFieldTextInError: boolean;
|
|
891
911
|
confirmText: string;
|
|
892
912
|
showCancel: boolean;
|
|
@@ -906,7 +926,8 @@ type __VLS_Props$28 = {
|
|
|
906
926
|
parentValues?: Object;
|
|
907
927
|
width?: string | number;
|
|
908
928
|
labelWidth?: string; /** 是否开启类型匹配校验 */
|
|
909
|
-
typeMatchValid?: boolean;
|
|
929
|
+
typeMatchValid?: boolean; /** 透传给内部 `MForm`,初始化完成后是否立即校验(默认 `false`) */
|
|
930
|
+
validateOnInit?: boolean;
|
|
910
931
|
disabled?: boolean;
|
|
911
932
|
closeOnPressEscape?: boolean;
|
|
912
933
|
title?: string;
|
|
@@ -946,6 +967,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
946
967
|
readonly parentValues?: Record<string, any> | undefined;
|
|
947
968
|
readonly labelWidth?: string | undefined;
|
|
948
969
|
readonly typeMatchValid?: boolean | undefined;
|
|
970
|
+
readonly validateOnInit?: boolean | undefined;
|
|
949
971
|
readonly disabled?: boolean | undefined;
|
|
950
972
|
readonly height?: string | undefined;
|
|
951
973
|
readonly stepActive?: string | number | undefined;
|
|
@@ -990,6 +1012,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
990
1012
|
parentValues?: Record<string, any>;
|
|
991
1013
|
labelWidth?: string;
|
|
992
1014
|
typeMatchValid?: boolean;
|
|
1015
|
+
validateOnInit?: boolean;
|
|
993
1016
|
disabled?: boolean;
|
|
994
1017
|
height?: string;
|
|
995
1018
|
stepActive?: string | number;
|
|
@@ -1044,6 +1067,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1044
1067
|
keyProp: string;
|
|
1045
1068
|
parentValues: Record<string, any>;
|
|
1046
1069
|
stepActive: string | number;
|
|
1070
|
+
validateOnInit: boolean;
|
|
1047
1071
|
useFieldTextInError: boolean;
|
|
1048
1072
|
}, {}, string, {}, import("@vue/runtime-core").GlobalComponents, import("@vue/runtime-core").GlobalDirectives, string, import("@vue/runtime-core").ComponentProvideOptions> & {
|
|
1049
1073
|
beforeCreate?: (() => void) | (() => void)[];
|
|
@@ -1078,6 +1102,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1078
1102
|
keyProp: string;
|
|
1079
1103
|
parentValues: Record<string, any>;
|
|
1080
1104
|
stepActive: string | number;
|
|
1105
|
+
validateOnInit: boolean;
|
|
1081
1106
|
useFieldTextInError: boolean;
|
|
1082
1107
|
}> & Omit<Readonly<{
|
|
1083
1108
|
config: schema_d_exports.FormConfig;
|
|
@@ -1087,6 +1112,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1087
1112
|
parentValues?: Record<string, any>;
|
|
1088
1113
|
labelWidth?: string;
|
|
1089
1114
|
typeMatchValid?: boolean;
|
|
1115
|
+
validateOnInit?: boolean;
|
|
1090
1116
|
disabled?: boolean;
|
|
1091
1117
|
height?: string;
|
|
1092
1118
|
stepActive?: string | number;
|
|
@@ -1111,7 +1137,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1111
1137
|
"onField-input"?: ((...args: any[]) => any) | undefined;
|
|
1112
1138
|
"onField-change"?: ((...args: any[]) => any) | undefined;
|
|
1113
1139
|
"onUpdate:stepActive"?: ((...args: any[]) => any) | undefined;
|
|
1114
|
-
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "useFieldTextInError")> & {
|
|
1140
|
+
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "validateOnInit" | "useFieldTextInError")> & {
|
|
1115
1141
|
values: schema_d_exports.FormValue;
|
|
1116
1142
|
lastValuesProcessed: schema_d_exports.FormValue;
|
|
1117
1143
|
formState: schema_d_exports.FormState;
|
|
@@ -1135,6 +1161,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1135
1161
|
readonly parentValues?: Record<string, any> | undefined;
|
|
1136
1162
|
readonly labelWidth?: string | undefined;
|
|
1137
1163
|
readonly typeMatchValid?: boolean | undefined;
|
|
1164
|
+
readonly validateOnInit?: boolean | undefined;
|
|
1138
1165
|
readonly disabled?: boolean | undefined;
|
|
1139
1166
|
readonly height?: string | undefined;
|
|
1140
1167
|
readonly stepActive?: string | number | undefined;
|
|
@@ -1179,6 +1206,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1179
1206
|
parentValues?: Record<string, any>;
|
|
1180
1207
|
labelWidth?: string;
|
|
1181
1208
|
typeMatchValid?: boolean;
|
|
1209
|
+
validateOnInit?: boolean;
|
|
1182
1210
|
disabled?: boolean;
|
|
1183
1211
|
height?: string;
|
|
1184
1212
|
stepActive?: string | number;
|
|
@@ -1233,6 +1261,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1233
1261
|
keyProp: string;
|
|
1234
1262
|
parentValues: Record<string, any>;
|
|
1235
1263
|
stepActive: string | number;
|
|
1264
|
+
validateOnInit: boolean;
|
|
1236
1265
|
useFieldTextInError: boolean;
|
|
1237
1266
|
}, {}, string, {}, import("@vue/runtime-core").GlobalComponents, import("@vue/runtime-core").GlobalDirectives, string, import("@vue/runtime-core").ComponentProvideOptions> & {
|
|
1238
1267
|
beforeCreate?: (() => void) | (() => void)[];
|
|
@@ -1267,6 +1296,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1267
1296
|
keyProp: string;
|
|
1268
1297
|
parentValues: Record<string, any>;
|
|
1269
1298
|
stepActive: string | number;
|
|
1299
|
+
validateOnInit: boolean;
|
|
1270
1300
|
useFieldTextInError: boolean;
|
|
1271
1301
|
}> & Omit<Readonly<{
|
|
1272
1302
|
config: schema_d_exports.FormConfig;
|
|
@@ -1276,6 +1306,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1276
1306
|
parentValues?: Record<string, any>;
|
|
1277
1307
|
labelWidth?: string;
|
|
1278
1308
|
typeMatchValid?: boolean;
|
|
1309
|
+
validateOnInit?: boolean;
|
|
1279
1310
|
disabled?: boolean;
|
|
1280
1311
|
height?: string;
|
|
1281
1312
|
stepActive?: string | number;
|
|
@@ -1300,7 +1331,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1300
1331
|
"onField-input"?: ((...args: any[]) => any) | undefined;
|
|
1301
1332
|
"onField-change"?: ((...args: any[]) => any) | undefined;
|
|
1302
1333
|
"onUpdate:stepActive"?: ((...args: any[]) => any) | undefined;
|
|
1303
|
-
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "useFieldTextInError")> & {
|
|
1334
|
+
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "validateOnInit" | "useFieldTextInError")> & {
|
|
1304
1335
|
values: schema_d_exports.FormValue;
|
|
1305
1336
|
lastValuesProcessed: schema_d_exports.FormValue;
|
|
1306
1337
|
formState: schema_d_exports.FormState;
|
|
@@ -1342,6 +1373,7 @@ declare const __VLS_base$3: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1342
1373
|
values: Object;
|
|
1343
1374
|
closeOnPressEscape: boolean;
|
|
1344
1375
|
config: schema_d_exports.FormConfig;
|
|
1376
|
+
validateOnInit: boolean;
|
|
1345
1377
|
useFieldTextInError: boolean;
|
|
1346
1378
|
confirmText: string;
|
|
1347
1379
|
}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, false, {}, any>;
|
|
@@ -1361,7 +1393,8 @@ type __VLS_Props$27 = {
|
|
|
1361
1393
|
width?: number;
|
|
1362
1394
|
height?: number;
|
|
1363
1395
|
labelWidth?: string; /** 是否开启类型匹配校验 */
|
|
1364
|
-
typeMatchValid?: boolean;
|
|
1396
|
+
typeMatchValid?: boolean; /** 透传给内部 `MForm`,初始化完成后是否立即校验(默认 `false`) */
|
|
1397
|
+
validateOnInit?: boolean;
|
|
1365
1398
|
disabled?: boolean;
|
|
1366
1399
|
size?: 'small' | 'default' | 'large';
|
|
1367
1400
|
confirmText?: string;
|
|
@@ -1391,6 +1424,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1391
1424
|
readonly parentValues?: Record<string, any> | undefined;
|
|
1392
1425
|
readonly labelWidth?: string | undefined;
|
|
1393
1426
|
readonly typeMatchValid?: boolean | undefined;
|
|
1427
|
+
readonly validateOnInit?: boolean | undefined;
|
|
1394
1428
|
readonly disabled?: boolean | undefined;
|
|
1395
1429
|
readonly height?: string | undefined;
|
|
1396
1430
|
readonly stepActive?: string | number | undefined;
|
|
@@ -1435,6 +1469,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1435
1469
|
parentValues?: Record<string, any>;
|
|
1436
1470
|
labelWidth?: string;
|
|
1437
1471
|
typeMatchValid?: boolean;
|
|
1472
|
+
validateOnInit?: boolean;
|
|
1438
1473
|
disabled?: boolean;
|
|
1439
1474
|
height?: string;
|
|
1440
1475
|
stepActive?: string | number;
|
|
@@ -1489,6 +1524,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1489
1524
|
keyProp: string;
|
|
1490
1525
|
parentValues: Record<string, any>;
|
|
1491
1526
|
stepActive: string | number;
|
|
1527
|
+
validateOnInit: boolean;
|
|
1492
1528
|
useFieldTextInError: boolean;
|
|
1493
1529
|
}, {}, string, {}, import("@vue/runtime-core").GlobalComponents, import("@vue/runtime-core").GlobalDirectives, string, import("@vue/runtime-core").ComponentProvideOptions> & {
|
|
1494
1530
|
beforeCreate?: (() => void) | (() => void)[];
|
|
@@ -1523,6 +1559,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1523
1559
|
keyProp: string;
|
|
1524
1560
|
parentValues: Record<string, any>;
|
|
1525
1561
|
stepActive: string | number;
|
|
1562
|
+
validateOnInit: boolean;
|
|
1526
1563
|
useFieldTextInError: boolean;
|
|
1527
1564
|
}> & Omit<Readonly<{
|
|
1528
1565
|
config: schema_d_exports.FormConfig;
|
|
@@ -1532,6 +1569,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1532
1569
|
parentValues?: Record<string, any>;
|
|
1533
1570
|
labelWidth?: string;
|
|
1534
1571
|
typeMatchValid?: boolean;
|
|
1572
|
+
validateOnInit?: boolean;
|
|
1535
1573
|
disabled?: boolean;
|
|
1536
1574
|
height?: string;
|
|
1537
1575
|
stepActive?: string | number;
|
|
@@ -1556,7 +1594,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1556
1594
|
"onField-input"?: ((...args: any[]) => any) | undefined;
|
|
1557
1595
|
"onField-change"?: ((...args: any[]) => any) | undefined;
|
|
1558
1596
|
"onUpdate:stepActive"?: ((...args: any[]) => any) | undefined;
|
|
1559
|
-
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "useFieldTextInError")> & {
|
|
1597
|
+
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "validateOnInit" | "useFieldTextInError")> & {
|
|
1560
1598
|
values: schema_d_exports.FormValue;
|
|
1561
1599
|
lastValuesProcessed: schema_d_exports.FormValue;
|
|
1562
1600
|
formState: schema_d_exports.FormState;
|
|
@@ -1580,6 +1618,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1580
1618
|
readonly parentValues?: Record<string, any> | undefined;
|
|
1581
1619
|
readonly labelWidth?: string | undefined;
|
|
1582
1620
|
readonly typeMatchValid?: boolean | undefined;
|
|
1621
|
+
readonly validateOnInit?: boolean | undefined;
|
|
1583
1622
|
readonly disabled?: boolean | undefined;
|
|
1584
1623
|
readonly height?: string | undefined;
|
|
1585
1624
|
readonly stepActive?: string | number | undefined;
|
|
@@ -1624,6 +1663,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1624
1663
|
parentValues?: Record<string, any>;
|
|
1625
1664
|
labelWidth?: string;
|
|
1626
1665
|
typeMatchValid?: boolean;
|
|
1666
|
+
validateOnInit?: boolean;
|
|
1627
1667
|
disabled?: boolean;
|
|
1628
1668
|
height?: string;
|
|
1629
1669
|
stepActive?: string | number;
|
|
@@ -1678,6 +1718,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1678
1718
|
keyProp: string;
|
|
1679
1719
|
parentValues: Record<string, any>;
|
|
1680
1720
|
stepActive: string | number;
|
|
1721
|
+
validateOnInit: boolean;
|
|
1681
1722
|
useFieldTextInError: boolean;
|
|
1682
1723
|
}, {}, string, {}, import("@vue/runtime-core").GlobalComponents, import("@vue/runtime-core").GlobalDirectives, string, import("@vue/runtime-core").ComponentProvideOptions> & {
|
|
1683
1724
|
beforeCreate?: (() => void) | (() => void)[];
|
|
@@ -1712,6 +1753,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1712
1753
|
keyProp: string;
|
|
1713
1754
|
parentValues: Record<string, any>;
|
|
1714
1755
|
stepActive: string | number;
|
|
1756
|
+
validateOnInit: boolean;
|
|
1715
1757
|
useFieldTextInError: boolean;
|
|
1716
1758
|
}> & Omit<Readonly<{
|
|
1717
1759
|
config: schema_d_exports.FormConfig;
|
|
@@ -1721,6 +1763,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1721
1763
|
parentValues?: Record<string, any>;
|
|
1722
1764
|
labelWidth?: string;
|
|
1723
1765
|
typeMatchValid?: boolean;
|
|
1766
|
+
validateOnInit?: boolean;
|
|
1724
1767
|
disabled?: boolean;
|
|
1725
1768
|
height?: string;
|
|
1726
1769
|
stepActive?: string | number;
|
|
@@ -1745,7 +1788,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1745
1788
|
"onField-input"?: ((...args: any[]) => any) | undefined;
|
|
1746
1789
|
"onField-change"?: ((...args: any[]) => any) | undefined;
|
|
1747
1790
|
"onUpdate:stepActive"?: ((...args: any[]) => any) | undefined;
|
|
1748
|
-
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "useFieldTextInError")> & {
|
|
1791
|
+
}>, "values" | "changeHandler" | "validate" | "initialized" | "lastValuesProcessed" | "formState" | "changeRecords" | "resetForm" | "submitForm" | "getTextByName" | ("disabled" | "labelWidth" | "inline" | "labelPosition" | "config" | "height" | "initValues" | "lastValues" | "isCompare" | "keyProp" | "parentValues" | "stepActive" | "validateOnInit" | "useFieldTextInError")> & {
|
|
1749
1792
|
values: schema_d_exports.FormValue;
|
|
1750
1793
|
lastValuesProcessed: schema_d_exports.FormValue;
|
|
1751
1794
|
formState: schema_d_exports.FormState;
|
|
@@ -1773,6 +1816,7 @@ declare const __VLS_base$2: import("@vue/runtime-core").DefineComponent<__VLS_Pr
|
|
|
1773
1816
|
}>, {
|
|
1774
1817
|
values: Object;
|
|
1775
1818
|
config: schema_d_exports.FormConfig;
|
|
1819
|
+
validateOnInit: boolean;
|
|
1776
1820
|
useFieldTextInError: boolean;
|
|
1777
1821
|
confirmText: string;
|
|
1778
1822
|
}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, false, {}, any>;
|
|
@@ -2206,8 +2250,12 @@ interface TypeMatchValidateContext {
|
|
|
2206
2250
|
props: any;
|
|
2207
2251
|
message?: string;
|
|
2208
2252
|
}
|
|
2209
|
-
/**
|
|
2210
|
-
|
|
2253
|
+
/**
|
|
2254
|
+
* 自定义 type 校验器:返回错误文案;通过则返回 undefined。
|
|
2255
|
+
*
|
|
2256
|
+
* 支持返回 Promise,用于需要异步确认取值是否合法的场景(如请求接口校验 id 是否存在)。
|
|
2257
|
+
*/
|
|
2258
|
+
type TypeMatchValidator = (value: any, context: TypeMatchValidateContext) => string | undefined | Promise<string | undefined>;
|
|
2211
2259
|
/** 注册或覆盖某个字段 type 的 typeMatch 校验规则 */
|
|
2212
2260
|
declare const registerTypeMatchRule: (type: string, validator: TypeMatchValidator) => void;
|
|
2213
2261
|
/** 批量注册 typeMatch 校验规则 */
|
|
@@ -2218,7 +2266,12 @@ declare const getTypeMatchRule: (type: string) => TypeMatchValidator | undefined
|
|
|
2218
2266
|
declare const deleteTypeMatchRule: (type: string) => boolean;
|
|
2219
2267
|
/** 清空所有自定义 typeMatch 校验规则 */
|
|
2220
2268
|
declare const clearTypeMatchRules: () => void;
|
|
2221
|
-
|
|
2269
|
+
/**
|
|
2270
|
+
* 校验取值与字段 type 是否匹配;通过返回 undefined,否则返回错误文案。
|
|
2271
|
+
*
|
|
2272
|
+
* 命中的自定义规则是异步校验器时返回 Promise,内置规则始终同步返回。
|
|
2273
|
+
*/
|
|
2274
|
+
declare const validateTypeMatch: (value: any, mForm: schema_d_exports.FormState | undefined, props: any, message?: string) => string | undefined | Promise<string | undefined>;
|
|
2222
2275
|
//#endregion
|
|
2223
2276
|
//#region temp/packages/form/src/plugin.d.ts
|
|
2224
2277
|
interface FormInstallOptions {
|