columns.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import i18n from '@/locales'
  2. import { getCopyWithContentTableColumn, getTimeTableColumn, getStatusTableColumn, getBillingTypeTableColumn } from '@/utils/common/tableColumn'
  3. export default {
  4. props: {
  5. data: {
  6. type: Object,
  7. default: () => ({}),
  8. },
  9. },
  10. created () {
  11. this.columns = [
  12. {
  13. field: 'index',
  14. title: i18n.t('compute.text_375'),
  15. width: 50,
  16. slots: {
  17. default: ({ rowIndex }) => {
  18. return rowIndex
  19. },
  20. },
  21. },
  22. getCopyWithContentTableColumn({ field: 'ifname', title: i18n.t('compute.text_384'), sortable: true }),
  23. getCopyWithContentTableColumn({ field: 'mac_addr', title: i18n.t('compute.text_385'), sortable: true }),
  24. {
  25. field: 'ip_addr',
  26. title: i18n.t('compute.text_386'),
  27. sortable: true,
  28. showOverflow: 'ellipsis',
  29. minWidth: 100,
  30. slots: {
  31. default: ({ row }, h) => {
  32. if (row.ip_addr) {
  33. const addrs = [
  34. <div>{i18n.t('compute.text_386')}: {row.ip_addr}/{row.guest_ip_mask}</div>,
  35. <div>{i18n.t('network.ipv4.gateway')}: {row.guest_gateway}</div>,
  36. ]
  37. if (row.mapped_ip_addr) {
  38. addrs.push(<div>{i18n.t('compute.vpc.mapped_addr')}: {row.mapped_ip_addr}</div>)
  39. }
  40. const ret = [
  41. <a-popover>
  42. <template slot="content">
  43. {addrs}
  44. </template>
  45. <list-body-cell-wrap copy row={row} field="ip_addr" hideField={true}>
  46. {row.ip_addr}/{row.guest_ip_mask}
  47. </list-body-cell-wrap>
  48. </a-popover>,
  49. ]
  50. return ret
  51. }
  52. return '-'
  53. },
  54. },
  55. },
  56. {
  57. field: 'ip6_addr',
  58. title: i18n.t('compute.ipv6.address'),
  59. sortable: true,
  60. showOverflow: 'ellipsis',
  61. minWidth: 200,
  62. slots: {
  63. default: ({ row }, h) => {
  64. if (row.ip6_addr) {
  65. const addrs = [
  66. <div>{i18n.t('compute.ipv6.address')}: {row.ip6_addr}/{row.guest_ip6_mask}</div>,
  67. <div>{i18n.t('network.ipv6.gateway')}: {row.guest_gateway6}</div>,
  68. ]
  69. if (row.mapped_ip6_addr) {
  70. addrs.push(<div>{i18n.t('compute.vpc.mapped_addr')}: {row.mapped_ip6_addr}</div>)
  71. }
  72. const ret = [
  73. <a-popover>
  74. <template slot="content">
  75. {addrs}
  76. </template>
  77. <list-body-cell-wrap copy row={row} field="ip6_addr" hideField={true}>
  78. {row.ip6_addr}/{row.guest_ip6_mask}
  79. </list-body-cell-wrap>
  80. </a-popover>,
  81. ]
  82. return ret
  83. }
  84. return '-'
  85. },
  86. },
  87. },
  88. getCopyWithContentTableColumn({ field: 'eip_addr', title: 'EIP', sortable: true }),
  89. getCopyWithContentTableColumn({ field: 'driver', title: i18n.t('compute.text_860') }),
  90. {
  91. field: 'guest_id',
  92. title: i18n.t('compute.text_106'),
  93. sortable: true,
  94. showOverflow: 'ellipsis',
  95. minWidth: 100,
  96. slots: {
  97. default: ({ row }, h) => {
  98. const ret = [
  99. <list-body-cell-wrap copy row={row} field="network" hideField={true}>
  100. <side-page-trigger onTrigger={() => this.handleOpenNetworkDetail(row.network_id)}>{row.network}</side-page-trigger>
  101. </list-body-cell-wrap>,
  102. ]
  103. return ret
  104. },
  105. },
  106. },
  107. {
  108. field: 'bw_limit',
  109. title: i18n.t('compute.text_387'),
  110. width: 100,
  111. formatter: ({ row }) => {
  112. if (row.rx_bw_limit && row.tx_bw_limit) {
  113. return `${row.tx_bw_limit}Mbps/${row.rx_bw_limit}Mbps`
  114. }
  115. if (+row.bw_limit) {
  116. return `${row.bw_limit}Mbps`
  117. }
  118. return `0(${this.$t('common.not_limited')})`
  119. },
  120. slots: {
  121. default: ({ row }, h) => {
  122. const ret = []
  123. if (row.rx_bw_limit && row.tx_bw_limit) {
  124. ret.push(<div> <a-icon type="arrow-up" /> {row.tx_bw_limit} Mbps</div>)
  125. ret.push(<div> <a-icon type="arrow-down" /> {row.rx_bw_limit} Mbps</div>)
  126. } else if (+row.bw_limit) {
  127. ret.push(<div> <a-icon type="swap" /> {row.bw_limit}Mbps </div>)
  128. } else {
  129. ret.push(<div>0({this.$t('common.not_limited')})</div>)
  130. }
  131. return ret
  132. },
  133. },
  134. },
  135. getBillingTypeTableColumn(),
  136. {
  137. field: 'num_queues',
  138. title: i18n.t('compute.num_queues'),
  139. slots: {
  140. default: ({ row }) => {
  141. return row.num_queues || '-'
  142. },
  143. },
  144. },
  145. getStatusTableColumn({
  146. field: 'is_default',
  147. title: i18n.t('compute.nics.is_default'),
  148. statusModule: 'enabled',
  149. minWidth: 30,
  150. }),
  151. {
  152. field: 'network_addresses',
  153. title: i18n.t('compute.sub_ips.title'),
  154. slots: {
  155. default: ({ row }) => {
  156. const { network_addresses = [] } = row
  157. const ret = []
  158. network_addresses.map(item => {
  159. if (item.type === 'sub_ip') {
  160. ret.push(<list-body-cell-wrap copy row={{ ip: item.ip_addr }} field="ip" hideField={true}>{item.ip_addr}</list-body-cell-wrap>)
  161. }
  162. })
  163. return ret.length ? ret : '-'
  164. },
  165. },
  166. },
  167. {
  168. field: 'port_mappings',
  169. title: i18n.t('compute.port_mappings.title', 'port'),
  170. slots: {
  171. default: ({ row }) => {
  172. return [
  173. this.$t('compute.text_619', [row.port_mappings ? row.port_mappings.length : 0]),
  174. <a-button type="link" class={'pl-1'} onClick={() => this.viewContentDialog(row.port_mappings, this.$t('compute.port_mappings.title'), 'port')}>{this.$t('common.view')}</a-button>,
  175. ]
  176. },
  177. },
  178. },
  179. getTimeTableColumn(),
  180. {
  181. field: 'secgroups',
  182. title: i18n.t('compute.text_105'),
  183. slots: {
  184. default: ({ row }) => {
  185. const target = (this.data.network_secgroups || []).filter(item => item.mac === row.mac_addr)
  186. console.log(target)
  187. return target.length ? target[0].secgroups.map(item => {
  188. return <list-body-cell-wrap copy hideField={true} field='name' row={item} message={item.name}>
  189. <side-page-trigger permission='secgroups_get' name='SecGroupSidePage' id={item.id} vm={this} tab='secgroup-detail'>{ item.name }</side-page-trigger>
  190. </list-body-cell-wrap>
  191. }) : '-'
  192. },
  193. },
  194. formatter: ({ row }) => {
  195. const target = (this.data.network_secgroups || []).filter(item => item.mac === row.mac_addr)
  196. return target.length ? target[0].secgroups.map(item => item.name).join(',') : '-'
  197. },
  198. },
  199. ]
  200. },
  201. methods: {
  202. viewContentDialog (data, title, type) {
  203. this.createDialog('ViewContentDialog', {
  204. title,
  205. data,
  206. type,
  207. })
  208. },
  209. },
  210. }