@cloudbase/weda-ui-mp 3.15.6 → 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
- if (form) {
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
- (w) => w.getConfig?.()?.componentType === 'form'
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
  },
@@ -2,7 +2,7 @@
2
2
  width: 200px;
3
3
  height: 200px;
4
4
  position: fixed;
5
- left: 100%;
5
+ left: 200%;
6
6
  }
7
7
  .wd-qrcode--image {
8
8
  width: 200px;
@@ -195,20 +195,29 @@ Component({
195
195
  * @returns
196
196
  */
197
197
  getTempValue(value) {
198
+ // 处理数组
198
199
  if (Array.isArray(value)) {
199
- return value.map((i = {}) => {
200
- const item = {};
201
- Object.keys(i).forEach((j) => {
202
- if (j) {
203
- item[j] = i[j] || null;
204
- }
205
- });
206
- return item;
200
+ return value.map((element) => {
201
+ if (typeof element === 'object' && element !== null) {
202
+ const obj = typeof element === 'object' && element !== null ? element : {};
203
+ const cleaned = {};
204
+ Object.keys(obj).forEach((key) => {
205
+ cleaned[key] = obj[key] === null || obj[key] === undefined || obj[key] === '' ? null : obj[key];
206
+ });
207
+ return cleaned;
208
+ }
209
+ return element;
207
210
  });
208
211
  }
212
+ // 处理单个对象
213
+
214
+ // 非数组/对象直接返回
209
215
  return value;
210
216
  },
211
217
  change(params, { isUpdateParentForm = false, isUpdateChildValue = true } = {}) {
218
+ if (this.data.disabled || this.data.readOnly) {
219
+ return;
220
+ }
212
221
  const { objValue, name, addDefaultValue } = this.data;
213
222
  let value = deepClone(params.value);
214
223
 
@@ -1,5 +1,5 @@
1
1
  <block wx:if="{{visible}}">
2
- <wd-form-item-obj id="{{id}}" mode="{{mode}}" className="{{className}}" style="{{style}}" label="{{label}}" labelVisible="{{labelVisible}}" labelTips="{{labelTips}}" labelWidth="{{labelWidth}}" labelAlign="{{labelAlign}}" labelWrap="{{labelWrap}}" extra="{{extra}}" classRoot="{{classRoot}}" layout="{{_layout}}">
2
+ <wd-form-item-obj id="{{id}}" mode="{{mode}}" className="{{className}}" style="{{style}}" label="{{label}}" labelVisible="{{labelVisible}}" labelTips="{{labelTips}}" labelWidth="{{labelWidth}}" labelAlign="{{labelAlign}}" labelWrap="{{labelWrap}}" extra="{{extra}}" classRoot="{{classRoot}}" layout="{{_layout}}" status="{{status}}">
3
3
  <slot></slot>
4
4
  </wd-form-item-obj>
5
5
  </block>
@@ -2,12 +2,7 @@ import { WD_PREFIX } from '../../utils/constant';
2
2
  import { textToString } from '../../utils/platform';
3
3
  import classNames from '../../utils/classnames';
4
4
  import itemBehavior from '../form-field-behavior/item-behavior';
5
- import {
6
- convertSize,
7
- convertLayout,
8
- convertLabelAlign,
9
- convertPx,
10
- } from '../../utils/getFormLegacy';
5
+ import { convertSize, convertLayout, convertLabelAlign, convertPx } from '../../utils/getFormLegacy';
11
6
 
12
7
  Component({
13
8
  options: { virtualHost: true, styleIsolation: 'shared' },
@@ -36,13 +31,12 @@ Component({
36
31
  methods: {
37
32
  setIconName() {
38
33
  this.setData({
39
- iconName:
40
- this.data.iconName === 'chevrondown' ? 'chevronup' : 'chevrondown',
34
+ iconName: this.data.iconName === 'chevrondown' ? 'chevronup' : 'chevrondown',
41
35
  });
42
36
  },
43
37
  },
44
38
  observers: {
45
- 'className,labelWidth,labelAlign,labelWrap,layout,required,requiredFlag,size,classRoot,borderedH5,disabled,controlAlign':
39
+ 'className,labelWidth,labelAlign,labelWrap,layout,required,requiredFlag,size,classRoot,borderedH5,disabled,controlAlign,status':
46
40
  function (
47
41
  className,
48
42
  _labelWidth,
@@ -55,7 +49,8 @@ Component({
55
49
  classRoot,
56
50
  borderedH5,
57
51
  disabled,
58
- controlAlign
52
+ controlAlign,
53
+ status,
59
54
  ) {
60
55
  const { item, itemWrap, classPrefix } = this.data;
61
56
  const sizeTemp = convertSize(_size);
@@ -66,26 +61,20 @@ Component({
66
61
  const labelRoot = `${root}__label`;
67
62
  const labelWidth = convertPx(_labelWidth);
68
63
  const labelStyle = labelWidth ? `width:${labelWidth}` : '';
69
- const itemLayout = this.properties.isWdFormDetail
70
- ? `${classPrefix}-form-item--detail`
71
- : `${item}-`;
64
+ const itemLayout = this.properties.isWdFormDetail ? `${classPrefix}-form-item--detail` : `${item}-`;
72
65
  const cls = classNames(
73
66
  item,
74
67
  className,
75
- `${classPrefix}-mp-form-item ${item}--weui item-size-height-${size} ${root}-root ${classPrefix}-mp-${classRoot}-root ${classPrefix}-mp-form-item-obj`,
68
+ `${classPrefix}-mp-form-item ${item}--weui item-size-height-${size} ${root}-root ${classPrefix}-mp-${classRoot}-root ${classPrefix}-mp-form-item-obj ${classPrefix}-mp-form-obj-${status}`,
76
69
  {
77
70
  'is-required': requiredFlag && required,
78
71
  'is-borderless': !borderedH5,
79
- [`${itemLayout}-horizontal-left`]:
80
- layout === 'horizontal' && labelAlign === 'left',
81
- [`${itemLayout}-horizontal-right`]:
82
- layout === 'horizontal' && labelAlign === 'right',
83
- [`${itemLayout}-vertical-left`]:
84
- layout === 'vertical' && labelAlign === 'left',
85
- [`${itemLayout}-vertical-right`]:
86
- layout === 'vertical' && labelAlign === 'right',
72
+ [`${itemLayout}-horizontal-left`]: layout === 'horizontal' && labelAlign === 'left',
73
+ [`${itemLayout}-horizontal-right`]: layout === 'horizontal' && labelAlign === 'right',
74
+ [`${itemLayout}-vertical-left`]: layout === 'vertical' && labelAlign === 'left',
75
+ [`${itemLayout}-vertical-right`]: layout === 'vertical' && labelAlign === 'right',
87
76
  [`${item}--label-${labelAlign}`]: !!labelAlign,
88
- }
77
+ },
89
78
  );
90
79
  const labelCls = classNames(`${itemWrap}__label`, labelRoot, {
91
80
  'is-nowrap': !labelWrap,
@@ -104,12 +93,7 @@ Component({
104
93
  controlWrapCls,
105
94
  });
106
95
  },
107
- 'readBeforeAfter,before,after,readValue': function (
108
- readBeforeAfter,
109
- before,
110
- after,
111
- readValue
112
- ) {
96
+ 'readBeforeAfter,before,after,readValue': function (readBeforeAfter, before, after, readValue) {
113
97
  const _readValue = textToString(readValue);
114
98
  const _before = readBeforeAfter && textToString(before);
115
99
  const _after = readBeforeAfter && textToString(after);
@@ -1,2 +1,7 @@
1
1
  @import '../../style/wd-design.wxss';
2
2
  @import './wd-form-item.wxss';
3
+
4
+ .wd-mp-form-obj-readOnly,
5
+ .wd-mp-form-obj-disabled {
6
+ pointer-events: none;
7
+ }
@@ -15,8 +15,7 @@ import equal from '../../utils/deepEqual';
15
15
  * @param currentName 当前表单项名称
16
16
  * @returns
17
17
  */
18
- const getValueName = (operateName, currentName) =>
19
- operateName.replace(new RegExp(`^${currentName}(\\.)?`), '');
18
+ const getValueName = (operateName, currentName) => operateName.replace(new RegExp(`^${currentName}(\\.)?`), '');
20
19
 
21
20
  Component({
22
21
  options: { virtualHost: true },
@@ -86,14 +85,10 @@ Component({
86
85
  * @returns
87
86
  */
88
87
  addFormItem(childName, formItem) {
89
- if (
90
- isNil(childName) ||
91
- !formItem ||
92
- (typeof childName === 'string' && childName.length === 0)
93
- ) {
88
+ if (isNil(childName) || !formItem || (typeof childName === 'string' && childName.length === 0)) {
94
89
  // childName 没设置或为空串的时候不受表单容器控制
95
90
  console.warn(
96
- `组件 #${formItem?.id} 表单key(表单输入类组件 childName 属性)没设置或为空串的时候不受表单容器控制`
91
+ `组件 #${formItem?.id} 表单key(表单输入类组件 childName 属性)没设置或为空串的时候不受表单容器控制`,
97
92
  );
98
93
  return noop;
99
94
  }
@@ -105,9 +100,7 @@ Component({
105
100
  }
106
101
  that.setData({ formsItemMap });
107
102
  return () => {
108
- const removedArr = formsItemMap[childName].filter(
109
- (item) => item !== formItem
110
- );
103
+ const removedArr = formsItemMap[childName].filter((item) => item !== formItem);
111
104
  if (removedArr.length <= 0) {
112
105
  delete formsItemMap[childName];
113
106
  } else {
@@ -121,8 +114,7 @@ Component({
121
114
  },
122
115
  methods: {
123
116
  updateWidgetAPI(apis = {}) {
124
- const { name, objValue, label, visible, readOnly, disabled, status } =
125
- this.data;
117
+ const { name, objValue, label, visible, readOnly, disabled, status } = this.data;
126
118
  this.setReadonlyAttributes?.({
127
119
  ...apis,
128
120
  label,
@@ -140,16 +132,12 @@ Component({
140
132
  },
141
133
  // 父级普通表单对象
142
134
  getParentForm() {
143
- const parent = this?.$widget?.closest(
144
- (w) => w.getConfig?.().componentType === 'form'
145
- );
135
+ const parent = this?.$widget?.closest((w) => w.getConfig?.().componentType === 'form');
146
136
  return parent;
147
137
  },
148
138
  // 父级嵌套表单对象
149
139
  getParentFormObj() {
150
- const parent = this?.$widget?.closest(
151
- (w) => w.getConfig?.().componentType === 'formObj'
152
- );
140
+ const parent = this?.$widget?.closest((w) => w.getConfig?.().componentType === 'formObj');
153
141
  return parent;
154
142
  },
155
143
  /**
@@ -169,10 +157,7 @@ Component({
169
157
  if (!Array.isArray(items)) {
170
158
  items = [items];
171
159
  }
172
- const newValue = lodashGet(
173
- value,
174
- getValueName(childName, this.data.name)
175
- );
160
+ const newValue = lodashGet(value, getValueName(childName, this.data.name));
176
161
  items.forEach((item) => {
177
162
  if (item?.setValue && !equal(item.value, newValue)) {
178
163
  item.setValue(newValue);
@@ -189,10 +174,10 @@ Component({
189
174
  * @param param1.isUpdateChildValue 是否更新子组件值, 因子组件值变化调用change时不去触发updateChildValueWithoutForm;因为外部设置了值,则触发updateChildValueWithoutForm去更新子组件值
190
175
  * @returns
191
176
  */
192
- change(
193
- params,
194
- { isUpdateParentForm = false, isUpdateChildValue = true } = {}
195
- ) {
177
+ change(params, { isUpdateParentForm = false, isUpdateChildValue = true } = {}) {
178
+ if (this.data.disabled || this.data.readOnly) {
179
+ return;
180
+ }
196
181
  const { objValue, name } = this.data;
197
182
  let value = deepClone(params.value);
198
183
 
@@ -260,9 +245,7 @@ Component({
260
245
 
261
246
  if (params.name) {
262
247
  // 判断是否将当前的name前缀加上,以便父级嵌套表单更新值
263
- const nameTemp = `${
264
- !params.name.startsWith(name) && name ? `${name}.` : ''
265
- }${params.name}`;
248
+ const nameTemp = `${!params.name.startsWith(name) && name ? `${name}.` : ''}${params.name}`;
266
249
  // 将值同步给父级嵌套表单
267
250
  parentFormObj?.__setValueImmediate__?.({
268
251
  name: nameTemp,
@@ -1,5 +1,5 @@
1
1
  <block wx:if="{{visible}}">
2
- <wd-form-item-obj id="{{id}}" mode="{{mode}}" className="{{className}}" style="{{style}}" label="{{label}}" labelVisible="{{labelVisible}}" labelTips="{{labelTips}}" labelWidth="{{labelWidth}}" labelAlign="{{labelAlign}}" labelWrap="{{labelWrap}}" extra="{{extra}}" classRoot="{{classRoot}}" layout="{{_layout}}">
2
+ <wd-form-item-obj id="{{id}}" mode="{{mode}}" className="{{className}}" style="{{style}}" label="{{label}}" labelVisible="{{labelVisible}}" labelTips="{{labelTips}}" labelWidth="{{labelWidth}}" labelAlign="{{labelAlign}}" labelWrap="{{labelWrap}}" extra="{{extra}}" classRoot="{{classRoot}}" layout="{{_layout}}" status="{{status}}">
3
3
  <slot></slot>
4
4
  </wd-form-item-obj>
5
5
  </block>
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "miniprogram": "./",
4
4
  "packageManager": "yarn@3.0.2",
5
5
  "dependencies": {},
6
- "version": "3.15.6",
6
+ "version": "3.15.8",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"