mirror of https://github.com/ElemeFE/element
Cascader: fix emitPath (#21185)
parent
f1252dcf61
commit
19f25baffc
|
@ -157,7 +157,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
if (!isEmpty(this.value)) {
|
if (!this.isEmptyValue(this.value)) {
|
||||||
this.syncCheckedValue();
|
this.syncCheckedValue();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -195,13 +195,21 @@ export default {
|
||||||
node.syncCheckState(this.checkedValue);
|
node.syncCheckState(this.checkedValue);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
isEmptyValue(val) {
|
||||||
|
const { multiple, config } = this;
|
||||||
|
const { emitPath } = config;
|
||||||
|
if (multiple || emitPath) {
|
||||||
|
return isEmpty(val);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
syncActivePath() {
|
syncActivePath() {
|
||||||
const { store, multiple, activePath, checkedValue } = this;
|
const { store, multiple, activePath, checkedValue } = this;
|
||||||
|
|
||||||
if (!isEmpty(activePath)) {
|
if (!isEmpty(activePath)) {
|
||||||
const nodes = activePath.map(node => this.getNodeByValue(node.getValue()));
|
const nodes = activePath.map(node => this.getNodeByValue(node.getValue()));
|
||||||
this.expandNodes(nodes);
|
this.expandNodes(nodes);
|
||||||
} else if (!isEmpty(checkedValue)) {
|
} else if (!this.isEmptyValue(checkedValue)) {
|
||||||
const value = multiple ? checkedValue[0] : checkedValue;
|
const value = multiple ? checkedValue[0] : checkedValue;
|
||||||
const checkedNode = this.getNodeByValue(value) || {};
|
const checkedNode = this.getNodeByValue(value) || {};
|
||||||
const nodes = (checkedNode.pathNodes || []).slice(0, -1);
|
const nodes = (checkedNode.pathNodes || []).slice(0, -1);
|
||||||
|
@ -361,7 +369,7 @@ export default {
|
||||||
const nodes = this.getFlattedNodes(leafOnly);
|
const nodes = this.getFlattedNodes(leafOnly);
|
||||||
return nodes.filter(node => node.checked);
|
return nodes.filter(node => node.checked);
|
||||||
} else {
|
} else {
|
||||||
return isEmpty(checkedValue)
|
return this.isEmptyValue(checkedValue)
|
||||||
? []
|
? []
|
||||||
: [this.getNodeByValue(checkedValue)];
|
: [this.getNodeByValue(checkedValue)];
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,12 +51,8 @@ export default class Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
getNodeByValue(value) {
|
getNodeByValue(value) {
|
||||||
if (value) {
|
const nodes = this.getFlattedNodes(false, !this.config.lazy)
|
||||||
const nodes = this.getFlattedNodes(false, !this.config.lazy)
|
.filter(node => (valueEquals(node.path, value) || node.value === value));
|
||||||
.filter(node => (valueEquals(node.path, value) || node.value === value));
|
return nodes && nodes.length ? nodes[0] : null;
|
||||||
return nodes && nodes.length ? nodes[0] : null;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
dropDownVisible: false,
|
dropDownVisible: false,
|
||||||
checkedValue: this.value || null,
|
checkedValue: this.value,
|
||||||
inputHover: false,
|
inputHover: false,
|
||||||
inputValue: null,
|
inputValue: null,
|
||||||
presentText: null,
|
presentText: null,
|
||||||
|
@ -350,7 +350,7 @@ export default {
|
||||||
this.inputInitialHeight = input.$el.offsetHeight || InputSizeMap[this.realSize] || 40;
|
this.inputInitialHeight = input.$el.offsetHeight || InputSizeMap[this.realSize] || 40;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEmpty(this.value)) {
|
if (!this.isEmptyValue(this.value)) {
|
||||||
this.computePresentContent();
|
this.computePresentContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,9 +485,17 @@ export default {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
isEmptyValue(val) {
|
||||||
|
const { multiple } = this;
|
||||||
|
const { emitPath } = this.panel.config;
|
||||||
|
if (multiple || emitPath) {
|
||||||
|
return isEmpty(val);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
computePresentText() {
|
computePresentText() {
|
||||||
const { checkedValue, config } = this;
|
const { checkedValue, config } = this;
|
||||||
if (!isEmpty(checkedValue)) {
|
if (!this.isEmptyValue(checkedValue)) {
|
||||||
const node = this.panel.getNodeByValue(checkedValue);
|
const node = this.panel.getNodeByValue(checkedValue);
|
||||||
if (node && (config.checkStrictly || node.isLeaf)) {
|
if (node && (config.checkStrictly || node.isLeaf)) {
|
||||||
this.presentText = node.getText(this.showAllLevels, this.separator);
|
this.presentText = node.getText(this.showAllLevels, this.separator);
|
||||||
|
|
Loading…
Reference in New Issue