资源管理1.0(树结构)

This commit is contained in:
xbx 2023-11-19 01:20:13 +08:00
parent 34f34f5292
commit 00dc394dfc
1 changed files with 134 additions and 0 deletions

View File

@ -0,0 +1,134 @@
<template>
<div :style="{ height: String(height) + 'px' }" class="tree">
<div class="title"><span>地址树</span><span><a-icon type="redo" @click="getTreeData"
style="float: right;margin-right: 20px;" /></span></div>
<div class="tree-border"></div>
<div class="tree-content">
<div v-if="isLoading" class="example">
<a-spin tip="加载中..."></a-spin>
</div>
<a-tree default-expand-all :tree-data="treeData" @select="onSelect" v-if="treeData.length > 0 && !isLoading">
<template #title="{ key: treeKey, title }">
<span>{{ title }}</span>
</template>
</a-tree>
<a-empty v-if="treeData.length === 0 && !isLoading" />
</div>
</div>
</template>
<script>
import { getAction } from '@/api/manage'
export default {
name: 'locationaTree',
props: {
//
height: {
type: Number,
default: 530
},
},
data() {
return {
showLine: true,
showIcon: false,
treeData: [],
getTreeUrl: '/rms/rmsLocation/getTree',
isLoading: false,
};
},
mounted() {
//
this.getTreeData();
},
methods: {
// onSelect
onSelect(selectedKeys, info) {
if (selectedKeys.length === 0) {
this.$emit('onSelect', []);
return;
}
const selectedKey = selectedKeys[0];
//
const findNode = (key, nodes) => {
for (let node of nodes) {
if (node.key === key) {
return node;
}
if (node.children) {
const found = findNode(key, node.children);
if (found) {
return found;
}
}
}
return null;
};
const selectedNode = findNode(selectedKey, this.treeData);
const childKeys = this.collectChildKeys(selectedNode);
childKeys.push(selectedKey);
//
this.$emit('onSelect', childKeys);
},
collectChildKeys(node, keys = []) {
if (!node) {
return keys;
}
// children
if (node.children && node.children.length > 0) {
node.children.forEach(child => {
keys.push(child.key);
this.collectChildKeys(child, keys);
});
}
return keys;
},
getTreeData() {
this.isLoading = true;
getAction(this.getTreeUrl, {}).then(res => {
if (res.success) {
this.isLoading = false;
this.treeData = res.result;
}
});
},
},
};
</script>
<style scoped>
.tree {
width: 100%;
height: 500px;
padding: 10px;
position: relative;
z-index: 999;
.title {
line-height: 30px;
font-size: 20px;
font-weight: bold;
margin-bottom: 10px;
}
/* 树边框 */
.tree-border {
border-top: 1px solid #cdcdcd;
width: 80%;
}
.tree-content {
height: 100%;
overflow: auto;
padding: 10px;
.example {
text-align: center;
border-radius: 4px;
margin-bottom: 20px;
padding: 30px 50px;
margin: 20px 0;
top: 50%;
position: relative;
}
}
}
</style>