Container.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 ListMixin from '@/mixins/list'
  10. import WindowsMixin from '@/mixins/windows'
  11. import expectStatus from '@/constants/expectStatus'
  12. import {
  13. getCopyWithContentTableColumn,
  14. getStatusTableColumn,
  15. } from '@/utils/common/tableColumn'
  16. import {
  17. getNameFilter,
  18. getStatusFilter,
  19. } from '@/utils/common/tableFilter'
  20. export default {
  21. name: 'ContainerListForVmContainerInstanceSidepage',
  22. mixins: [ListMixin, WindowsMixin],
  23. props: {
  24. resId: String,
  25. data: {
  26. type: Object,
  27. required: true,
  28. },
  29. },
  30. data () {
  31. return {
  32. list: this.$list.createList(this, {
  33. resource: 'containers',
  34. getParams: {
  35. guest_id: this.resId,
  36. },
  37. steadyStatus: Object.values(expectStatus.container).flat(),
  38. filterOptions: {
  39. name: getNameFilter(),
  40. status: getStatusFilter('container'),
  41. },
  42. }),
  43. columns: [
  44. getCopyWithContentTableColumn({
  45. field: 'name',
  46. title: this.$t('common.name'),
  47. hideField: true,
  48. message: (row) => {
  49. return row.name
  50. },
  51. slotCallback: (row) => {
  52. return row.name
  53. },
  54. }),
  55. getStatusTableColumn({ statusModule: 'container' }),
  56. {
  57. field: 'image',
  58. title: this.$t('compute.pod-image'),
  59. width: 350,
  60. formatter: ({ row }) => {
  61. return row.spec?.image || '-'
  62. },
  63. },
  64. {
  65. field: 'env',
  66. title: this.$t('compute.repo.env_variables'),
  67. minWidth: 200,
  68. slots: {
  69. default: ({ row }, h) => {
  70. if (!row.spec.envs || !row.spec.envs.length) return '-'
  71. return row.spec.envs.map(v => {
  72. return (
  73. <a-tooltip title={`${v.key}: ${v.value}`}>
  74. <a-tag class="d-block text-truncate mb-1" style="max-width: 400px;">{v.key}: {v.value}</a-tag>
  75. </a-tooltip>
  76. )
  77. })
  78. },
  79. },
  80. },
  81. {
  82. field: 'command',
  83. title: this.$t('compute.repo.command'),
  84. minWidth: 200,
  85. slots: {
  86. default: ({ row }, h) => {
  87. const command = row.spec?.command || []
  88. return command.join(' ') || '-'
  89. },
  90. },
  91. },
  92. {
  93. field: 'args',
  94. title: this.$t('compute.repo.command.params'),
  95. minWidth: 200,
  96. slots: {
  97. default: ({ row }, h) => {
  98. const args = row.spec?.args
  99. return args?.length ? `[${args}]` : '-'
  100. },
  101. },
  102. },
  103. ],
  104. groupActions: [
  105. // 启动
  106. {
  107. label: this.$t('compute.repo.start'),
  108. action: () => {
  109. const ids = this.list.selectedItems.map(item => item.id)
  110. this.list.onManager('batchPerformAction', {
  111. steadyStatus: 'running',
  112. id: ids,
  113. managerArgs: {
  114. action: 'start',
  115. },
  116. })
  117. },
  118. meta: () => {
  119. const ret = { validate: true, tooltip: null }
  120. if (this.list.selectedItems.length === 0) {
  121. ret.validate = false
  122. return ret
  123. }
  124. const isStatusOk = this.list.selectedItems.every(item => ['exited'].includes(item.status))
  125. if (!isStatusOk) {
  126. ret.validate = false
  127. return ret
  128. }
  129. return ret
  130. },
  131. },
  132. // 停止
  133. {
  134. label: this.$t('compute.repo.stop'),
  135. action: () => {
  136. this.createDialog('ContainerShutDownDialog', {
  137. data: this.list.selectedItems,
  138. columns: this.columns,
  139. onManager: this.onManager,
  140. })
  141. },
  142. meta: () => {
  143. const ret = { validate: true, tooltip: null }
  144. if (this.list.selectedItems.length === 0) {
  145. ret.validate = false
  146. return ret
  147. }
  148. const isStatusOk = this.list.selectedItems.every(item => ['running'].includes(item.status))
  149. if (!isStatusOk) {
  150. ret.validate = false
  151. return ret
  152. }
  153. return ret
  154. },
  155. },
  156. ],
  157. }
  158. },
  159. created () {
  160. this.list.fetchData()
  161. },
  162. methods: {},
  163. }
  164. </script>