List.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. getNameFilter,
  14. getStatusFilter,
  15. } from '@/utils/common/tableFilter'
  16. import SingleActionsMixin from '../mixins/singleActions'
  17. import ColumnsMixin from '../mixins/columns'
  18. export default {
  19. name: 'ContainerList',
  20. mixins: [ListMixin, WindowsMixin, SingleActionsMixin, ColumnsMixin],
  21. props: {
  22. id: String,
  23. resId: String,
  24. data: {
  25. type: Object,
  26. required: true,
  27. },
  28. },
  29. data () {
  30. return {
  31. list: this.$list.createList(this, {
  32. id: this.id,
  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. groupActions: [
  44. // 启动
  45. {
  46. label: this.$t('compute.repo.start'),
  47. action: () => {
  48. const ids = this.list.selectedItems.map(item => item.id)
  49. this.list.onManager('batchPerformAction', {
  50. steadyStatus: 'running',
  51. id: ids,
  52. managerArgs: {
  53. action: 'start',
  54. },
  55. })
  56. },
  57. meta: () => {
  58. const ret = { validate: true, tooltip: null }
  59. if (this.list.selectedItems.length === 0) {
  60. ret.validate = false
  61. return ret
  62. }
  63. const isStatusOk = this.list.selectedItems.every(item => ['exited'].includes(item.status))
  64. if (!isStatusOk) {
  65. ret.validate = false
  66. return ret
  67. }
  68. return ret
  69. },
  70. },
  71. // 停止
  72. {
  73. label: this.$t('compute.repo.stop'),
  74. action: () => {
  75. this.createDialog('ContainerShutDownDialog', {
  76. data: this.list.selectedItems,
  77. columns: this.columns,
  78. onManager: this.onManager,
  79. })
  80. },
  81. meta: () => {
  82. const ret = { validate: true, tooltip: null }
  83. if (this.list.selectedItems.length === 0) {
  84. ret.validate = false
  85. return ret
  86. }
  87. const isStatusOk = this.list.selectedItems.every(item => ['running'].includes(item.status))
  88. if (!isStatusOk) {
  89. ret.validate = false
  90. return ret
  91. }
  92. return ret
  93. },
  94. },
  95. ],
  96. }
  97. },
  98. created () {
  99. this.list.fetchData()
  100. },
  101. methods: {
  102. handleOpenSidepage (row, tab) {
  103. this.sidePageTriggerHandle(this, 'VmPodContainerSidePage', {
  104. id: row.id,
  105. resource: 'containers',
  106. getParams: this.getParam,
  107. }, {
  108. list: this.list,
  109. tab,
  110. })
  111. },
  112. },
  113. }
  114. </script>