forked from TencentBlueKing/bk-job
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.vue
158 lines (143 loc) · 4.28 KB
/
index.vue
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
<div class="bk-ip-selector-views">
<search-host
v-if="isShowHostSearch"
class="view-host-serach"
:data="lastHostList"
:search-key="searchKey"
@change="handleChange" />
<div
v-show="!searchKey"
class="views-container">
<render-host
v-if="lastHostList && lastHostList.length > 0"
ref="hostRef"
:data="lastHostList"
@change="handleChange" />
<render-node
v-if="lastNodeList && lastNodeList.length > 0"
ref="nodeRef"
:data="lastNodeList"
@change="handleChange" />
<render-dynamic-group
v-if="lastDynamicGroupList && lastDynamicGroupList.length > 0"
ref="dynamicGroupRef"
:data="lastDynamicGroupList"
@change="handleChange" />
</div>
</div>
</template>
<script setup>
import {
computed,
ref,
shallowRef,
watch,
} from 'vue';
import {
formatInput,
formatOutput,
} from '../utils';
import SearchHost from './components/search-host.vue';
import RenderDynamicGroup from './dynamic-group.vue';
import RenderHost from './host.vue';
import RenderNode from './node.vue';
const props = defineProps({
value: {
type: Object,
default: () => ({
hostList: [],
nodeList: [],
dynamicGroupList: [],
}),
},
searchKey: {
type: String,
},
});
const emits = defineEmits(['change']);
const lastHostList = shallowRef([]);
const lastNodeList = shallowRef([]);
const lastDynamicGroupList = shallowRef([]);
const hostRef = ref();
const nodeRef = ref();
const dynamicGroupRef = ref();
const isShowHostSearch = computed(() => {
if (!props.value.hostList || props.value.hostList.length < 1) {
return false;
}
return Boolean(props.searchKey);
});
let isInnerChange = false;
watch(() => props.value, () => {
if (isInnerChange) {
isInnerChange = false;
return;
}
const {
host_list: hostList,
node_list: nodeList,
dynamic_group_list: dynamicGroupList,
} = formatInput(props.value || {});
lastHostList.value = hostList;
lastNodeList.value = nodeList;
lastDynamicGroupList.value = dynamicGroupList;
}, {
immediate: true,
});
const handleChange = (name, value) => {
switch (name) {
case 'hostList':
lastHostList.value = value;
break;
case 'nodeList':
lastNodeList.value = value;
break;
case 'dynamicGroupList':
lastDynamicGroupList.value = value;
break;
}
isInnerChange = true;
emits('change', formatOutput({
hostList: lastHostList.value,
nodeList: lastNodeList.value,
dynamicGroupList: lastDynamicGroupList.value,
}));
};
defineExpose({
getHostIpList () {
if (!hostRef.value) {
return [];
}
return hostRef.value.getHostIpList();
},
getAbnormalHostIpList () {
if (!hostRef.value) {
return [];
}
return hostRef.value.getAbnormalHostIpList();
},
refresh () {
hostRef.value && hostRef.value.refresh();
nodeRef.value && nodeRef.value.refresh();
dynamicGroupRef.value && dynamicGroupRef.value.refresh();
},
collapseToggle (toggle) {
hostRef.value && hostRef.value.collapseToggle(toggle);
nodeRef.value && nodeRef.value.collapseToggle(toggle);
dynamicGroupRef.value && dynamicGroupRef.value.collapseToggle(toggle);
},
});
</script>
<style lang="postcss">
.bk-ip-selector-views {
.view-host-serach {
margin-top: 16px;
}
.views-container {
& > * {
margin-top: 16px;
}
}
}
</style>