cy-element-ui 1.1.27 → 1.1.28
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/lib/CyTreeSelect.js +28 -17
- package/lib/element-ui.common.js +34 -23
- package/lib/index.js +2 -2
- package/package.json +1 -1
- package/packages/cy/treeSelect/src/main.vue +25 -15
- package/src/index.js +1 -1
package/package.json
CHANGED
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
ref="tree"
|
|
27
27
|
:data="treeOptions"
|
|
28
28
|
:show-checkbox="multiple"
|
|
29
|
-
:node-key="
|
|
29
|
+
:node-key="treeFieldMap.id"
|
|
30
30
|
:check-strictly="!isCheckStrictly"
|
|
31
|
-
:props="
|
|
31
|
+
:props="treeFieldMap"
|
|
32
32
|
:expand-on-click-node="false"
|
|
33
33
|
:default-expand-all="defaultExpandAll"
|
|
34
34
|
:filter-node-method="filterNode"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
<div class="cy-tree-select-select-v">
|
|
44
44
|
<!-- 未选中时显示占位提示,选中后显示已选节点 label 拼接文本 -->
|
|
45
45
|
<span v-if="checkedArr.length < 1" class="cy-tree-select-select-v-placeholder">{{ placeholder }}</span>
|
|
46
|
-
<span v-else>{{ checkedArr.map(item => item[
|
|
46
|
+
<span v-else>{{ checkedArr.map(item => item[treeFieldMap.label]).join() }}</span>
|
|
47
47
|
</div>
|
|
48
48
|
|
|
49
49
|
<!-- 右侧图标区:hover 显示清空按钮,否则显示下拉箭头 -->
|
|
@@ -180,6 +180,16 @@ export default {
|
|
|
180
180
|
};
|
|
181
181
|
},
|
|
182
182
|
computed: {
|
|
183
|
+
/**
|
|
184
|
+
* 字段映射配置:将用户传入的 defaultOptions 与默认值合并,
|
|
185
|
+
* 保证 children / label / id 三个 key 始终存在,
|
|
186
|
+
* 避免只传部分字段时取到的 key 为 undefined 而导致层级/选中/搜索失效
|
|
187
|
+
* @returns {Object} 合并后的字段映射
|
|
188
|
+
*/
|
|
189
|
+
treeFieldMap() {
|
|
190
|
+
return Object.assign({ children: 'children', label: 'label', id: 'id' }, this.defaultOptions);
|
|
191
|
+
},
|
|
192
|
+
|
|
183
193
|
/**
|
|
184
194
|
* 根据 value 反查当前选中节点对象数组,用于回显文本
|
|
185
195
|
* @returns {Array} 选中节点对象数组
|
|
@@ -188,12 +198,12 @@ export default {
|
|
|
188
198
|
if (this.multiple) {
|
|
189
199
|
let arr = [];
|
|
190
200
|
this.value && this.value.forEach(id => {
|
|
191
|
-
let cItem = this.treeArr.filter(tItem => tItem[this.
|
|
201
|
+
let cItem = this.treeArr.filter(tItem => tItem[this.treeFieldMap.id] === id)[0];
|
|
192
202
|
if (cItem) arr.push(cItem);
|
|
193
203
|
});
|
|
194
204
|
return arr;
|
|
195
205
|
} else {
|
|
196
|
-
let cItem = this.treeArr.filter(tItem => tItem[this.
|
|
206
|
+
let cItem = this.treeArr.filter(tItem => tItem[this.treeFieldMap.id] === Number(this.value))[0];
|
|
197
207
|
return cItem ? [cItem] : [];
|
|
198
208
|
}
|
|
199
209
|
}
|
|
@@ -254,7 +264,7 @@ export default {
|
|
|
254
264
|
*/
|
|
255
265
|
filterNode(value, data) {
|
|
256
266
|
if (!value) return true;
|
|
257
|
-
return this.matchedNodeIds.includes(data[this.
|
|
267
|
+
return this.matchedNodeIds.includes(data[this.treeFieldMap.id]);
|
|
258
268
|
},
|
|
259
269
|
|
|
260
270
|
/**
|
|
@@ -268,15 +278,15 @@ export default {
|
|
|
268
278
|
let matchedIds = [];
|
|
269
279
|
|
|
270
280
|
nodes.forEach(node => {
|
|
271
|
-
const currentNodeMatched = node[this.
|
|
281
|
+
const currentNodeMatched = node[this.treeFieldMap.label].indexOf(value) !== -1;
|
|
272
282
|
const shouldShow = currentNodeMatched || parentMatched;
|
|
273
283
|
|
|
274
284
|
if (shouldShow) {
|
|
275
|
-
matchedIds.push(node[this.
|
|
285
|
+
matchedIds.push(node[this.treeFieldMap.id]);
|
|
276
286
|
}
|
|
277
287
|
|
|
278
|
-
if (node[this.
|
|
279
|
-
const childIds = this.findMatchedNodes(value, node[this.
|
|
288
|
+
if (node[this.treeFieldMap.children] && node[this.treeFieldMap.children].length > 0) {
|
|
289
|
+
const childIds = this.findMatchedNodes(value, node[this.treeFieldMap.children], shouldShow);
|
|
280
290
|
matchedIds = matchedIds.concat(childIds);
|
|
281
291
|
}
|
|
282
292
|
});
|
|
@@ -324,7 +334,7 @@ export default {
|
|
|
324
334
|
treeCheck(value, { checkedKeys, checkedNodes }) {
|
|
325
335
|
let arr = [];
|
|
326
336
|
arr = checkedNodes;
|
|
327
|
-
let idArr = arr.map(item => item[this.
|
|
337
|
+
let idArr = arr.map(item => item[this.treeFieldMap.id]);
|
|
328
338
|
this.$emit('change', this.multiple ? idArr : idArr[0], this.multiple ? arr : arr[0]);
|
|
329
339
|
},
|
|
330
340
|
|
|
@@ -339,7 +349,7 @@ export default {
|
|
|
339
349
|
treeClick(value, node, event) {
|
|
340
350
|
if (this.multiple) return;
|
|
341
351
|
|
|
342
|
-
this.$emit('change', value[this.
|
|
352
|
+
this.$emit('change', value[this.treeFieldMap.id], value);
|
|
343
353
|
this.popoverOpen = false;
|
|
344
354
|
},
|
|
345
355
|
|
|
@@ -363,12 +373,12 @@ export default {
|
|
|
363
373
|
turnFormatTreeData(arr, data, pId) {
|
|
364
374
|
data.forEach(item => {
|
|
365
375
|
let cItem = JSON.parse(JSON.stringify(item));
|
|
366
|
-
delete cItem[this.
|
|
376
|
+
delete cItem[this.treeFieldMap.children];
|
|
367
377
|
cItem.pId = pId;
|
|
368
378
|
arr.push(cItem);
|
|
369
379
|
|
|
370
|
-
if (item[this.
|
|
371
|
-
this.turnFormatTreeData(arr, item[this.
|
|
380
|
+
if (item[this.treeFieldMap.children] && item[this.treeFieldMap.children].length > 0) {
|
|
381
|
+
this.turnFormatTreeData(arr, item[this.treeFieldMap.children], item[this.treeFieldMap.id]);
|
|
372
382
|
}
|
|
373
383
|
});
|
|
374
384
|
return arr;
|