VMInstanceListForInstanceGroup.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :single-actions="singleActions"
  6. :group-actions="groupActions" />
  7. </template>
  8. <script>
  9. import { sizestr } from '@/utils/utils'
  10. import { getStatusTableColumn, getCopyWithContentTableColumn, getNameDescriptionTableColumn, getIpsTableColumn, getTimeTableColumn } from '@/utils/common/tableColumn'
  11. import SystemIcon from '@/sections/SystemIcon'
  12. import expectStatus from '@/constants/expectStatus'
  13. import WindowsMixin from '@/mixins/windows'
  14. import ListMixin from '@/mixins/list'
  15. export default {
  16. name: 'VMInstanceListForInstanceGroup',
  17. mixins: [WindowsMixin, ListMixin],
  18. props: {
  19. resId: {
  20. type: String,
  21. required: true,
  22. },
  23. },
  24. data () {
  25. return {
  26. list: this.$list.createList(this, {
  27. id: 'VminstanceListForInstanceGroupSidepage',
  28. resource: 'servers',
  29. getParams: this.getParams,
  30. steadyStatus: Object.values(expectStatus.server).flat(),
  31. filterOptions: {
  32. name: {
  33. label: this.$t('compute.text_719'),
  34. filter: true,
  35. formatter: val => {
  36. return `name.contains("${val}")`
  37. },
  38. },
  39. status: {
  40. label: this.$t('compute.text_353'),
  41. dropdown: true,
  42. multiple: true,
  43. items: [
  44. { label: this.$t('compute.text_574'), key: 'running' },
  45. { label: this.$t('compute.text_273'), key: 'ready' },
  46. { label: this.$t('compute.text_339'), key: 'unknown' },
  47. { label: this.$t('compute.text_720'), key: 'sched_fail' },
  48. ],
  49. filter: true,
  50. formatter: val => {
  51. return `status.in(${val.join(',')})`
  52. },
  53. },
  54. os_type: {
  55. label: this.$t('compute.text_721'),
  56. dropdown: true,
  57. multiple: true,
  58. items: [
  59. { label: 'Windows', key: 'windows' },
  60. { label: 'Linux', key: 'linux' },
  61. { label: 'VMware', key: 'VMWare' },
  62. ],
  63. filter: true,
  64. formatter: val => {
  65. return `os_type.contains("${val}")`
  66. },
  67. },
  68. },
  69. }),
  70. columns: [
  71. getNameDescriptionTableColumn({ addLock: true, vm: this }),
  72. {
  73. field: 'os_type',
  74. title: this.$t('table.title.os'),
  75. width: 50,
  76. slots: {
  77. default: ({ row }) => {
  78. let name = ((row.metadata && row.metadata.os_distribution) ? row.metadata.os_distribution : row.os_type) || ''
  79. if (name.includes('Windows') || name.includes('windows')) {
  80. name = 'Windows'
  81. }
  82. const version = (row.metadata && row.metadata.os_version) ? `${row.metadata.os_version}` : ''
  83. const tooltip = version.includes(name) ? version : `${name} ${version}` // 去重
  84. return [
  85. <SystemIcon tooltip={ tooltip } name={ name } />,
  86. ]
  87. },
  88. },
  89. },
  90. getStatusTableColumn({ statusModule: 'server' }),
  91. {
  92. field: 'instance_type',
  93. title: this.$t('compute.text_295'),
  94. showOverflow: 'ellipsis',
  95. minWidth: 120,
  96. slots: {
  97. default: ({ row }) => {
  98. const ret = []
  99. if (row.instance_type) {
  100. ret.push(<div style={{ color: '#0A1F44' }}>{ row.instance_type }</div>)
  101. }
  102. const config = row.vcpu_count + 'C' + sizestr(row.vmem_size, 'M', 1024) + (row.disk ? sizestr(row.disk, 'M', 1024) : '')
  103. return ret.concat(<div style={{ color: '#53627C' }}>{ config }</div>)
  104. },
  105. },
  106. },
  107. getIpsTableColumn({ field: 'ip', title: 'IP', vm: this }),
  108. getTimeTableColumn({
  109. field: 'attach_time',
  110. title: this.$t('compute.text_722'),
  111. }),
  112. getCopyWithContentTableColumn({ field: 'host', title: this.$t('compute.text_111') }),
  113. ],
  114. groupActions: [
  115. {
  116. label: this.$t('compute.text_723'),
  117. action: () => {
  118. this.createDialog('InstanceGroupUnbindServerDialog', {
  119. instanceGroupId: this.resId,
  120. columns: this.columns,
  121. data: this.list.selectedItems,
  122. onManager: this.onManager,
  123. refresh: this.refresh,
  124. })
  125. },
  126. meta: () => {
  127. return {
  128. validate: this.list.selectedItems.length > 0,
  129. }
  130. },
  131. },
  132. ],
  133. singleActions: [
  134. {
  135. label: this.$t('compute.text_723'),
  136. action: obj => {
  137. this.createDialog('InstanceGroupUnbindServerDialog', {
  138. instanceGroupId: this.resId,
  139. columns: this.columns,
  140. data: [obj],
  141. onManager: this.onManager,
  142. refresh: this.refresh,
  143. })
  144. },
  145. },
  146. ],
  147. }
  148. },
  149. created () {
  150. this.list.fetchData()
  151. this.$bus.$on('VMInstanceListForInstanceGroupRefreshList', () => {
  152. this.list.refresh()
  153. }, this)
  154. },
  155. methods: {
  156. getParams () {
  157. return {
  158. details: true,
  159. with_meta: true,
  160. filter: 'hypervisor.notin(baremetal,container,pod)',
  161. group: this.resId,
  162. }
  163. },
  164. },
  165. }
  166. </script>