OrganizationIdTree.vue
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<template>
<div class="organization-tree flex relative">
<div class="cursor-pointer flex py-4 fold-icon" :class="foldFlag ? 'absolute' : ''">
<div @click="handleFold">
<DoubleRightOutlined :class="[foldFlag ? '' : 'rotate-180']" class="text-xl transform" />
</div>
</div>
<div
:style="{ width: foldFlag ? '0px' : '100%' }"
:class="[foldFlag ? '' : 'my-4 ml-2']"
class="bg-white mr-0 overflow-hidden"
>
<BasicTree
title="组织列表"
toolbar
search
:clickRowToExpand="false"
:treeData="treeData"
:expandedKeys="treeExpandData"
:replaceFields="{ key: 'id', title: 'name' }"
:selectedKeys="selectedKeys"
@select="handleSelect"
v-bind="$attrs"
/>
</div>
</div>
</template>
<script lang="ts" setup name="OrganizationIdTree">
import { onMounted, ref, unref } from 'vue';
import { BasicTree, TreeItem } from '/@/components/Tree';
import { getOrganizationList } from '/@/api/system/system';
import { DoubleRightOutlined } from '@ant-design/icons-vue';
const emit = defineEmits(['select']);
const treeData = ref<TreeItem[]>([]);
const selectedKeys = ref<string[]>();
const treeExpandData = ref([]);
//获取所有父级id
function findForAllId(data = [], arr = []) {
for (const item of data) {
arr.push(item.id);
}
return arr;
}
function handleSelect(keys) {
emit('select', keys[0]);
}
function resetOrganization() {
selectedKeys.value = [];
}
const foldFlag = ref(true);
const handleFold = () => {
foldFlag.value = !unref(foldFlag);
};
onMounted(async () => {
treeData.value = (await getOrganizationList()) as unknown as TreeItem[];
const getAllIds = findForAllId(treeData.value as any, []);
//设置要展开的id
treeExpandData.value = getAllIds;
});
defineExpose({
resetOrganization,
});
</script>
<style scoped lang="less">
.organization-tree {
.expand {
opacity: 0;
}
&:hover {
.expand {
opacity: 1;
}
}
}
</style>