@cloudbase/weda-ui-mp 3.15.6 → 3.15.7

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.
@@ -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.7",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"