@cloudbase/weda-ui-mp 3.15.7 → 3.15.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,11 +3,7 @@ import equal from '../../utils/deepEqual';
|
|
|
3
3
|
import { errorHandler } from '../../utils/error';
|
|
4
4
|
|
|
5
5
|
import { autorun, untracked } from 'mobx';
|
|
6
|
-
import {
|
|
7
|
-
convertStatus,
|
|
8
|
-
convertRules,
|
|
9
|
-
convertMethodParam,
|
|
10
|
-
} from '../../utils/getFormLegacy';
|
|
6
|
+
import { convertStatus, convertRules, convertMethodParam } from '../../utils/getFormLegacy';
|
|
11
7
|
|
|
12
8
|
export default Behavior({
|
|
13
9
|
behaviors: [],
|
|
@@ -101,14 +97,7 @@ export default Behavior({
|
|
|
101
97
|
},
|
|
102
98
|
async handleValidate(throwError = true) {
|
|
103
99
|
let finalValue = that.data.value;
|
|
104
|
-
const {
|
|
105
|
-
required,
|
|
106
|
-
rules,
|
|
107
|
-
requiredMsg,
|
|
108
|
-
privateRules,
|
|
109
|
-
selfDefineRules,
|
|
110
|
-
label,
|
|
111
|
-
} = that.data;
|
|
100
|
+
const { required, rules, requiredMsg, privateRules, selfDefineRules, label } = that.data;
|
|
112
101
|
const _rules = [].concat(rules, privateRules, selfDefineRules);
|
|
113
102
|
if (!required && !_rules.length) return;
|
|
114
103
|
if (finalValue) {
|
|
@@ -124,9 +113,7 @@ export default Behavior({
|
|
|
124
113
|
const validPromise = [];
|
|
125
114
|
if (required) {
|
|
126
115
|
if (!validType.required(finalValue)) {
|
|
127
|
-
validPromise.push(
|
|
128
|
-
Promise.resolve({ format: 'required', message: requiredMsg })
|
|
129
|
-
);
|
|
116
|
+
validPromise.push(Promise.resolve({ format: 'required', message: requiredMsg }));
|
|
130
117
|
}
|
|
131
118
|
}
|
|
132
119
|
|
|
@@ -153,10 +140,7 @@ export default Behavior({
|
|
|
153
140
|
let reg;
|
|
154
141
|
if (typeof item.pattern === 'string') {
|
|
155
142
|
const m = item.pattern.match(/(\/?)(.+)\1([a-z]*)/i);
|
|
156
|
-
if (
|
|
157
|
-
m[3] &&
|
|
158
|
-
!/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])
|
|
159
|
-
) {
|
|
143
|
+
if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) {
|
|
160
144
|
reg = RegExp(item.pattern);
|
|
161
145
|
} else {
|
|
162
146
|
reg = new RegExp(m[2], m[3]);
|
|
@@ -225,15 +209,10 @@ export default Behavior({
|
|
|
225
209
|
Promise.resolve().then(() => {
|
|
226
210
|
this._reaction = autorun(() => {
|
|
227
211
|
const form = untracked(() => {
|
|
228
|
-
return this.$widget?.closest(
|
|
229
|
-
(w) => w.getConfig?.()?.componentType === 'form'
|
|
230
|
-
);
|
|
212
|
+
return this.$widget?.closest((w) => w.getConfig?.()?.componentType === 'form');
|
|
231
213
|
});
|
|
232
214
|
|
|
233
|
-
if (
|
|
234
|
-
form &&
|
|
235
|
-
(this.data.layout === 'auto' || this.data.layout === '')
|
|
236
|
-
) {
|
|
215
|
+
if (form && (this.data.layout === 'auto' || this.data.layout === '')) {
|
|
237
216
|
if (form.layout !== this.data.actualLayout) {
|
|
238
217
|
// 在 form 里面
|
|
239
218
|
this.setData({ actualLayout: form.layout });
|
|
@@ -271,9 +250,7 @@ export default Behavior({
|
|
|
271
250
|
// 清空嵌套表单
|
|
272
251
|
this._removeFormObjItem?.();
|
|
273
252
|
if (this.$widget) {
|
|
274
|
-
const form = this.$widget.closest(
|
|
275
|
-
(w) => w.getConfig?.()?.componentType === 'form'
|
|
276
|
-
);
|
|
253
|
+
const form = this.$widget.closest((w) => w.getConfig?.()?.componentType === 'form');
|
|
277
254
|
|
|
278
255
|
form?.updateFormContext(this.data.name, undefined);
|
|
279
256
|
}
|
|
@@ -315,10 +292,7 @@ export default Behavior({
|
|
|
315
292
|
};
|
|
316
293
|
},
|
|
317
294
|
setReadOnly(val) {
|
|
318
|
-
const [originalReadOnly, originalDisabled] = [
|
|
319
|
-
this.data.readOnly,
|
|
320
|
-
this.data.disabled,
|
|
321
|
-
];
|
|
295
|
+
const [originalReadOnly, originalDisabled] = [this.data.readOnly, this.data.disabled];
|
|
322
296
|
const value = convertMethodParam(val);
|
|
323
297
|
if (value !== originalReadOnly) {
|
|
324
298
|
// 先用disabled属性来做
|
|
@@ -345,29 +319,20 @@ export default Behavior({
|
|
|
345
319
|
// this.$instanceRef.current.name = newName;
|
|
346
320
|
this.data._oldName = newName;
|
|
347
321
|
if (typeof this.$widget !== 'object') return;
|
|
348
|
-
const form = this.$widget?.closest?.(
|
|
349
|
-
(w) => w.getConfig?.()?.componentType === 'form'
|
|
350
|
-
);
|
|
322
|
+
const form = this.$widget?.closest?.((w) => w.getConfig?.()?.componentType === 'form');
|
|
351
323
|
|
|
352
|
-
|
|
324
|
+
const formObj = this.$widget?.closest?.((w) => w.getConfig?.()?.componentType === 'formObj');
|
|
325
|
+
|
|
326
|
+
if (formObj) {
|
|
327
|
+
// 添加子组件到嵌套表单里面
|
|
328
|
+
this._removeFormObjItem = formObj.addFormItem(this.data.name, this.$widget);
|
|
329
|
+
} else if (form) {
|
|
353
330
|
// 在 form 里面
|
|
354
331
|
this._removeFormItem = form.addFormItem(this.data.name, this.$widget);
|
|
355
332
|
if (!Object.prototype.hasOwnProperty.call(form?.value, newName)) {
|
|
356
333
|
form?.updateFormContext(this.data.name, this.data.value);
|
|
357
334
|
}
|
|
358
335
|
}
|
|
359
|
-
|
|
360
|
-
const formObj = this.$widget?.closest?.(
|
|
361
|
-
(w) => w.getConfig?.()?.componentType === 'formObj'
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
if (formObj) {
|
|
365
|
-
// 添加子组件到嵌套表单里面
|
|
366
|
-
this._removeFormObjItem = formObj.addFormItem(
|
|
367
|
-
this.data.name,
|
|
368
|
-
this.$widget
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
336
|
});
|
|
372
337
|
},
|
|
373
338
|
value: function (value) {
|
|
@@ -382,18 +347,12 @@ export default Behavior({
|
|
|
382
347
|
this.$instanceRef.current.value = value;
|
|
383
348
|
|
|
384
349
|
if (this.$widget) {
|
|
385
|
-
const form = this.$widget.closest(
|
|
386
|
-
|
|
387
|
-
);
|
|
388
|
-
const formObj = this.$widget.closest(
|
|
389
|
-
(w) => w.getConfig?.()?.componentType === 'formObj'
|
|
390
|
-
);
|
|
350
|
+
const form = this.$widget.closest((w) => w.getConfig?.()?.componentType === 'form');
|
|
351
|
+
const formObj = this.$widget.closest((w) => w.getConfig?.()?.componentType === 'formObj');
|
|
391
352
|
// 有父级嵌套表单的不更新form值,父级嵌套表单会去更新
|
|
392
353
|
!formObj && form?.updateFormContext(this.data.name, value);
|
|
393
354
|
formObj?.valueChangeFromChild?.({
|
|
394
|
-
name: `${formObj?.formObjName ? `${formObj.formObjName}.` : ''}${
|
|
395
|
-
this.data.name
|
|
396
|
-
}`,
|
|
355
|
+
name: `${formObj?.formObjName ? `${formObj.formObjName}.` : ''}${this.data.name}`,
|
|
397
356
|
value,
|
|
398
357
|
});
|
|
399
358
|
}
|
|
@@ -407,9 +366,7 @@ export default Behavior({
|
|
|
407
366
|
Promise.resolve().then(() => {
|
|
408
367
|
this.data._layout = layout;
|
|
409
368
|
if (!layout || layout === 'auto') {
|
|
410
|
-
const form = this.$widget.closest(
|
|
411
|
-
(w) => w.getConfig?.()?.componentType === 'form'
|
|
412
|
-
);
|
|
369
|
+
const form = this.$widget.closest((w) => w.getConfig?.()?.componentType === 'form');
|
|
413
370
|
|
|
414
371
|
if (form) {
|
|
415
372
|
// 在 form 里面
|
|
@@ -432,9 +389,7 @@ export default Behavior({
|
|
|
432
389
|
this.data._status = status;
|
|
433
390
|
const { disabled: _disabled, readOnly: _readOnly } = this.data;
|
|
434
391
|
const statusParams = convertStatus(status, _disabled, _readOnly);
|
|
435
|
-
const form = this?.$widget?.closest(
|
|
436
|
-
(w) => w.getConfig?.()?.componentType === 'form'
|
|
437
|
-
);
|
|
392
|
+
const form = this?.$widget?.closest((w) => w.getConfig?.()?.componentType === 'form');
|
|
438
393
|
let disabled = statusParams.disabled;
|
|
439
394
|
let readOnly = statusParams.readOnly;
|
|
440
395
|
if (form) {
|
|
@@ -443,13 +398,7 @@ export default Behavior({
|
|
|
443
398
|
}
|
|
444
399
|
this.setData({ disabled, readOnly });
|
|
445
400
|
},
|
|
446
|
-
'required,before,after,requiredMsg,isUnionValue': function (
|
|
447
|
-
required,
|
|
448
|
-
before,
|
|
449
|
-
after,
|
|
450
|
-
requiredMsg,
|
|
451
|
-
isUnionValue
|
|
452
|
-
) {
|
|
401
|
+
'required,before,after,requiredMsg,isUnionValue': function (required, before, after, requiredMsg, isUnionValue) {
|
|
453
402
|
const newPrivateRules = {
|
|
454
403
|
required,
|
|
455
404
|
before,
|
|
@@ -459,13 +408,7 @@ export default Behavior({
|
|
|
459
408
|
};
|
|
460
409
|
if (equal(newPrivateRules, this.data._privateRules)) return;
|
|
461
410
|
this.data._privateRules = newPrivateRules;
|
|
462
|
-
let privateRules = convertRules(
|
|
463
|
-
required,
|
|
464
|
-
before,
|
|
465
|
-
after,
|
|
466
|
-
requiredMsg,
|
|
467
|
-
isUnionValue
|
|
468
|
-
);
|
|
411
|
+
let privateRules = convertRules(required, before, after, requiredMsg, isUnionValue);
|
|
469
412
|
this.setData({ privateRules });
|
|
470
413
|
},
|
|
471
414
|
},
|