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
81
82
83
84
85
86
87
| <template>
| <el-tree
| ref="treeRef"
| v-loading="loading"
| @node-click="onNodeClick"
| :expandOnClickNode="props.expandOnClickNode"
| :nodeKey="props.nodeKey"
| :props="props.props"
| :data="treeData"
| :defaultExpandAll="defaultExpandAll"
| >
| </el-tree>
| </template>
|
| <script setup>
|
| const props = defineProps({
| expandOnClickNode: {
| type: Boolean,
| default: false
| },
| nodeKey: {
| type: String,
| default: 'id'
| },
| subActive: {
| type: Function,
| default: () => {
| }
| },
| props: {
| type: Object,
| default: {}
| },
| defaultExpandAll: {
| type: Boolean,
| default: true
| },
| subRequest: {
| type: Function,
| default: () => {
| }
| },
| });
|
| const treeRef = ref();
|
| const form = reactive({
| active: {}
| })
|
| const loading = ref(false);
|
| const treeData = ref([]);
|
| onMounted(async () => {
| await onReload(true);
| });
|
| const onNodeClick = (row) => {
| form.active = row;
| props.subActive(row);
| }
|
| const onReload = async (bool = true) => {
| if (bool) {
| form.active = {};
| }
| loading.value = true;
| treeData.value = await props.subRequest();
| loading.value = false;
|
| if(Object.keys(form.active).length > 0) {
| await nextTick();
| treeRef.value.setCurrentKey(form.active[props.nodeKey]);
| }
| }
|
| defineExpose({
| /**
| * 初始化
| */
| onReload
| });
|
|
| </script>
|
|