@cloudbase/weda-ui-mp 3.6.3 → 3.7.1
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/components/form/form/wd-form.wxss +15 -0
- package/components/form/uploader/index.js +3 -3
- package/components/form/uploader/weui-uploader.wxml +1 -1
- package/components/form/uploader/weui-uploader.wxss +4 -0
- package/components/form-field-behavior/form-field-behavior.js +38 -7
- package/components/form-field-behavior/validator.js +3 -2
- package/components/form-phone/index.wxml +1 -1
- package/components/formdetail/wd-form-detail.wxss +5 -0
- package/components/tooltip/wd-tooltip.wxss +6 -0
- package/components/wd-button/wd-button.wxss +6 -0
- package/components/wd-card/wd-card.wxss +6 -0
- package/components/wd-cascader/index.js +198 -0
- package/components/wd-cascader/index.json +12 -0
- package/components/wd-cascader/index.wxml +59 -0
- package/components/wd-cascader/index.wxss +2 -0
- package/components/wd-cascader/utils.js +70 -0
- package/components/wd-cascader/wd-cascader.wxss +284 -0
- package/components/wd-checkbox-list/wd-checkbox-list.wxss +6 -0
- package/components/wd-date/modal/index.js +4 -1
- package/components/wd-date/modal/index.wxml +1 -1
- package/components/wd-date/wd-date.wxss +5 -0
- package/components/wd-date-range/wd-date-range.wxss +5 -0
- package/components/wd-divider/wd-divider.wxss +6 -0
- package/components/wd-form/form-utils.js +4 -0
- package/components/wd-form/wd-form.wxss +15 -0
- package/components/wd-form-arr/index.js +330 -0
- package/components/wd-form-arr/index.json +7 -0
- package/components/wd-form-arr/index.wxml +5 -0
- package/components/wd-form-arr/index.wxss +2 -0
- package/components/wd-form-arr/wd-form-obj.wxss +51 -0
- package/components/wd-form-item/wd-form-item.wxss +15 -0
- package/components/wd-form-item-obj/index.js +113 -0
- package/components/wd-form-item-obj/index.json +8 -0
- package/components/wd-form-item-obj/index.wxml +51 -0
- package/components/wd-form-item-obj/index.wxss +2 -0
- package/components/wd-form-item-obj/wd-form-item.wxss +1106 -0
- package/components/wd-form-obj/index.js +305 -0
- package/components/wd-form-obj/index.json +7 -0
- package/components/wd-form-obj/index.wxml +5 -0
- package/components/wd-form-obj/index.wxss +2 -0
- package/components/wd-form-obj/wd-form-obj.wxss +51 -0
- package/components/wd-icon/index.json +1 -1
- package/components/wd-icon/wd-icon.wxss +6 -0
- package/components/wd-image/wd-image.wxss +6 -0
- package/components/wd-input/inner-input/wd-input.wxss +15 -0
- package/components/wd-input-group/wd-input-group.wxss +6 -0
- package/components/wd-input-number/wd-input-number.wxss +6 -0
- package/components/wd-input-wrap/wd-input-wrap.wxss +6 -0
- package/components/wd-layout/wd-layout.wxss +6 -0
- package/components/wd-menu-layout/wd-menu-layout.wxss +5 -0
- package/components/wd-menu-list/wd-menu-list.wxss +5 -0
- package/components/wd-modal/wd-modal.wxss +6 -0
- package/components/wd-progress/wd-progress.wxss +15 -0
- package/components/wd-radio-list/wd-radio-list.wxss +6 -0
- package/components/wd-rating/wd-rating.wxss +15 -0
- package/components/wd-select/select.wxss +14 -3
- package/components/wd-switch/wd-switch.wxss +15 -0
- package/components/wd-tabbar/wd-tabbar.wxss +6 -0
- package/components/wd-tabs/wd-tabs.wxss +6 -0
- package/components/wd-tag/wd-tag.wxss +6 -0
- package/components/wd-tag-select/wd-tag-select.wxss +15 -0
- package/components/wd-text/wd-text.wxss +5 -0
- package/components/wd-textarea/wd-textarea.wxss +6 -0
- package/components/wd-time/wd-time.wxss +5 -0
- package/components/wd-unified-link/wd-link.wxss +6 -0
- package/components/web-view/index.js +3 -0
- package/index.json +2 -0
- package/package.json +1 -1
- package/style/utils.wxss +5 -0
- package/style/wd-design.wxss +5 -0
- package/utils/enum.js +13 -0
- package/components/dataView/index.wxss +0 -0
- package/components/wd-audio/index.wxss +0 -0
- package/components/wd-date/calendar/index.wxss +0 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
@charset "UTF-8";
|
|
2
|
+
._B00_Xa {
|
|
3
|
+
/* 如果生成的wxss 为空文件似乎会导致IDE编译报错, 所以这里给他弄个占位 */
|
|
4
|
+
word-break: inherit;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.wd-cascader,
|
|
8
|
+
.wd-cascader-menu,
|
|
9
|
+
.wd-cascader-h5-view-list__menu {
|
|
10
|
+
--wd-cascader-font-size: var(--wd-font-size-default);
|
|
11
|
+
--wd-cascader-border-radius: var(--wd-border-radius);
|
|
12
|
+
--wd-cascader-color-text: var(--wd-color-text-default);
|
|
13
|
+
--wd-cascader-color-bg: var(--wd-color-bg-form-default);
|
|
14
|
+
--wd-cascader-color-bg-hover: var(--wd-color-bg-form-default);
|
|
15
|
+
--wd-cascader-menu-li-color-bg-hover: var(--wd-color-bg-container-hover);
|
|
16
|
+
--wd-cascader-menu-li-color-bg-selected: var(--wd-color-brand-light);
|
|
17
|
+
--wd-cascader-menu-li-color-text-disabled: var(--wd-color-text-disabled);
|
|
18
|
+
--wd-cascader-menu-li-color-text-selected: var(--wd-color-brand);
|
|
19
|
+
--wd-cascader-color-border: var(--wd-color-border-form-default);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.wd-cascader,
|
|
23
|
+
.wd-cascader-menu,
|
|
24
|
+
.wd-cascader-h5-view-list__menu {
|
|
25
|
+
--wd-cascader-font-size: var(--wd-font-size-default);
|
|
26
|
+
--wd-cascader-border-radius: var(--wd-border-radius);
|
|
27
|
+
--wd-cascader-color-text: var(--wd-color-text-default);
|
|
28
|
+
--wd-cascader-color-bg: var(--wd-color-bg-form-default);
|
|
29
|
+
--wd-cascader-color-bg-hover: var(--wd-color-bg-form-default);
|
|
30
|
+
--wd-cascader-menu-li-color-bg-hover: var(--wd-color-bg-container-hover);
|
|
31
|
+
--wd-cascader-menu-li-color-bg-selected: var(--wd-color-brand-light);
|
|
32
|
+
--wd-cascader-menu-li-color-text-disabled: var(--wd-color-text-disabled);
|
|
33
|
+
--wd-cascader-menu-li-color-text-selected: var(--wd-color-brand);
|
|
34
|
+
--wd-cascader-color-border: var(--wd-color-border-form-default);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.wd-form-region-wrap {
|
|
38
|
+
color: var(--wd-color-text-default);
|
|
39
|
+
font-size: var(--wd-font-size-default);
|
|
40
|
+
line-height: var(--wd-font-line-height-default);
|
|
41
|
+
box-sizing: border-box;
|
|
42
|
+
margin: 0;
|
|
43
|
+
padding: 0;
|
|
44
|
+
list-style: none;
|
|
45
|
+
padding: 0 0.5rem 0 0;
|
|
46
|
+
}
|
|
47
|
+
.wd-form-region-wrap .wd-form-region__input {
|
|
48
|
+
font-size: 16px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.wd-cascader {
|
|
52
|
+
display: inline-flex;
|
|
53
|
+
vertical-align: middle;
|
|
54
|
+
position: relative;
|
|
55
|
+
border: none;
|
|
56
|
+
width: 100%;
|
|
57
|
+
height: 100%;
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
color: var(--wd-cascader-color-text);
|
|
60
|
+
transition: 0.2s ease-in-out;
|
|
61
|
+
transition-property: color, background-color, border;
|
|
62
|
+
padding-left: 0.5rem;
|
|
63
|
+
}
|
|
64
|
+
.wd-cascader__input {
|
|
65
|
+
height: 100%;
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
}
|
|
69
|
+
.wd-cascader .wd-icon-arrowdown {
|
|
70
|
+
display: none;
|
|
71
|
+
}
|
|
72
|
+
.wd-cascader .wd-tag {
|
|
73
|
+
margin-top: calc((var(--wd-form-height-md) - 20) / 2);
|
|
74
|
+
}
|
|
75
|
+
.wd-cascader .wd-input--editor {
|
|
76
|
+
position: relative;
|
|
77
|
+
padding: 0;
|
|
78
|
+
height: 24px;
|
|
79
|
+
line-height: 24px;
|
|
80
|
+
width: 26px;
|
|
81
|
+
top: calc((var(--wd-form-height-md) - 26) / 2);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.wd-cascader__input .wd-input[readonly],
|
|
85
|
+
.wd-cascader__input .wd-input {
|
|
86
|
+
background-color: transparent;
|
|
87
|
+
border: 0;
|
|
88
|
+
position: absolute;
|
|
89
|
+
height: calc(var(--wd-form-height-md) - 4);
|
|
90
|
+
line-height: calc(var(--wd-form-height-md) - 4);
|
|
91
|
+
top: 0px;
|
|
92
|
+
left: 0.5rem;
|
|
93
|
+
z-index: 1;
|
|
94
|
+
right: 0px;
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
height: 100%;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.wd-cascader__input .wd-input {
|
|
100
|
+
z-index: 2;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.wd-cascader__input .wd-input--editor {
|
|
104
|
+
position: relative;
|
|
105
|
+
padding: 0;
|
|
106
|
+
height: 24px;
|
|
107
|
+
line-height: 24px;
|
|
108
|
+
width: 26px;
|
|
109
|
+
top: calc((var(--wd-form-height-md) - 26) / 2);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.wd-cascader__value {
|
|
113
|
+
line-height: calc(var(--wd-form-height-md) - 2);
|
|
114
|
+
font-size: var(--wd-cascader-font-size);
|
|
115
|
+
white-space: nowrap;
|
|
116
|
+
overflow: hidden;
|
|
117
|
+
position: relative;
|
|
118
|
+
z-index: 2;
|
|
119
|
+
}
|
|
120
|
+
.wd-cascader__value .wd-tag-group {
|
|
121
|
+
margin-top: 0px;
|
|
122
|
+
margin-bottom: 4px;
|
|
123
|
+
white-space: normal;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.wd-cascader > .wd-icon,
|
|
127
|
+
.wd-cascader .wd-icon-arrowdown {
|
|
128
|
+
position: absolute;
|
|
129
|
+
z-index: 2;
|
|
130
|
+
right: 4px;
|
|
131
|
+
top: calc((var(--wd-form-height-md) - 16 - 2) / 2);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.wd-cascader.is-disabled {
|
|
135
|
+
background-color: var(--wd-color-bg-form-disabled);
|
|
136
|
+
cursor: not-allowed;
|
|
137
|
+
}
|
|
138
|
+
.wd-cascader.is-disabled .wd-cascader__value {
|
|
139
|
+
color: var(--wd-color-text-form-disabled);
|
|
140
|
+
}
|
|
141
|
+
.wd-cascader.is-disabled .wd-cascader__input .wd-input {
|
|
142
|
+
cursor: inherit;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.wd-cascader-menu {
|
|
146
|
+
min-width: 198px;
|
|
147
|
+
box-sizing: border-box;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.wd-cascader-menu .wd-tabs--bordered .wd-tabs__tab {
|
|
151
|
+
font-size: var(--wd-cascader-font-size);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.wd-cascader-menu__list {
|
|
155
|
+
padding: 0 5px 0 15px;
|
|
156
|
+
font-size: 0;
|
|
157
|
+
width: 500px;
|
|
158
|
+
margin-bottom: -10px;
|
|
159
|
+
max-height: 280px;
|
|
160
|
+
overflow-y: auto;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.wd-cascader-menu__list li {
|
|
164
|
+
font-size: var(--wd-cascader-font-size);
|
|
165
|
+
line-height: 1.5;
|
|
166
|
+
margin-bottom: 8px;
|
|
167
|
+
display: inline-block;
|
|
168
|
+
vertical-align: middle;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.wd-cascader-menu__col4 .wd-cascader-menu__list li {
|
|
172
|
+
width: 116px;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.wd-cascader-menu__col2 .wd-cascader-menu__list li {
|
|
176
|
+
width: 232px;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.wd-cascader-menu__col1 .wd-cascader-menu__list li {
|
|
180
|
+
width: 100%;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.wd-cascader-menu__col1 .wd-cascader-menu__list {
|
|
184
|
+
width: 350px;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.wd-cascader-menu__label {
|
|
188
|
+
padding: 1px 5px;
|
|
189
|
+
cursor: pointer;
|
|
190
|
+
margin-right: 10px;
|
|
191
|
+
word-break: keep-all;
|
|
192
|
+
white-space: nowrap;
|
|
193
|
+
overflow: hidden;
|
|
194
|
+
text-overflow: ellipsis;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.wd-cascader-menu__label:hover {
|
|
198
|
+
background-color: var(--wd-cascader-menu-li-color-bg-hover);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.wd-cascader-menu__label.is-selected {
|
|
202
|
+
background-color: --wd-cascader-menu-li-color-bg-selected;
|
|
203
|
+
color: var(--wd-color-text-inverse);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.wd-cascader-menu__label.is-disabled {
|
|
207
|
+
color: var(--wd-cascader-menu-li-color-text-disabled);
|
|
208
|
+
}
|
|
209
|
+
.wd-cascader-menu__label.is-disabled:hover {
|
|
210
|
+
background-color: transparent;
|
|
211
|
+
cursor: not-allowed;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.wd-cascader--search .wd-input {
|
|
215
|
+
border: none;
|
|
216
|
+
}
|
|
217
|
+
.wd-cascader-menu--thin {
|
|
218
|
+
display: flex;
|
|
219
|
+
min-width: 0;
|
|
220
|
+
}
|
|
221
|
+
.wd-cascader-menu--thin .wd-list {
|
|
222
|
+
min-width: 160px;
|
|
223
|
+
max-height: 194px;
|
|
224
|
+
border-left: 1px solid var(--wd-color-border-separator);
|
|
225
|
+
}
|
|
226
|
+
.wd-cascader-menu--thin .wd-list:first-child {
|
|
227
|
+
border-left: none;
|
|
228
|
+
}
|
|
229
|
+
.wd-cascader-menu--thin .wd-list > li {
|
|
230
|
+
position: relative;
|
|
231
|
+
}
|
|
232
|
+
.wd-cascader-menu--thin .wd-list__submenu {
|
|
233
|
+
padding-right: 24px;
|
|
234
|
+
}
|
|
235
|
+
.wd-cascader-menu--thin .wd-list__submenu::after {
|
|
236
|
+
top: 50%;
|
|
237
|
+
margin-top: -8px;
|
|
238
|
+
}
|
|
239
|
+
.wd-cascader-menu--thin .wd-list__submenu.is-selected::after {
|
|
240
|
+
display: flex;
|
|
241
|
+
align-items: center;
|
|
242
|
+
justify-content: center;
|
|
243
|
+
font-family: "t";
|
|
244
|
+
content: ">";
|
|
245
|
+
content: "\e0f7";
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.wd-cascader-modal .wd-tabs-h5-root .wd-tabs__header-item-content {
|
|
249
|
+
width: auto;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.wd-cascader-h5-multiple-view {
|
|
253
|
+
height: 260px;
|
|
254
|
+
padding: 8px 16px;
|
|
255
|
+
overflow: auto;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.wd-cascader-h5-view-list {
|
|
259
|
+
padding: 8px;
|
|
260
|
+
overflow: auto;
|
|
261
|
+
height: 260px;
|
|
262
|
+
}
|
|
263
|
+
.wd-cascader-h5-view-list__menu {
|
|
264
|
+
display: flex;
|
|
265
|
+
padding: 0 8px;
|
|
266
|
+
justify-content: space-between;
|
|
267
|
+
align-items: center;
|
|
268
|
+
cursor: pointer;
|
|
269
|
+
}
|
|
270
|
+
.wd-cascader-h5-view-list__menu__text {
|
|
271
|
+
display: inline-block;
|
|
272
|
+
padding: 8px 0;
|
|
273
|
+
}
|
|
274
|
+
.wd-cascader-h5-view-list__menu.is-selected {
|
|
275
|
+
color: var(--wd-cascader-menu-li-color-text-selected);
|
|
276
|
+
}
|
|
277
|
+
.wd-cascader-h5-view-list__menu.is-disabled {
|
|
278
|
+
color: var(--wd-cascader-menu-li-color-text-disabled);
|
|
279
|
+
cursor: not-allowed;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.wd-h5-cascader-root .wd-form-input-wrap {
|
|
283
|
+
font-size: var(--wd-font-size-4);
|
|
284
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<view class="{{classPrefix}}-custom-picker" wx:if="{{visible}}">
|
|
1
|
+
<view class="{{classPrefix}}-custom-picker {{className}}" wx:if="{{visible}}">
|
|
2
2
|
<view class="{{classPrefix}}-custom-backdrop" bind:tap="handleClose"></view>
|
|
3
3
|
|
|
4
4
|
<view class="{{classPrefix}}-custom-picker__inner">
|
|
@@ -27,6 +27,10 @@ export function getFormDataFromItemMap(formItemMap, formType) {
|
|
|
27
27
|
if (w.getConfig?.()?.componentType === 'formdetail') {
|
|
28
28
|
return acc;
|
|
29
29
|
}
|
|
30
|
+
// 如果位于嵌套表单内,则跳过赋值,交给嵌套表单处理
|
|
31
|
+
if (w.closest((ww) => ww.getConfig?.().componentType === 'formObj')) {
|
|
32
|
+
return acc;
|
|
33
|
+
}
|
|
30
34
|
lodashSet(acc, k, w?.getValue?.());
|
|
31
35
|
});
|
|
32
36
|
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
@charset "UTF-8";
|
|
2
|
+
._B00_Xa {
|
|
3
|
+
/* 如果生成的wxss 为空文件似乎会导致IDE编译报错, 所以这里给他弄个占位 */
|
|
4
|
+
word-break: inherit;
|
|
5
|
+
}
|
|
6
|
+
|
|
2
7
|
.wd-form,
|
|
3
8
|
.wd-form-item,
|
|
4
9
|
.gsd-h5-react-formitem {
|
|
@@ -1088,4 +1093,14 @@ textarea {
|
|
|
1088
1093
|
}
|
|
1089
1094
|
.wd-form.size-width-hundred {
|
|
1090
1095
|
width: 100%;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
.wd-mp-form-item-obj .wd-form-obj-card-header {
|
|
1099
|
+
display: flex;
|
|
1100
|
+
}
|
|
1101
|
+
.wd-mp-form-item-obj .wd-form-obj-item-wrap__control-wrap {
|
|
1102
|
+
flex-direction: column;
|
|
1103
|
+
}
|
|
1104
|
+
.wd-mp-form-item-obj .wd-form-item--weui.wd-form-item {
|
|
1105
|
+
width: 100%;
|
|
1091
1106
|
}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
import itemBehavior from '../form-field-behavior/item-behavior';
|
|
3
|
+
import { noop } from '../../utils/constant';
|
|
4
|
+
import { commonCompBehavior } from '../../utils/common-behavior';
|
|
5
|
+
import formFieldBehavior from '../form-field-behavior/form-field-behavior';
|
|
6
|
+
import { isNil, deepClone } from '../../utils/lodash';
|
|
7
|
+
import debounce from '../../utils/debounce';
|
|
8
|
+
import lodashGet from 'lodash.get';
|
|
9
|
+
import lodashSet from 'lodash.set';
|
|
10
|
+
|
|
11
|
+
import equal from '../../utils/deepEqual';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 获取待操作的数据路径,嵌套表单中子组件的名称是按lodashSet形式拼接的,在更新嵌套表单值时,要去除掉当前嵌套表单的路径名称
|
|
15
|
+
* @param operateName 待操作的表单项名称
|
|
16
|
+
* @param currentName 当前表单项名称
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
const getValueName = (operateName, currentName) =>
|
|
20
|
+
operateName.replace(new RegExp(`^${currentName}(\\.)?`), '');
|
|
21
|
+
|
|
22
|
+
Component({
|
|
23
|
+
options: { virtualHost: true },
|
|
24
|
+
behaviors: [itemBehavior, commonCompBehavior, formFieldBehavior],
|
|
25
|
+
properties: {
|
|
26
|
+
classRoot: {
|
|
27
|
+
type: String,
|
|
28
|
+
value: 'form-obj',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
data: {
|
|
32
|
+
status: 'edit',
|
|
33
|
+
objValue: [],
|
|
34
|
+
formsItemMap: {},
|
|
35
|
+
},
|
|
36
|
+
lifetimes: {
|
|
37
|
+
created() {
|
|
38
|
+
this.updateChildValue = debounce(this.updateChildValueDebounce, 0);
|
|
39
|
+
},
|
|
40
|
+
attached: function () {
|
|
41
|
+
const that = this;
|
|
42
|
+
this.updateWidgetAPI({
|
|
43
|
+
getConfig() {
|
|
44
|
+
return {
|
|
45
|
+
componentType: 'formObj',
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* 外部直接set嵌入表单的值
|
|
50
|
+
* @param value
|
|
51
|
+
*/
|
|
52
|
+
setValue(value) {
|
|
53
|
+
that.change({ name: '', value }, { isUpdateParentForm: true });
|
|
54
|
+
},
|
|
55
|
+
add() {
|
|
56
|
+
that.change({ type: 'add' }, { isUpdateParentForm: false });
|
|
57
|
+
},
|
|
58
|
+
remove({ index = -1 } = {}) {
|
|
59
|
+
that.change(
|
|
60
|
+
{ type: 'remove', value: index },
|
|
61
|
+
{ isUpdateParentForm: false }
|
|
62
|
+
);
|
|
63
|
+
},
|
|
64
|
+
change(params) {
|
|
65
|
+
that.change(params, { isUpdateParentForm: true });
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* 用于同步子组件的默认值
|
|
69
|
+
* @param params
|
|
70
|
+
*/
|
|
71
|
+
__setValueImmediate__(params) {
|
|
72
|
+
that.changeByChildFormObj(params);
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* 嵌套表单内部子组件值改变时,触发嵌套表单组件的值更新
|
|
76
|
+
* @param params.name 子组件名称
|
|
77
|
+
* @param params.value 子组件值
|
|
78
|
+
*/
|
|
79
|
+
valueChangeFromChild(params = {}) {
|
|
80
|
+
if (!params.name) return;
|
|
81
|
+
|
|
82
|
+
// 由于是子组件值变更触发,所以嵌套表单值更新后不再次触发子组件值变更
|
|
83
|
+
that.change(params, {
|
|
84
|
+
isUpdateParentForm: true,
|
|
85
|
+
isUpdateChildValue: false,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* 收集嵌套表单内的子组件实例,以便嵌套表单值变化时,主动触发子组件值更新
|
|
90
|
+
* @param childName 子组件名称
|
|
91
|
+
* @param formItem 子组件$widget
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
addFormItem(childName, formItem) {
|
|
95
|
+
if (
|
|
96
|
+
isNil(childName) ||
|
|
97
|
+
!formItem ||
|
|
98
|
+
(typeof childName === 'string' && childName.length === 0)
|
|
99
|
+
) {
|
|
100
|
+
// childName 没设置或为空串的时候不受表单容器控制
|
|
101
|
+
console.warn(
|
|
102
|
+
`组件 #${formItem?.id} 表单key(表单输入类组件 childName 属性)没设置或为空串的时候不受表单容器控制`
|
|
103
|
+
);
|
|
104
|
+
return noop;
|
|
105
|
+
}
|
|
106
|
+
const { formsItemMap } = that.data;
|
|
107
|
+
if (Array.isArray(formsItemMap[childName])) {
|
|
108
|
+
formsItemMap[childName].push(formItem);
|
|
109
|
+
} else {
|
|
110
|
+
formsItemMap[childName] = [formItem];
|
|
111
|
+
}
|
|
112
|
+
that.setData({ formsItemMap });
|
|
113
|
+
return () => {
|
|
114
|
+
const removedArr = formsItemMap[childName].filter(
|
|
115
|
+
(item) => item !== formItem
|
|
116
|
+
);
|
|
117
|
+
if (removedArr.length <= 0) {
|
|
118
|
+
delete formsItemMap[childName];
|
|
119
|
+
} else {
|
|
120
|
+
formsItemMap[childName] = removedArr;
|
|
121
|
+
}
|
|
122
|
+
that.setData({ formsItemMap });
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
methods: {
|
|
129
|
+
updateWidgetAPI(apis = {}) {
|
|
130
|
+
const { name, objValue, label, visible, readOnly, disabled, status } =
|
|
131
|
+
this.data;
|
|
132
|
+
this.setReadonlyAttributes?.({
|
|
133
|
+
...apis,
|
|
134
|
+
label,
|
|
135
|
+
name,
|
|
136
|
+
value: objValue,
|
|
137
|
+
visible,
|
|
138
|
+
disabled,
|
|
139
|
+
readOnly,
|
|
140
|
+
status,
|
|
141
|
+
formObjName: name,
|
|
142
|
+
getValue() {
|
|
143
|
+
return objValue;
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
// 父级普通表单对象
|
|
148
|
+
getParentForm() {
|
|
149
|
+
const parent = this?.$widget?.closest(
|
|
150
|
+
(w) => w.getConfig?.().componentType === 'form'
|
|
151
|
+
);
|
|
152
|
+
return parent;
|
|
153
|
+
},
|
|
154
|
+
// 父级嵌套表单对象
|
|
155
|
+
getParentFormObj() {
|
|
156
|
+
const parent = this?.$widget?.closest(
|
|
157
|
+
(w) => w.getConfig?.().componentType === 'formObj'
|
|
158
|
+
);
|
|
159
|
+
return parent;
|
|
160
|
+
},
|
|
161
|
+
/**
|
|
162
|
+
* 对外触发嵌套表单的onDataChange事件
|
|
163
|
+
*/
|
|
164
|
+
triggerOnDataChange(value) {
|
|
165
|
+
this.triggerEvent('onDataChange', { data: value });
|
|
166
|
+
},
|
|
167
|
+
/**
|
|
168
|
+
* 不在表单容器中使用时,更新子组件值
|
|
169
|
+
*/
|
|
170
|
+
updateChildValue() {},
|
|
171
|
+
updateChildValueDebounce(value) {
|
|
172
|
+
Object.keys(this.data.formsItemMap).forEach((childName) => {
|
|
173
|
+
let items = this.data.formsItemMap[childName];
|
|
174
|
+
|
|
175
|
+
if (!Array.isArray(items)) {
|
|
176
|
+
items = [items];
|
|
177
|
+
}
|
|
178
|
+
const newValue = lodashGet(
|
|
179
|
+
value,
|
|
180
|
+
getValueName(childName, this.data.name)
|
|
181
|
+
);
|
|
182
|
+
items.forEach((item) => {
|
|
183
|
+
if (item?.setValue && !equal(item.value, newValue)) {
|
|
184
|
+
item.setValue(newValue);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
/**
|
|
190
|
+
* 更新值
|
|
191
|
+
* @param params.name
|
|
192
|
+
* @param params.value
|
|
193
|
+
* @param params.type 'change' | 'add' | 'remove'
|
|
194
|
+
* @param param1.isUpdateParentForm 是否更新父级表单,因子组件值变化调用change时不去触发父表单的更新,因为子组件自己会触发;因为外部设置了值,则触发父表单更新
|
|
195
|
+
* @param param1.isUpdateChildValue 是否更新子组件值, 因子组件值变化调用change时不去触发updateChildValueWithoutForm;因为外部设置了值,则触发updateChildValueWithoutForm去更新子组件值
|
|
196
|
+
* @returns
|
|
197
|
+
*/
|
|
198
|
+
change(
|
|
199
|
+
params,
|
|
200
|
+
{ isUpdateParentForm = false, isUpdateChildValue = true } = {}
|
|
201
|
+
) {
|
|
202
|
+
const { objValue, name } = this.data;
|
|
203
|
+
let value = deepClone(params.value);
|
|
204
|
+
|
|
205
|
+
// 顶层为数组类型
|
|
206
|
+
if (Array.isArray(objValue)) {
|
|
207
|
+
// 触发添加操作,则增加一个undefined值
|
|
208
|
+
if (params.type === 'add') {
|
|
209
|
+
value = deepClone(objValue);
|
|
210
|
+
value.push({});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// 触发删除操作,则删除对应索引的值
|
|
214
|
+
if (params.type === 'remove') {
|
|
215
|
+
value = deepClone(objValue);
|
|
216
|
+
value = [
|
|
217
|
+
...value.slice(0, params.value),
|
|
218
|
+
...value.slice(params.value + 1),
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 如果有更新标识,则按标识路径更新值
|
|
224
|
+
if (params.name) {
|
|
225
|
+
value = deepClone(objValue);
|
|
226
|
+
lodashSet(value, getValueName(params.name, name), params.value);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (equal(value, objValue)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
this.setData({ objValue: value || [] });
|
|
234
|
+
|
|
235
|
+
if (isUpdateChildValue) {
|
|
236
|
+
// 外部设置数据,同时去更新子组件的值
|
|
237
|
+
this.updateChildValue(value);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const parentForm = this.getParentForm();
|
|
241
|
+
const parentFormObj = this.getParentFormObj();
|
|
242
|
+
|
|
243
|
+
// 不存在父级嵌套表单时,去更新父级普通表单,避免重复更新
|
|
244
|
+
if (!parentFormObj && isUpdateParentForm) {
|
|
245
|
+
// 触发父级普通表单值更新
|
|
246
|
+
parentForm?.setValue?.({ [name]: value }, false, true);
|
|
247
|
+
// 刷新父级普通表单的formData
|
|
248
|
+
parentForm?.updateFormContext();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (params.name) {
|
|
252
|
+
// 触发父级嵌套表单值更新
|
|
253
|
+
parentFormObj?.__setValueImmediate__?.({
|
|
254
|
+
name: params.name,
|
|
255
|
+
value: params.value,
|
|
256
|
+
});
|
|
257
|
+
} else if (parentFormObj?.formObjName) {
|
|
258
|
+
// 外部直接调用formObj.setValue的情况下,触发父级嵌套表单值更新
|
|
259
|
+
parentFormObj?.__setValueImmediate__?.({ name, value });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
this.triggerOnDataChange(value);
|
|
263
|
+
},
|
|
264
|
+
/**
|
|
265
|
+
* 子组件默认值变更,触发嵌套表单值更新
|
|
266
|
+
* @param params.name
|
|
267
|
+
* @param params.value
|
|
268
|
+
*/
|
|
269
|
+
changeByChildFormObj(params) {
|
|
270
|
+
const { objValue, name } = this.data;
|
|
271
|
+
const value = deepClone(objValue);
|
|
272
|
+
lodashSet(value, getValueName(params.name, name), params.value);
|
|
273
|
+
|
|
274
|
+
if (equal(value, objValue)) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const parentFormObj = this.getParentFormObj();
|
|
279
|
+
const parentForm = this.getParentForm();
|
|
280
|
+
|
|
281
|
+
if (params.name) {
|
|
282
|
+
// 判断是否将当前的name前缀加上,以便父级嵌套表单更新值
|
|
283
|
+
const nameTemp = `${
|
|
284
|
+
!params.name.startsWith(name) && name ? `${name}.` : ''
|
|
285
|
+
}${params.name}`;
|
|
286
|
+
// 将值同步给父级嵌套表单
|
|
287
|
+
parentFormObj?.__setValueImmediate__?.({
|
|
288
|
+
name: nameTemp,
|
|
289
|
+
value: params.value,
|
|
290
|
+
});
|
|
291
|
+
} else if (parentFormObj?.formObjName) {
|
|
292
|
+
// 外部直接调用formObj.setValue的情况下,触发父级嵌套表单值更新
|
|
293
|
+
parentFormObj?.__setValueImmediate__?.({ name, value });
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (!parentFormObj && parentForm) {
|
|
297
|
+
// 触发父级普通表单值更新
|
|
298
|
+
parentForm?.setValue?.({ [name]: value }, false, true);
|
|
299
|
+
// 刷新父级普通表单的formData
|
|
300
|
+
parentForm?.updateFormContext();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
this.setData({ objValue: value || [] });
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
observers: {
|
|
307
|
+
'disabled, readOnly': function (disabled, readOnly) {
|
|
308
|
+
if (readOnly) {
|
|
309
|
+
this.setData({ status: 'readOnly' });
|
|
310
|
+
} else if (disabled) {
|
|
311
|
+
this.setData({ status: 'disabled' });
|
|
312
|
+
} else {
|
|
313
|
+
this.setData({ status: 'edit' });
|
|
314
|
+
}
|
|
315
|
+
this.updateWidgetAPI();
|
|
316
|
+
},
|
|
317
|
+
value: function (value) {
|
|
318
|
+
this.setData({ objValue: value });
|
|
319
|
+
this.updateWidgetAPI();
|
|
320
|
+
},
|
|
321
|
+
objValue: function (objValue) {
|
|
322
|
+
this.updateWidgetAPI();
|
|
323
|
+
// 如果是最顶层的嵌套表单,则去更新子组件的值,否则自己的值更新不去触发子组件值更新,因为父级普通表单会去更新
|
|
324
|
+
const parentFormObj = this.getParentFormObj();
|
|
325
|
+
if (!parentFormObj) {
|
|
326
|
+
this.updateChildValue(objValue);
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
});
|