17
17
18
18
<template >
19
19
<a
20
- v-if =" ['vm', 'systemvm', 'router', 'ilbvm', 'vnfapp'].includes($route.meta.name) && 'listVirtualMachines' in $store.getters.apis && 'createConsoleEndpoint' in $store.getters.apis"
20
+ v-if =" ['vm', 'systemvm', 'router', 'ilbvm', 'vnfapp'].includes($route.meta.name) &&
21
+ 'listVirtualMachines' in $store.getters.apis &&
22
+ 'createConsoleEndpoint' in $store.getters.apis"
21
23
@click =" consoleUrl" >
22
- <a-button style =" margin-left : 5px " shape =" circle" type =" dashed" :size =" size" :disabled =" ['Stopped', 'Restoring', 'Error', 'Destroyed'].includes(resource.state) || resource.hostcontrolstate === 'Offline'" >
24
+ <a-button
25
+ style =" margin-left : 5px "
26
+ shape =" circle"
27
+ type =" dashed"
28
+ :size =" size"
29
+ :disabled =" ['Stopped', 'Restoring', 'Error', 'Destroyed'].includes(resource.state) ||
30
+ resource.hostcontrolstate === 'Offline'" >
23
31
<code-outlined v-if =" !copyUrlToClipboard" />
24
32
<copy-outlined v-else />
25
33
</a-button >
@@ -49,11 +57,29 @@ export default {
49
57
}
50
58
},
51
59
methods: {
52
- consoleUrl () {
53
- const params = {}
54
- params .virtualmachineid = this .resource .id
55
- postAPI (' createConsoleEndpoint' , params).then (json => {
56
- this .url = (json && json .createconsoleendpointresponse ) ? json .createconsoleendpointresponse .consoleendpoint .url : ' #/exception/404'
60
+ async consoleUrl () {
61
+ try {
62
+ const externalUrl = this .resource ? .details ? .[' External:console_url' ]
63
+ if (externalUrl) {
64
+ this .url = externalUrl
65
+ if (this .copyUrlToClipboard ) {
66
+ this .$copyText (this .url )
67
+ this .$message .success ({
68
+ content: this .$t (' label.copied.clipboard' )
69
+ })
70
+ } else {
71
+ window .open (this .url , ' _blank' )
72
+ }
73
+ return
74
+ }
75
+
76
+ const params = { virtualmachineid: this .resource .id }
77
+ const json = await postAPI (' createConsoleEndpoint' , params)
78
+
79
+ this .url = (json && json .createconsoleendpointresponse )
80
+ ? json .createconsoleendpointresponse .consoleendpoint .url
81
+ : ' #/exception/404'
82
+
57
83
if (json .createconsoleendpointresponse .consoleendpoint .success ) {
58
84
if (this .copyUrlToClipboard ) {
59
85
this .$copyText (this .url )
@@ -69,9 +95,9 @@ export default {
69
95
description: json .createconsoleendpointresponse .consoleendpoint .details
70
96
})
71
97
}
72
- }). catch (error => {
98
+ } catch (error) {
73
99
this .$notifyError (error)
74
- })
100
+ }
75
101
}
76
102
},
77
103
computed: {
0 commit comments