columns.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // import HighLight from '../components/HighLight'
  2. import {
  3. getProjectTableColumn,
  4. getNameDescriptionTableColumn,
  5. getPublicScopeTableColumn,
  6. getTagTableColumn,
  7. getStatusTableColumn,
  8. getTimeTableColumn,
  9. getRegionTableColumn,
  10. getCopyWithContentTableColumn,
  11. getBrandTableColumn,
  12. getAccountTableColumn,
  13. } from '@/utils/common/tableColumn'
  14. import i18n from '@/locales'
  15. export default {
  16. props: {
  17. secgroupType: {
  18. type: String,
  19. validator (value) {
  20. return ['network', 'server'].includes(value)
  21. },
  22. },
  23. },
  24. created () {
  25. this.columns = [
  26. getNameDescriptionTableColumn({
  27. onManager: this.onManager,
  28. hideField: true,
  29. formRules: [
  30. { required: true, message: i18n.t('compute.text_210') },
  31. ],
  32. edit: this.secgroupType !== 'network',
  33. editDesc: this.secgroupType !== 'network',
  34. slotCallback: row => {
  35. return (
  36. <side-page-trigger onTrigger={ () => this.handleOpenSidepage(row) }>{ row.name || row.secgroup }</side-page-trigger>
  37. )
  38. },
  39. }),
  40. getStatusTableColumn({ statusModule: 'secgroup', vm: this, field: this.secgroupType === 'network' ? 'secgroup_status' : 'status' }),
  41. getTagTableColumn({ onManager: this.onManager, resource: 'secgroups', columns: () => this.columns }),
  42. // {
  43. // field: 'rules',
  44. // title: i18n.t('compute.text_1025'),
  45. // width: 220,
  46. // type: 'expand',
  47. // slots: {
  48. // default: ({ row }) => {
  49. // if (this.isPreLoad && !row.rules) return [<data-loading />]
  50. // const len = (row.rules && row.rules.length) || 0
  51. // return i18n.t('compute.text_619', [len])
  52. // },
  53. // content: ({ row }, h) => {
  54. // const inList = []
  55. // const outList = []
  56. // if (row.rules && row.rules.length > 0) {
  57. // row.rules.forEach(obj => {
  58. // let text = ''
  59. // if (obj.action) text += `${obj.action}`
  60. // if (obj.cidr) text += ` ${obj.cidr} (IP)`
  61. // if (obj.protocol) text += ` ${obj.protocol}`
  62. // if (obj.ports) text += ` ${obj.ports}`
  63. // if (obj.direction === 'in') {
  64. // inList.push({
  65. // value: text,
  66. // rule: obj,
  67. // })
  68. // } else if (obj.direction === 'out') {
  69. // outList.push({
  70. // value: text,
  71. // rule: obj,
  72. // })
  73. // }
  74. // })
  75. // }
  76. // const ret = []
  77. // const keys = this.list.filter
  78. // const getHightLight = (keys, item) => {
  79. // if (keys.ip) {
  80. // return <HighLight k={ keys.ip && keys.ip[0] } v={ item.value } />
  81. // } else if (keys.ports) {
  82. // return <HighLight k={ keys.ports && keys.ports[0] } v={ item.value } />
  83. // } else {
  84. // return <HighLight v={ item.value } />
  85. // }
  86. // }
  87. // if (inList.length > 0) {
  88. // ret.push(
  89. // <div class='d-flex'>
  90. // <div class='flex-grow-0 flex-shrink-0'>{this.$t('compute.text_1316')}</div>
  91. // <div>{ inList.map(item => {
  92. // return <span onClick={ () => { this.openEditRulesDialog(item.rule, row) } }>{ getHightLight(keys, item) }</span>
  93. // }) }</div>
  94. // </div>,
  95. // )
  96. // }
  97. // if (outList.length > 0) {
  98. // ret.push(
  99. // <div class='mb-2 d-flex'>
  100. // <div class='flex-grow-0 flex-shrink-0'>{this.$t('compute.text_1317')}</div>
  101. // <div>{ outList.map(item => {
  102. // return <span onClick={ () => { this.openEditRulesDialog(item.rule, row) } }>{ getHightLight(keys, item) }</span>
  103. // }) }</div>
  104. // </div>,
  105. // )
  106. // }
  107. // if (ret.length <= 0) {
  108. // ret.push(
  109. // <div>{this.$t('compute.norule')}</div>,
  110. // )
  111. // }
  112. // return ret
  113. // },
  114. // },
  115. // },
  116. getBrandTableColumn(),
  117. getAccountTableColumn(),
  118. {
  119. field: 'guest_cnt',
  120. title: i18n.t('compute.associated_instances'),
  121. width: 80,
  122. slots: {
  123. default: ({ row }, h) => {
  124. if (row.guest_cnt === undefined && row.guest_nic_cnt === undefined) return [<data-loading />]
  125. return row.total_cnt || 0
  126. },
  127. },
  128. hidden: () => this.hiddenColumns.includes('guest_cnt'),
  129. },
  130. // {
  131. // field: 'cache_cnt',
  132. // title: this.$t('compute.cache_cnt'),
  133. // slots: {
  134. // default: ({ row }, h) => {
  135. // if (row.cache_cnt === undefined) return [<data-loading />]
  136. // return row.cache_cnt
  137. // },
  138. // },
  139. // },
  140. getPublicScopeTableColumn({ vm: this, resource: 'secgroups' }),
  141. getProjectTableColumn(),
  142. getRegionTableColumn(),
  143. getCopyWithContentTableColumn({
  144. field: 'vpc',
  145. title: 'VPC',
  146. }),
  147. getTimeTableColumn(),
  148. ]
  149. },
  150. }