@cloudbase/weda-ui-mp 3.15.2 → 3.15.3

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.
@@ -16,8 +16,7 @@ import equal from '../../utils/deepEqual';
16
16
  * @param currentName 当前表单项名称
17
17
  * @returns
18
18
  */
19
- const getValueName = (operateName, currentName) =>
20
- operateName.replace(new RegExp(`^${currentName}(\\.)?`), '');
19
+ const getValueName = (operateName, currentName) => operateName.replace(new RegExp(`^${currentName}(\\.)?`), '');
21
20
 
22
21
  Component({
23
22
  options: { virtualHost: true },
@@ -64,10 +63,7 @@ Component({
64
63
  that.change({ type: 'add' }, { isUpdateParentForm: false });
65
64
  },
66
65
  remove({ index = -1 } = {}) {
67
- that.change(
68
- { type: 'remove', value: index },
69
- { isUpdateParentForm: false }
70
- );
66
+ that.change({ type: 'remove', value: index }, { isUpdateParentForm: false });
71
67
  },
72
68
  change(params) {
73
69
  that.change(params, { isUpdateParentForm: true });
@@ -100,14 +96,10 @@ Component({
100
96
  * @returns
101
97
  */
102
98
  addFormItem(childName, formItem) {
103
- if (
104
- isNil(childName) ||
105
- !formItem ||
106
- (typeof childName === 'string' && childName.length === 0)
107
- ) {
99
+ if (isNil(childName) || !formItem || (typeof childName === 'string' && childName.length === 0)) {
108
100
  // childName 没设置或为空串的时候不受表单容器控制
109
101
  console.warn(
110
- `组件 #${formItem?.id} 表单key(表单输入类组件 childName 属性)没设置或为空串的时候不受表单容器控制`
102
+ `组件 #${formItem?.id} 表单key(表单输入类组件 childName 属性)没设置或为空串的时候不受表单容器控制`,
111
103
  );
112
104
  return noop;
113
105
  }
@@ -119,9 +111,7 @@ Component({
119
111
  }
120
112
  that.setData({ formsItemMap });
121
113
  return () => {
122
- const removedArr = formsItemMap[childName].filter(
123
- (item) => item !== formItem
124
- );
114
+ const removedArr = formsItemMap[childName].filter((item) => item !== formItem);
125
115
  if (removedArr.length <= 0) {
126
116
  delete formsItemMap[childName];
127
117
  } else {
@@ -144,8 +134,7 @@ Component({
144
134
  });
145
135
  },
146
136
  updateWidgetAPI(apis = {}) {
147
- const { name, objValue, label, visible, readOnly, disabled, status } =
148
- this.data;
137
+ const { name, objValue, label, visible, readOnly, disabled, status } = this.data;
149
138
  this.setReadonlyAttributes?.({
150
139
  ...apis,
151
140
  label,
@@ -163,16 +152,12 @@ Component({
163
152
  },
164
153
  // 父级普通表单对象
165
154
  getParentForm() {
166
- const parent = this?.$widget?.closest(
167
- (w) => w.getConfig?.().componentType === 'form'
168
- );
155
+ const parent = this?.$widget?.closest((w) => w.getConfig?.().componentType === 'form');
169
156
  return parent;
170
157
  },
171
158
  // 父级嵌套表单对象
172
159
  getParentFormObj() {
173
- const parent = this?.$widget?.closest(
174
- (w) => w.getConfig?.().componentType === 'formObj'
175
- );
160
+ const parent = this?.$widget?.closest((w) => w.getConfig?.().componentType === 'formObj');
176
161
  return parent;
177
162
  },
178
163
  /**
@@ -192,10 +177,7 @@ Component({
192
177
  if (!Array.isArray(items)) {
193
178
  items = [items];
194
179
  }
195
- const newValue = lodashGet(
196
- value,
197
- getValueName(childName, this.data.name)
198
- );
180
+ const newValue = lodashGet(value, getValueName(childName, this.data.name));
199
181
  items.forEach((item) => {
200
182
  if (item?.setValue && !equal(item.value, newValue)) {
201
183
  item.setValue(newValue);
@@ -226,10 +208,7 @@ Component({
226
208
  }
227
209
  return value;
228
210
  },
229
- change(
230
- params,
231
- { isUpdateParentForm = false, isUpdateChildValue = true } = {}
232
- ) {
211
+ change(params, { isUpdateParentForm = false, isUpdateChildValue = true } = {}) {
233
212
  const { objValue, name, addDefaultValue } = this.data;
234
213
  let value = deepClone(params.value);
235
214
 
@@ -244,10 +223,7 @@ Component({
244
223
  // 触发删除操作,则删除对应索引的值
245
224
  if (params.type === 'remove') {
246
225
  value = deepClone(objValue);
247
- value = [
248
- ...value.slice(0, params.value),
249
- ...value.slice(params.value + 1),
250
- ];
226
+ value = [...value.slice(0, params.value), ...value.slice(params.value + 1)];
251
227
  }
252
228
  }
253
229
 
@@ -294,8 +270,6 @@ Component({
294
270
  // 外部直接调用formObj.setValue的情况下,触发父级嵌套表单值更新
295
271
  parentFormObj?.__setValueImmediate__?.({ name, value });
296
272
  }
297
-
298
- this.triggerOnDataChange(value);
299
273
  },
300
274
  /**
301
275
  * 子组件默认值变更,触发嵌套表单值更新
@@ -320,9 +294,7 @@ Component({
320
294
 
321
295
  if (params.name) {
322
296
  // 判断是否将当前的name前缀加上,以便父级嵌套表单更新值
323
- const nameTemp = `${
324
- !params.name.startsWith(name) && name ? `${name}.` : ''
325
- }${params.name}`;
297
+ const nameTemp = `${!params.name.startsWith(name) && name ? `${name}.` : ''}${params.name}`;
326
298
  // 将值同步给父级嵌套表单
327
299
  parentFormObj?.__setValueImmediate__?.({
328
300
  name: nameTemp,
@@ -361,7 +333,7 @@ Component({
361
333
  this.change({ value }, { isUpdateParentForm: true });
362
334
  });
363
335
  },
364
- objValue: function () {
336
+ objValue: function (value) {
365
337
  this.updateWidgetAPI();
366
338
  // 更新子组件的值需要主动去调用,不被动执行
367
339
  // 如果是最顶层的嵌套表单,则去更新子组件的值,否则自己的值更新不去触发子组件值更新,因为父级普通表单会去更新
@@ -369,6 +341,10 @@ Component({
369
341
  // if (!parentFormObj) {
370
342
  // // this.updateChildValue(objValue);
371
343
  // }
344
+ const tempValue = this.getTempValue(value);
345
+ if (equal(tempValue, this.data.objValue)) {
346
+ this.triggerOnDataChange(value);
347
+ }
372
348
  },
373
349
  },
374
350
  });
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.2",
6
+ "version": "3.15.3",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"