|
27 | 27 |
|
28 | 28 | <template> |
29 | 29 | <div |
| 30 | + v-if="allHostList.length > 0" |
30 | 31 | class="server-panel-action-extend" |
31 | 32 | @click.stop="" |
32 | 33 | @mouseleave="handleHide"> |
33 | | - <icon type="more" /> |
| 34 | + <div v-bk-tooltips="$t('复制所有')"> |
| 35 | + <icon type="more" /> |
| 36 | + </div> |
34 | 37 | <div |
35 | 38 | ref="popoverContent" |
36 | 39 | class="server-action-extend-content" |
37 | 40 | @click="handleWraperClick" |
38 | 41 | @mouseleave="handleClose" |
39 | 42 | @mouseover="handleShow"> |
40 | | - <template v-if="copyable"> |
41 | | - <div |
42 | | - class="action-item" |
43 | | - @click="handleCopyAll"> |
44 | | - {{ $t('复制所有 IP') }} |
45 | | - </div> |
46 | | - <div |
47 | | - class="action-item" |
48 | | - @click="handleCopyFail"> |
49 | | - {{ $t('复制异常 IP') }} |
50 | | - </div> |
51 | | - </template> |
52 | | - <slot /> |
| 43 | + <div |
| 44 | + class="action-item" |
| 45 | + @click="() => handleCopyIPv4()"> |
| 46 | + IPV4 |
| 47 | + </div> |
| 48 | + <div |
| 49 | + class="action-item" |
| 50 | + @click="() => handleCopyIPv4(true)"> |
| 51 | + {{ $t('管控区域 ID:IPv4') }} |
| 52 | + </div> |
| 53 | + <div |
| 54 | + class="action-item" |
| 55 | + @click="() => handleCopyIPv6()"> |
| 56 | + IPV6 |
| 57 | + </div> |
| 58 | + <div |
| 59 | + class="action-item" |
| 60 | + @click="() => handleCopyIPv6(true)"> |
| 61 | + {{ $t('管控区域 ID:IPv6') }} |
| 62 | + </div> |
| 63 | + <div |
| 64 | + class="action-item" |
| 65 | + @click="handleCopyHostId"> |
| 66 | + {{ $t('主机 ID') }} |
| 67 | + </div> |
53 | 68 | </div> |
54 | 69 | </div> |
55 | 70 | </template> |
56 | 71 | <script> |
| 72 | +
|
| 73 | + import _ from 'lodash'; |
| 74 | +
|
| 75 | + import HomeService from '@service/home'; |
| 76 | +
|
57 | 77 | import { |
58 | 78 | execCopy, |
59 | 79 | } from '@utils/assist'; |
|
69 | 89 | type: Array, |
70 | 90 | default: () => [], |
71 | 91 | }, |
72 | | - invalidList: { |
73 | | - type: Array, |
74 | | - default: () => [], |
| 92 | + agentStatus: { |
| 93 | + type: Number, |
75 | 94 | }, |
76 | | - copyable: { |
77 | | - type: Boolean, |
78 | | - default: false, |
| 95 | + }, |
| 96 | + data() { |
| 97 | + return { |
| 98 | + allHostList: [], |
| 99 | + }; |
| 100 | + }, |
| 101 | + watch: { |
| 102 | + agentStatus: { |
| 103 | + handler() { |
| 104 | + if (this.agentStatus > -1) { |
| 105 | + this.fetchData(); |
| 106 | + } |
| 107 | + }, |
| 108 | + immediate: true, |
79 | 109 | }, |
80 | 110 | }, |
81 | 111 | created() { |
82 | 112 | this.id = `action_extend_${Math.random()}_${Math.random()}`; |
83 | 113 | }, |
84 | | - mounted() { |
85 | | - this.init(); |
86 | | - }, |
87 | 114 | beforeDestroy() { |
88 | 115 | instanceMap[this.id].hide(); |
89 | 116 | delete instanceMap[this.id]; |
90 | 117 | }, |
91 | 118 | methods: { |
| 119 | + fetchData() { |
| 120 | + HomeService.fetchAgentStatus({ |
| 121 | + agentStatus: this.agentStatus, |
| 122 | + }).then((data) => { |
| 123 | + this.allHostList = data.data; |
| 124 | + if (this.allHostList.length > 0) { |
| 125 | + setTimeout(() => { |
| 126 | + this.init(); |
| 127 | + }); |
| 128 | + } |
| 129 | + }); |
| 130 | + }, |
92 | 131 | /** |
93 | 132 | * @desc 弹层面板初始化 |
94 | 133 | */ |
|
123 | 162 | this.handleClose(); |
124 | 163 | }, 3000); |
125 | 164 | }, |
126 | | - /** |
127 | | - * @desc 复制所有主机 |
128 | | - */ |
129 | | - handleCopyAll() { |
130 | | - if (this.list.length < 1 && this.invalidList.length < 1) { |
131 | | - this.messageWarn(I18n.t('你还未选择主机')); |
| 165 | +
|
| 166 | + handleCopyIPv4(withNet = false) { |
| 167 | + const allIP = _.filter(this.allHostList.map(host => (withNet ? `${host.cloudArea.id}:${host.ip}` : host.ip)), item => !!item); |
| 168 | +
|
| 169 | + if (allIP.length < 1) { |
| 170 | + this.messageWarn(I18n.t('home.没有可复制的 IPv4')); |
132 | 171 | return; |
133 | 172 | } |
134 | | - let allIP = this.list.map(host => host.ip); |
135 | | - const allInvalidList = this.invalidList.map(host => host.ip); |
136 | | - allIP = [ |
137 | | - ...allIP, ...allInvalidList, |
138 | | - ]; |
139 | | - execCopy(allIP.join('\n'), `${I18n.t('复制成功')}(${allIP.length}${I18n.t('个IP')})`); |
| 173 | + execCopy(allIP.join('\n'), `${I18n.t('home.复制成功')}(${allIP.length}${I18n.t('home.个IP')})`); |
140 | 174 | }, |
141 | | - /** |
142 | | - * @desc 复制异常主机 |
143 | | - */ |
144 | | - handleCopyFail() { |
145 | | - if (this.list.length < 1 && this.invalidList.length < 1) { |
146 | | - this.messageWarn(I18n.t('你还未选择主机')); |
| 175 | + handleCopyIPv6(withNet = false) { |
| 176 | + const ipv6HostList = _.filter(this.allHostList, host => !!host.ipv6); |
| 177 | + if (ipv6HostList.length < 1) { |
| 178 | + this.messageWarn(I18n.t('home.没有可复制的 IPv6')); |
147 | 179 | return; |
148 | 180 | } |
149 | | - let allFailIp = []; |
150 | | - this.list.forEach((currentHost) => { |
151 | | - if (!currentHost.alive) { |
152 | | - allFailIp.push(currentHost.ip); |
153 | | - } |
154 | | - }); |
155 | | - if (allFailIp.length < 1 && this.invalidList.length < 1) { |
156 | | - this.messageWarn(I18n.t('暂无异常主机')); |
| 181 | + const allIP = _.filter(ipv6HostList.map(host => (withNet ? `${host.cloudArea.id}:${host.ipv6}` : host.ipv6)), item => !!item); |
| 182 | +
|
| 183 | + execCopy(allIP.join('\n'), `${I18n.t('home.复制成功')}(${allIP.length}${I18n.t('home.个IP')})`); |
| 184 | + }, |
| 185 | + /** |
| 186 | + * @desc 复制主机ID |
| 187 | + */ |
| 188 | + handleCopyHostId() { |
| 189 | + const allHostId = this.allHostList.map(host => host.hostId); |
| 190 | + if (allHostId.length < 1) { |
| 191 | + this.messageWarn(I18n.t('home.没有可复制的主机ID')); |
157 | 192 | return; |
158 | 193 | } |
159 | | - const allInvalidList = this.invalidList.map(host => host.ip); |
160 | | - allFailIp = [ |
161 | | - ...allFailIp, ...allInvalidList, |
162 | | - ]; |
163 | | - execCopy(allFailIp.join('\n'), `${I18n.t('复制成功')}(${allFailIp.length}${I18n.t('个异常IP')})`); |
| 194 | + execCopy(allHostId.join('\n'), `${I18n.t('home.复制成功')}(${allHostId.length}${I18n.t('home.个主机ID')})`); |
164 | 195 | }, |
165 | 196 | handleShow() { |
166 | 197 | clearTimeout(this.leaveTimer); |
|
172 | 203 | }; |
173 | 204 | </script> |
174 | 205 | <style lang="postcss"> |
175 | | - html[lang="en-US"] { |
176 | | - .server-action-extend-content { |
177 | | - width: 154px; |
178 | | - } |
179 | | - } |
180 | | -
|
181 | 206 | .server-panel-action-extend { |
182 | 207 | position: absolute; |
183 | 208 | top: 50%; |
|
212 | 237 | } |
213 | 238 |
|
214 | 239 | .server-action-extend-content { |
215 | | - width: 93px; |
216 | | - font-size: 14px; |
| 240 | + font-size: 12px; |
217 | 241 | line-height: 32px; |
218 | 242 | color: #63656e; |
219 | 243 | background: #fff; |
220 | 244 | border: 1px solid #f0f1f5; |
221 | 245 | box-shadow: 0 2px 1px 0 rgb(185 203 222 / 50%); |
222 | 246 |
|
223 | 247 | .action-item { |
224 | | - padding-left: 15px; |
| 248 | + padding: 0 15px; |
225 | 249 | cursor: pointer; |
226 | 250 |
|
| 251 | +
|
227 | 252 | &:hover { |
228 | 253 | color: #3a84ff; |
229 | 254 | background: #e5efff; |
|
0 commit comments