Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/cascader-panel/src/cascader-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default {
},

mounted() {
if (!isEmpty(this.value)) {
if (!this.isEmptyValue(this.value)) {
this.syncCheckedValue();
}
},
Expand Down Expand Up @@ -195,13 +195,21 @@ export default {
node.syncCheckState(this.checkedValue);
});
},
isEmptyValue(val) {
const { multiple, config } = this;
const { emitPath } = config;
if (multiple || emitPath) {
return isEmpty(val);
}
return false;
},
syncActivePath() {
const { store, multiple, activePath, checkedValue } = this;

if (!isEmpty(activePath)) {
const nodes = activePath.map(node => this.getNodeByValue(node.getValue()));
this.expandNodes(nodes);
} else if (!isEmpty(checkedValue)) {
} else if (!this.isEmptyValue(checkedValue)) {
const value = multiple ? checkedValue[0] : checkedValue;
const checkedNode = this.getNodeByValue(value) || {};
const nodes = (checkedNode.pathNodes || []).slice(0, -1);
Expand Down Expand Up @@ -361,7 +369,7 @@ export default {
const nodes = this.getFlattedNodes(leafOnly);
return nodes.filter(node => node.checked);
} else {
return isEmpty(checkedValue)
return this.isEmptyValue(checkedValue)
? []
: [this.getNodeByValue(checkedValue)];
}
Expand Down
10 changes: 3 additions & 7 deletions packages/cascader-panel/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ export default class Store {
}

getNodeByValue(value) {
if (value) {
const nodes = this.getFlattedNodes(false, !this.config.lazy)
.filter(node => (valueEquals(node.path, value) || node.value === value));
return nodes && nodes.length ? nodes[0] : null;
}
return null;
const nodes = this.getFlattedNodes(false, !this.config.lazy)
.filter(node => (valueEquals(node.path, value) || node.value === value));
return nodes && nodes.length ? nodes[0] : null;
}

}
14 changes: 11 additions & 3 deletions packages/cascader/src/cascader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export default {
data() {
return {
dropDownVisible: false,
checkedValue: this.value || null,
checkedValue: this.value,
inputHover: false,
inputValue: null,
presentText: null,
Expand Down Expand Up @@ -350,7 +350,7 @@ export default {
this.inputInitialHeight = input.$el.offsetHeight || InputSizeMap[this.realSize] || 40;
}

if (!isEmpty(this.value)) {
if (!this.isEmptyValue(this.value)) {
this.computePresentContent();
}

Expand Down Expand Up @@ -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() {
const { checkedValue, config } = this;
if (!isEmpty(checkedValue)) {
if (!this.isEmptyValue(checkedValue)) {
const node = this.panel.getNodeByValue(checkedValue);
if (node && (config.checkStrictly || node.isLeaf)) {
this.presentText = node.getText(this.showAllLevels, this.separator);
Expand Down