Skip to content

Commit

Permalink
Merge pull request #438 from qishibo/multi_delete
Browse files Browse the repository at this point in the history
keep folder in front of list
  • Loading branch information
qishibo authored Feb 2, 2021
2 parents 98b5a79 + 1f7eeca commit eb3e726
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/components/KeyListTree.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<div ref="treeWrapper" class='key-list-ztree'>

<!-- multi operate -->
<el-row class="batch-operate" :gutter="6">
<el-col :span="12">
Expand Down Expand Up @@ -42,7 +41,6 @@ export default {
data() {
return {
treeId: 'treeId' + Math.ceil(Math.random() * 1e10),
separator: this.config.separator ? this.config.separator : ':',
openStatus: {},
rightClickNode: {},
multiOperating: false,
Expand Down Expand Up @@ -101,6 +99,11 @@ export default {
};
},
props: ['client', 'config', 'keyList'],
computed: {
separator() {
return this.config.separator ? this.config.separator : ':';
}
},
methods: {
showMultiSelect() {
this.multiOperating = true;
Expand Down Expand Up @@ -235,13 +238,7 @@ export default {
treeRefresh(nodes) {
// this.ztreeObj && this.ztreeObj.destroy();
// folder keep in front
nodes = nodes.sort(function(a, b) {
if (a.children && b.children) {
return 0;
}

return a.children ? -1 : (b.children ? 1 : 0);
});
this.$util.sortNodes(nodes);

this.ztreeObj = $.fn.zTree.init(
$(`#${this.treeId}`),
Expand Down
14 changes: 13 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export default {
let tillNowKeyName = previousKey + key + separator;
node.open = !!openStatus[tillNowKeyName];
node.children = this.formatTreeData(tree[key], tillNowKeyName, openStatus, separator);
// keep folder node in top of the tree(not include the outest list)
this.sortNodes(node.children);
node.keyCount = node.children.reduce((a, b) => a + (b.keyCount || 0), 0);
node.fullName = tillNowKeyName;
}
Expand All @@ -140,5 +142,15 @@ export default {

return node;
});
}
},
// nodes is reference
sortNodes(nodes) {
nodes.sort(function(a, b) {
if (a.children && b.children) {
return 0;
}

return a.children ? -1 : (b.children ? 1 : 0);
});
},
};

0 comments on commit eb3e726

Please sign in to comment.