Detail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <detail
  3. :on-manager="onManager"
  4. :data="data"
  5. :base-info="baseInfo"
  6. :extra-info="extraInfo"
  7. resource="networks"
  8. status-module="network"
  9. auto-hidden-columns-key="network_hidden_columns" />
  10. </template>
  11. <script>
  12. import {
  13. getBrandTableColumn,
  14. getCopyWithContentTableColumn,
  15. getPublicScopeTableColumn,
  16. } from '@/utils/common/tableColumn'
  17. import {
  18. getUserTagColumn,
  19. getExtTagColumn,
  20. } from '@/utils/common/detailColumn'
  21. import WindowsMixin from '@/mixins/windows'
  22. export default {
  23. name: 'NetworkDetail',
  24. mixins: [WindowsMixin],
  25. props: {
  26. data: {
  27. type: Object,
  28. required: true,
  29. },
  30. onManager: {
  31. type: Function,
  32. required: true,
  33. },
  34. columns: Array,
  35. },
  36. data () {
  37. const extraInfo = [
  38. {
  39. title: this.$t('network.text_308'),
  40. items: ([
  41. getCopyWithContentTableColumn({
  42. field: 'vpc',
  43. title: 'VPC',
  44. hideField: true,
  45. slotCallback: row => {
  46. if (!row.vpc) return '-'
  47. return [
  48. <side-page-trigger permission='vpcs_get' name='VpcSidePage' id={row.vpc_id} vm={this}>{ row.vpc }</side-page-trigger>,
  49. ]
  50. },
  51. }),
  52. {
  53. field: 'wire',
  54. title: this.$t('network.text_571'),
  55. slots: {
  56. default: ({ row }) => {
  57. return [
  58. <side-page-trigger permission='wires_get' name='WireSidePage' id={row.wire_id} vm={this}>{ row.wire }</side-page-trigger>,
  59. ]
  60. },
  61. },
  62. },
  63. {
  64. field: 'server_type',
  65. title: this.$t('network.text_574'),
  66. formatter: ({ cellValue }) => {
  67. if (cellValue === 'baremetal') {
  68. return this.$t('network.text_598')
  69. }
  70. if (cellValue === 'container') {
  71. return this.$t('network.text_599')
  72. }
  73. if (cellValue === 'guest') {
  74. return this.$t('network.text_226')
  75. }
  76. if (cellValue === 'eip') {
  77. return this.$t('network.text_221')
  78. }
  79. if (cellValue === 'hostlocal') {
  80. return 'HostLocal'
  81. }
  82. return this.$t('network.text_507')
  83. },
  84. },
  85. {
  86. field: 'bgp_type',
  87. title: this.$t('network.text_743'),
  88. formatter: ({ cellValue }) => {
  89. return cellValue || '-'
  90. },
  91. },
  92. {
  93. field: 'guest_ip_start',
  94. title: this.$t('network.ipv4.range'),
  95. formatter: ({ cellValue, row }) => {
  96. if (!row.guest_ip_start || !row.guest_ip_end) {
  97. return '-'
  98. }
  99. return `${cellValue} - ${row.guest_ip_end}/${row.guest_ip_mask}`
  100. },
  101. },
  102. getCopyWithContentTableColumn({
  103. field: 'guest_gateway',
  104. title: this.$t('network.ipv4.gateway'),
  105. }),
  106. {
  107. field: 'guest_ip6_start',
  108. title: this.$t('network.ipv6.range'),
  109. formatter: ({ cellValue, row }) => {
  110. if (!row.guest_ip6_start || !row.guest_ip6_end) {
  111. return '-'
  112. }
  113. return `${cellValue} - ${row.guest_ip6_end}/${row.guest_ip6_mask}`
  114. },
  115. },
  116. getCopyWithContentTableColumn({
  117. field: 'guest_gateway6',
  118. title: this.$t('network.ipv6.gateway'),
  119. }),
  120. {
  121. field: 'guest_dhcp',
  122. title: 'dhcp_relay',
  123. slots: {
  124. default: ({ row }) => {
  125. const ips = (row.guest_dhcp || '').split(',')
  126. if (!ips.length) return '-'
  127. const ret = ips.map(item => {
  128. const obj = { ip: item }
  129. return <list-body-cell-wrap copy field='ip' row={obj} hideField={true} message={item}>
  130. {item}
  131. </list-body-cell-wrap>
  132. })
  133. return ret
  134. },
  135. },
  136. },
  137. {
  138. field: 'vlan_id',
  139. title: 'VLAN ID',
  140. formatter: ({ cellValue }) => {
  141. return cellValue || '-'
  142. },
  143. },
  144. {
  145. field: 'ports',
  146. title: this.$t('network.text_622'),
  147. slots: {
  148. default: ({ row }) => {
  149. return [
  150. <i18n path='network.text_735' tag="div">
  151. <template slot='ports'>{ row.ports }</template>
  152. <template slot='ports_used'>
  153. { row.ports_used + row.ports6_used <= 0 ? 0 : <a onClick={ () => this.$emit('tab-change', 'i-p-list') }>{row.ports_used + row.ports6_used}</a> }
  154. </template>
  155. <template slot='reserve_vnics'>{ row.reserve_vnics }</template>
  156. </i18n>,
  157. ]
  158. },
  159. },
  160. },
  161. {
  162. field: 'guest_dns',
  163. title: this.$t('network.dns_server'),
  164. slots: {
  165. default: ({ row }) => {
  166. const ips = (row.guest_dns || '').split(',')
  167. if (!ips.length) return '-'
  168. const ret = ips.map(item => {
  169. const obj = { ip: item }
  170. return <list-body-cell-wrap copy field='ip' row={obj} hideField={true} message={item}>
  171. {item}
  172. </list-body-cell-wrap>
  173. })
  174. return ret
  175. },
  176. },
  177. },
  178. {
  179. field: 'guest_domain',
  180. title: this.$t('network.text_586'),
  181. formatter: ({ cellValue }) => {
  182. return cellValue || '-'
  183. },
  184. },
  185. {
  186. field: 'guest_npt',
  187. title: this.$t('network.ntp_server'),
  188. slots: {
  189. default: ({ row }) => {
  190. const ips = (row.guest_ntp || '').split(',')
  191. if (!ips.length) return '-'
  192. const ret = ips.map(item => {
  193. const obj = { ip: item }
  194. return <list-body-cell-wrap copy field='ip' row={obj} hideField={true} message={item}>
  195. {item}
  196. </list-body-cell-wrap>
  197. })
  198. return ret
  199. },
  200. },
  201. },
  202. ]).filter(item => {
  203. if (['wire', 'server_type', 'bgp_type', 'guest_dhcp', 'vlan_id'].indexOf(item.field) >= 0) {
  204. if (this.data.cloud_env === 'onpremise' && (this.data.is_classic || this.data.is_default_vpc)) {
  205. return true
  206. }
  207. return false
  208. }
  209. return !this.$isScopedPolicyMenuHidden(`network_hidden_columns.${item.field}`)
  210. }),
  211. },
  212. ]
  213. if (this.data.cloud_env === 'onpremise') {
  214. if (this.data.metadata && this.data.metadata.static_routes) {
  215. extraInfo[0].items.push({
  216. title: this.$t('network.static_routes'),
  217. slots: {
  218. default: ({ row }) => {
  219. const routes = JSON.parse(row.metadata.static_routes)
  220. console.log(routes)
  221. const comps = []
  222. return comps
  223. },
  224. },
  225. })
  226. }
  227. }
  228. if (this.data.cloud_env === 'onpremise' && this.$store.getters.capability && this.$store.getters.capability.brands && this.$store.getters.capability.brands.includes('VMware')) {
  229. extraInfo.push({
  230. title: this.$t('network.vmware_extra_info'),
  231. items: [
  232. {
  233. field: 'additional_wires',
  234. title: () => {
  235. return [
  236. this.$t('network.additional_wires.title'),
  237. <help-tooltip class="ml-1" text={ this.$t('network.additional_wires.title.tooltip') } />,
  238. ]
  239. },
  240. slots: {
  241. default: ({ row }) => {
  242. let comps = []
  243. const link = <span class='wire-edit' onclick={this.setWireHandle}>
  244. <a-icon class='mr-1' type="edit" style="font-size: 12px;" />{ this.$t('common.setting') }</span>
  245. if (!row.additional_wires) {
  246. comps.push(link)
  247. return comps
  248. }
  249. comps = row.additional_wires.map((item, idx) => {
  250. return <side-page-trigger permission='wires_get' name='WireSidePage' id={item.wire_id} vm={this}>{ item.wire }{ idx < row.additional_wires.length - 1 ? ',' : '' }</side-page-trigger>
  251. })
  252. comps.push(link)
  253. return comps
  254. },
  255. },
  256. },
  257. ],
  258. })
  259. }
  260. return {
  261. baseInfo: [
  262. getUserTagColumn({
  263. onManager: this.onManager,
  264. resource: 'network',
  265. columns: () => this.columns,
  266. tipName: this.$t('dictionary.network'),
  267. editCheck: (row) => (row.provider || '').toLowerCase() !== 'bingocloud',
  268. }),
  269. getExtTagColumn({
  270. onManager: this.onManager,
  271. resource: 'network',
  272. columns: () => this.columns,
  273. tipName: this.$t('dictionary.network'),
  274. editCheck: (row) => (row.provider || '').toLowerCase() !== 'bingocloud',
  275. }),
  276. getPublicScopeTableColumn({ vm: this, resource: 'networks' }),
  277. getBrandTableColumn(),
  278. {
  279. field: 'schedtag',
  280. title: this.$t('network.text_630'),
  281. formatter: ({ cellValue, row }) => {
  282. if (row.schedtags && row.schedtags.length > 0) {
  283. const schedtags = row.schedtags.map(v => v.name)
  284. return schedtags.join(',')
  285. }
  286. return '-'
  287. },
  288. },
  289. ],
  290. extraInfo: extraInfo,
  291. }
  292. },
  293. methods: {
  294. setWireHandle () {
  295. this.createDialog('SetAdditionalWiresDialog', {
  296. currentData: this.data,
  297. success: () => {
  298. this.$emit('refresh')
  299. },
  300. })
  301. },
  302. },
  303. }
  304. </script>
  305. <style lang="scss" scoped>
  306. .wire-edit {
  307. padding: 0 6px 0 4px;
  308. margin-left: 10px;
  309. font-size: 12px;
  310. line-height: 20px;
  311. border: 1px dashed #97a4b6;
  312. cursor: pointer;
  313. }
  314. </style>