@cloudbase/weda-ui-mp 3.6.5 → 3.7.2
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 +10 -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 +29 -3
- 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-date/modal/index.js +4 -1
- package/components/wd-date/modal/index.wxml +1 -1
- package/components/wd-form/form-utils.js +4 -0
- package/components/wd-form/wd-form.wxss +10 -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 +10 -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-input/inner-input/wd-input.wxss +10 -0
- package/components/wd-progress/wd-progress.wxss +10 -0
- package/components/wd-rating/wd-rating.wxss +10 -0
- package/components/wd-select/select.wxss +9 -3
- package/components/wd-switch/wd-switch.wxss +10 -0
- package/components/wd-tag-select/wd-tag-select.wxss +10 -0
- package/components/web-view/index.js +3 -0
- package/index.json +2 -0
- package/package.json +1 -1
- package/utils/enum.js +13 -0
|
@@ -1093,4 +1093,14 @@ textarea {
|
|
|
1093
1093
|
}
|
|
1094
1094
|
.wd-form.size-width-hundred {
|
|
1095
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%;
|
|
1096
1106
|
}
|
|
@@ -227,14 +227,14 @@ Component({
|
|
|
227
227
|
urls: newUrls,
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
|
-
this.handleChange(newUrls);
|
|
230
|
+
this.handleChange(newUrls, true);
|
|
231
231
|
},
|
|
232
|
-
handleChange: function (values) {
|
|
232
|
+
handleChange: function (values, isDelete = false) {
|
|
233
233
|
let value = values;
|
|
234
234
|
if (this.properties.single) {
|
|
235
235
|
value = values[0] ?? '';
|
|
236
236
|
}
|
|
237
|
-
this.triggerEvent('change', { value });
|
|
237
|
+
this.triggerEvent('change', { value, isDelete });
|
|
238
238
|
},
|
|
239
239
|
},
|
|
240
240
|
observers: {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
<view wx:if="{{currentFiles.length < maxCount && !readOnly}}" class="weui-uploader__input-box {{shapeClass}}" hover-class="weui-active">
|
|
41
41
|
<view wx:if="{{!disabled&&!isChooseAvatar}}" class="weui-uploader__input" bindtap="chooseImage"></view>
|
|
42
42
|
|
|
43
|
-
<button class="weui-uploader__input" wx:if="{{!disabled&&isChooseAvatar}}" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar"></button>
|
|
43
|
+
<button class="weui-uploader__input weui-uploader__input-button" wx:if="{{!disabled&&isChooseAvatar}}" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar"></button>
|
|
44
44
|
|
|
45
45
|
<view wx:if="{{disabled}}" class="weui-uploader__uploader_disabled"></view>
|
|
46
46
|
</view>
|
|
@@ -210,7 +210,7 @@ export default Behavior({
|
|
|
210
210
|
Promise.resolve().then(() => {
|
|
211
211
|
this._reaction = autorun(() => {
|
|
212
212
|
const form = untracked(() => {
|
|
213
|
-
return this.$widget
|
|
213
|
+
return this.$widget?.closest(
|
|
214
214
|
(w) => w.getConfig?.()?.componentType === 'form'
|
|
215
215
|
);
|
|
216
216
|
});
|
|
@@ -253,6 +253,8 @@ export default Behavior({
|
|
|
253
253
|
},
|
|
254
254
|
detached() {
|
|
255
255
|
this._removeFormItem && this._removeFormItem();
|
|
256
|
+
// 清空嵌套表单
|
|
257
|
+
this._removeFormObjItem?.();
|
|
256
258
|
if (this.$widget) {
|
|
257
259
|
const form = this.$widget.closest(
|
|
258
260
|
(w) => w.getConfig?.()?.componentType === 'form'
|
|
@@ -320,6 +322,9 @@ export default Behavior({
|
|
|
320
322
|
if (newName === this.data._oldName) return;
|
|
321
323
|
Promise.resolve().then(() => {
|
|
322
324
|
this._removeFormItem?.();
|
|
325
|
+
// 清空嵌套表单
|
|
326
|
+
this._removeFormObjItem?.();
|
|
327
|
+
|
|
323
328
|
// this.$instanceRef.current = this.$instanceRef.current ?? {};
|
|
324
329
|
this.setReadonlyAttributes?.({ name: newName });
|
|
325
330
|
// this.$instanceRef.current.name = newName;
|
|
@@ -336,6 +341,18 @@ export default Behavior({
|
|
|
336
341
|
form?.updateFormContext(this.data.name, this.data.value);
|
|
337
342
|
}
|
|
338
343
|
}
|
|
344
|
+
|
|
345
|
+
const formObj = this.$widget?.closest?.(
|
|
346
|
+
(w) => w.getConfig?.()?.componentType === 'formObj'
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
if (formObj) {
|
|
350
|
+
// 添加子组件到嵌套表单里面
|
|
351
|
+
this._removeFormObjItem = formObj.addFormItem(
|
|
352
|
+
this.data.name,
|
|
353
|
+
this.$widget
|
|
354
|
+
);
|
|
355
|
+
}
|
|
339
356
|
});
|
|
340
357
|
},
|
|
341
358
|
value: function (value) {
|
|
@@ -353,8 +370,17 @@ export default Behavior({
|
|
|
353
370
|
const form = this.$widget.closest(
|
|
354
371
|
(w) => w.getConfig?.()?.componentType === 'form'
|
|
355
372
|
);
|
|
356
|
-
|
|
357
|
-
|
|
373
|
+
const formObj = this.$widget.closest(
|
|
374
|
+
(w) => w.getConfig?.()?.componentType === 'formObj'
|
|
375
|
+
);
|
|
376
|
+
// 有父级嵌套表单的不更新form值,父级嵌套表单会去更新
|
|
377
|
+
!formObj && form?.updateFormContext(this.data.name, value);
|
|
378
|
+
formObj?.valueChangeFromChild?.({
|
|
379
|
+
name: `${formObj?.formObjName ? `${formObj.formObjName}.` : ''}${
|
|
380
|
+
this.data.name
|
|
381
|
+
}`,
|
|
382
|
+
value,
|
|
383
|
+
});
|
|
358
384
|
}
|
|
359
385
|
|
|
360
386
|
// console.log(this.data.name, this.data.valueHistory, 'VALUE history');
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
|
|
3
|
+
import { commonCompBehavior } from '../../utils/common-behavior';
|
|
4
|
+
import formFieldBehavior from '../form-field-behavior/form-field-behavior';
|
|
5
|
+
import itemBehavior from '../form-field-behavior/item-behavior';
|
|
6
|
+
import { convertFixedIcon, SELECT_ICON_H5 } from '../../utils/getFormLegacy';
|
|
7
|
+
import debounce from '../../utils/debounce';
|
|
8
|
+
import {
|
|
9
|
+
getSelectedOptions,
|
|
10
|
+
transformTabData,
|
|
11
|
+
setSelectedValue,
|
|
12
|
+
initTabData,
|
|
13
|
+
initListOptions,
|
|
14
|
+
placeholderItem,
|
|
15
|
+
} from './utils';
|
|
16
|
+
Component({
|
|
17
|
+
options: {
|
|
18
|
+
virtualHost: true,
|
|
19
|
+
},
|
|
20
|
+
behaviors: [itemBehavior, commonCompBehavior, formFieldBehavior],
|
|
21
|
+
properties: {
|
|
22
|
+
classRoot: {
|
|
23
|
+
type: String,
|
|
24
|
+
value: 'cascader',
|
|
25
|
+
},
|
|
26
|
+
data: {
|
|
27
|
+
type: Array,
|
|
28
|
+
value: [],
|
|
29
|
+
},
|
|
30
|
+
className: {
|
|
31
|
+
type: String,
|
|
32
|
+
value: '',
|
|
33
|
+
},
|
|
34
|
+
style: {
|
|
35
|
+
type: String,
|
|
36
|
+
value: '',
|
|
37
|
+
},
|
|
38
|
+
id: {
|
|
39
|
+
type: String,
|
|
40
|
+
value: '',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
data: {
|
|
44
|
+
initData: [],
|
|
45
|
+
tabData: [],
|
|
46
|
+
listOptions: [],
|
|
47
|
+
_suffixType: '',
|
|
48
|
+
_suffixIcon: '',
|
|
49
|
+
modalVisible: false,
|
|
50
|
+
searchable: false,
|
|
51
|
+
selectedOptions: [],
|
|
52
|
+
displayValue: '',
|
|
53
|
+
},
|
|
54
|
+
methods: {
|
|
55
|
+
finalUpdateWidgetAPI: function () {
|
|
56
|
+
const { selectedOptions } = this.data;
|
|
57
|
+
this.setReadonlyAttributes &&
|
|
58
|
+
this.setReadonlyAttributes({
|
|
59
|
+
selectedOptions,
|
|
60
|
+
});
|
|
61
|
+
this.updateWidgetAPI();
|
|
62
|
+
},
|
|
63
|
+
search: function (e) {
|
|
64
|
+
this.debouncedTriggerSearchEvent(e.detail.value);
|
|
65
|
+
},
|
|
66
|
+
debouncedTriggerSearchEvent: debounce(function (value) {
|
|
67
|
+
this.triggerEvent('search', {
|
|
68
|
+
value,
|
|
69
|
+
});
|
|
70
|
+
}),
|
|
71
|
+
|
|
72
|
+
// tab 展示值
|
|
73
|
+
updateTabData: function (newTabData, activeItem) {
|
|
74
|
+
let _activeItem = activeItem;
|
|
75
|
+
// 当前选中值是否存在子选项
|
|
76
|
+
const hasChildItem = newTabData[newTabData.length - 1]?.children?.length;
|
|
77
|
+
|
|
78
|
+
let tabData = [...newTabData];
|
|
79
|
+
if (hasChildItem) {
|
|
80
|
+
_activeItem = placeholderItem;
|
|
81
|
+
tabData = [...tabData, placeholderItem];
|
|
82
|
+
}
|
|
83
|
+
const _tabData = setSelectedValue(tabData, _activeItem.value);
|
|
84
|
+
this.setData({
|
|
85
|
+
tabData: _tabData,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
// 点击列表选项
|
|
90
|
+
handleListOptionsClick: function (itemInfo) {
|
|
91
|
+
const item = itemInfo?.currentTarget?.dataset?.item;
|
|
92
|
+
if (item.disabled) return;
|
|
93
|
+
const { listOptions, tabData } = this.data;
|
|
94
|
+
if (item.children) {
|
|
95
|
+
this.setData({
|
|
96
|
+
listOptions: [...item.children],
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
const _listOptions = setSelectedValue(listOptions, item.value);
|
|
100
|
+
this.setData({
|
|
101
|
+
listOptions: _listOptions,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// 更新tab数据
|
|
105
|
+
const newTabData = [...tabData.filter((i) => i.level < item.level), item];
|
|
106
|
+
this.updateTabData(newTabData, item);
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
// 点击tab项,更新列表选项
|
|
110
|
+
handleTabClick: function (e) {
|
|
111
|
+
const selectedIndex = e?.detail;
|
|
112
|
+
const { tabData, initData } = this.data;
|
|
113
|
+
const selectedItem = tabData[selectedIndex];
|
|
114
|
+
this.updateTabData(tabData, selectedItem);
|
|
115
|
+
let listOptions =
|
|
116
|
+
selectedItem.level === 0
|
|
117
|
+
? initData
|
|
118
|
+
: tabData.find((i) => i.level === selectedIndex - 1)?.children;
|
|
119
|
+
|
|
120
|
+
listOptions = setSelectedValue(listOptions, selectedItem?.value);
|
|
121
|
+
this.setData({
|
|
122
|
+
listOptions: listOptions,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
init: function () {
|
|
126
|
+
const { data, value } = this.data;
|
|
127
|
+
const _value = Array.isArray(value) ? value : [];
|
|
128
|
+
const initData = transformTabData(data);
|
|
129
|
+
const tabData = initTabData(initData, _value || [], placeholderItem);
|
|
130
|
+
const listOptions = initListOptions(initData, _value || []);
|
|
131
|
+
const selectedOptions = _value?.map((i) => getSelectedOptions(data, i));
|
|
132
|
+
const displayValue =
|
|
133
|
+
selectedOptions?.map((i) => i.label)?.join(' / ') || _value.join(' / ');
|
|
134
|
+
this.setData({
|
|
135
|
+
tabData,
|
|
136
|
+
listOptions,
|
|
137
|
+
initData,
|
|
138
|
+
selectedOptions,
|
|
139
|
+
displayValue,
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
handleClick: function () {
|
|
143
|
+
if (this.data.disabled) return;
|
|
144
|
+
this.setData({
|
|
145
|
+
modalVisible: true,
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
handleClose: function () {
|
|
149
|
+
this.setData({
|
|
150
|
+
modalVisible: false,
|
|
151
|
+
});
|
|
152
|
+
this.init();
|
|
153
|
+
},
|
|
154
|
+
handleOk: function () {
|
|
155
|
+
const { tabData, data } = this.data;
|
|
156
|
+
const value = tabData
|
|
157
|
+
.map((item) => item.value)
|
|
158
|
+
.filter((i) => i !== '__placeholderItem');
|
|
159
|
+
const selectedOptions = value.map((i) => getSelectedOptions(data, i));
|
|
160
|
+
this.setData({
|
|
161
|
+
modalVisible: false,
|
|
162
|
+
value,
|
|
163
|
+
selectedOptions,
|
|
164
|
+
displayValue: selectedOptions?.map((i) => i.label)?.join(' / '),
|
|
165
|
+
});
|
|
166
|
+
this.triggerEvent('change', {
|
|
167
|
+
value,
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
observers: {
|
|
172
|
+
'name, value, label, required, visible, disabled, readOnly, before, after, selectedOptions':
|
|
173
|
+
function () {
|
|
174
|
+
this.finalUpdateWidgetAPI();
|
|
175
|
+
},
|
|
176
|
+
'suffixType,suffixIcon': function (suffixType, suffixIcon) {
|
|
177
|
+
const [_suffixType, _suffixIcon] = convertFixedIcon(
|
|
178
|
+
suffixType,
|
|
179
|
+
suffixIcon,
|
|
180
|
+
SELECT_ICON_H5
|
|
181
|
+
);
|
|
182
|
+
this.setData({
|
|
183
|
+
_suffixType,
|
|
184
|
+
_suffixIcon,
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
'data, value': function () {
|
|
188
|
+
this.init();
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
lifetimes: {
|
|
192
|
+
attached: function () {
|
|
193
|
+
this.finalUpdateWidgetAPI();
|
|
194
|
+
this.init();
|
|
195
|
+
this.setData({ id: this.id });
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"component": true,
|
|
3
|
+
"styleIsolation": "shared",
|
|
4
|
+
"usingComponents": {
|
|
5
|
+
"wd-form-item": "../wd-form-item/index",
|
|
6
|
+
"wd-input-group": "../wd-input-group/index",
|
|
7
|
+
"wd-input-wrap": "../wd-input-wrap/index",
|
|
8
|
+
"wd-modal": "../wd-date/modal",
|
|
9
|
+
"wd-tabs": "../wd-tabs",
|
|
10
|
+
"wd-icon": "../wd-icon"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<block wx:if="{{visible}}">
|
|
2
|
+
<wd-form-item
|
|
3
|
+
id="{{id}}"
|
|
4
|
+
className="{{className}}"
|
|
5
|
+
style="{{style}}"
|
|
6
|
+
label="{{label}}"
|
|
7
|
+
labelVisible="{{labelVisible}}"
|
|
8
|
+
labelTips="{{labelTips}}"
|
|
9
|
+
labelWidth="{{labelWidth}}"
|
|
10
|
+
labelAlign="{{labelAlign}}"
|
|
11
|
+
labelWrap="{{labelWrap}}"
|
|
12
|
+
layout="{{actualLayout}}"
|
|
13
|
+
extra="{{extra}}"
|
|
14
|
+
required="{{required}}"
|
|
15
|
+
requiredFlag="{{requiredFlag}}"
|
|
16
|
+
validateState="{{validateState}}"
|
|
17
|
+
validateErrorMsg="{{validateErrorMsg}}"
|
|
18
|
+
classRoot="{{classRoot}}"
|
|
19
|
+
size="{{size}}"
|
|
20
|
+
borderedH5="{{borderedH5}}"
|
|
21
|
+
>
|
|
22
|
+
<wd-input-group before="{{before}}" after="{{after}}" block="{{true}}" size="{{_size}}" classRoot="{{classRoot}}" readOnly="{{readOnly}}">
|
|
23
|
+
<wd-input-wrap block="{{block}}" classRoot="{{classRoot}}" before="{{before}}" after="{{after}}" disabled="{{disabled}}" prefixType="{{prefixType}}" prefixIcon="{{prefixIcon}}" prefixSrc="{{prefixSrc}}" suffixType="{{_suffixType}}" suffixIcon="{{_suffixIcon}}" suffixSrc="{{suffixSrc}}" hasClearIcon="{{hasClearIcon}}" bind:onClear="handleClear" readOnly="{{readOnly}}">
|
|
24
|
+
<view class="weui-cell__bd">
|
|
25
|
+
<view bindtap="handleClick" class="weui-picker__group weui-input">
|
|
26
|
+
<label class="wd-form-select_input {{displayValue ? '' : 'weui-input__placeholder'}}">{{displayValue || placeholder}}</label>
|
|
27
|
+
</view>
|
|
28
|
+
</view>
|
|
29
|
+
</wd-input-wrap>
|
|
30
|
+
</wd-input-group>
|
|
31
|
+
</wd-form-item>
|
|
32
|
+
<wd-modal visible="{{modalVisible}}" bind:onClose="handleClose" bind:onOk="handleOk" header="{{focus}}" className="{{classPrefix + '-cascader-modal'}}">
|
|
33
|
+
<block wx:if="{{searchable}}">
|
|
34
|
+
<view class="wd-custom-search {{focus?'is-focused':''}}" style="{{focus? 'margin: 34rpx 32rpx 16rpx 32rpx':'margin: 20rpx 32rpx'}}">
|
|
35
|
+
<view class="wd-custom-search-box" bindtap="onFocus">
|
|
36
|
+
<input class="wd-input" focus="{{focus}}" bindfocus="onFocus" bindblur="onBlur" bindinput="bindinput" value="{{searchValue}}" hold-keyboard="true" bindconfirm="bindconfirm" />
|
|
37
|
+
<view class="wd-custom-search-box__label">
|
|
38
|
+
<span class="wd-custom-search-box__search-icon"></span>
|
|
39
|
+
<span class="wd-custom-search-box__search-placeholder"> 搜索 </span>
|
|
40
|
+
</view>
|
|
41
|
+
<span wx:if="{{focus && searchValue !== ''}}" class="wd-custom-search-box__dismiss-icon" bindtap="clear"></span>
|
|
42
|
+
</view>
|
|
43
|
+
<text class="wd-custom-search__btn-cancle" bindtap="shrink">取消</text>
|
|
44
|
+
</view>
|
|
45
|
+
</block>
|
|
46
|
+
<view class="wd-custom-view-content">
|
|
47
|
+
<wd-tabs list="{{tabData}}" bind:onCurrent="handleTabClick" direction="horizontal">
|
|
48
|
+
<scroll-view scroll-y="true" class="{{classPrefix + '-cascader-h5-view-list'}}" enable-flex="true">
|
|
49
|
+
<view wx:for="{{listOptions}}" class="{{classPrefix + '-cascader-h5-view-list__menu'}} {{item.selected?'is-selected':''}} {{item.isDisabled?'is-disabled':''}}" wx:for-index="index" wx:for-item="item" wx:key="{{item.value}}" id="{{'cell-'+index}}" bindtap="handleListOptionsClick" data-value="{{item.value}}" data-item="{{item}}">
|
|
50
|
+
<view class="{{classPrefix + '-cascader-h5-view-list__menu__text'}}"> {{item.label}} </view>
|
|
51
|
+
<view wx-if="{{item.selected}}">
|
|
52
|
+
<wd-icon name="td:check" size="md" />
|
|
53
|
+
</view>
|
|
54
|
+
</view>
|
|
55
|
+
</scroll-view>
|
|
56
|
+
</wd-tabs>
|
|
57
|
+
</view>
|
|
58
|
+
</wd-modal>
|
|
59
|
+
</block>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
|
|
3
|
+
import { deepClone } from '../../utils/lodash';
|
|
4
|
+
|
|
5
|
+
// 获取选中项
|
|
6
|
+
export const getSelectedOptions = (data, value) => {
|
|
7
|
+
for (const i of data) {
|
|
8
|
+
if (i.value === value) return i;
|
|
9
|
+
if (i.children) {
|
|
10
|
+
const res = getSelectedOptions(i.children, value);
|
|
11
|
+
if (res) return res;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// 组装tab数据
|
|
17
|
+
export const transformTabData = (data, pid = 'root', level = 0) => {
|
|
18
|
+
if (!Array.isArray(data)) return [];
|
|
19
|
+
return data.map((_item) => {
|
|
20
|
+
const item = deepClone(_item);
|
|
21
|
+
if (item.children) {
|
|
22
|
+
item.children = transformTabData(item.children, item.value, level + 1);
|
|
23
|
+
}
|
|
24
|
+
return { ...item, level, selected: false, pid };
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
// 设置选中值
|
|
28
|
+
export const setSelectedValue = (data, value) => {
|
|
29
|
+
if (!Array.isArray(data)) return [];
|
|
30
|
+
const _value = [].concat(value);
|
|
31
|
+
return data.map((item) => {
|
|
32
|
+
item.selected = !!_value.find((i) => i === item?.value);
|
|
33
|
+
if (item.children) {
|
|
34
|
+
item.children = setSelectedValue(item.children, value);
|
|
35
|
+
}
|
|
36
|
+
return item;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const initTabData = (data, value, placeholderItem) => {
|
|
41
|
+
if (!Array.isArray(data)) return [];
|
|
42
|
+
let tabDataRes = [placeholderItem];
|
|
43
|
+
if (value.length) {
|
|
44
|
+
const selectedOptions =
|
|
45
|
+
value?.map((i) => getSelectedOptions(data, i)) || [];
|
|
46
|
+
const selectedItem = selectedOptions[selectedOptions.length - 1];
|
|
47
|
+
|
|
48
|
+
tabDataRes = setSelectedValue(selectedOptions, selectedItem?.value);
|
|
49
|
+
}
|
|
50
|
+
return tabDataRes;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const initListOptions = (data, value) => {
|
|
54
|
+
if (!Array.isArray(data)) return [];
|
|
55
|
+
let listOptionsRes = deepClone(data);
|
|
56
|
+
if (value.length) {
|
|
57
|
+
const selectedOptions =
|
|
58
|
+
value?.map((i) => getSelectedOptions(data, i)) || [];
|
|
59
|
+
const selectedItem = selectedOptions[selectedOptions.length - 1];
|
|
60
|
+
listOptionsRes =
|
|
61
|
+
getSelectedOptions(data, selectedItem.pid)?.children || data;
|
|
62
|
+
}
|
|
63
|
+
return listOptionsRes;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const placeholderItem = {
|
|
67
|
+
label: '请选择',
|
|
68
|
+
value: '__placeholderItem',
|
|
69
|
+
selected: true,
|
|
70
|
+
};
|