VmContainer.vue 4.6 KB

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