List.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="templateListColumns || columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :export-data-options="exportDataOptions"
  8. :showSearchbox="showSearchbox"
  9. :showGroupActions="showGroupActions"
  10. :show-single-actions="!isTemplate"
  11. :show-page="!isTemplate" />
  12. </template>
  13. <script>
  14. import * as R from 'ramda'
  15. import expectStatus from '@/constants/expectStatus'
  16. import { getNameFilter, getStatusFilter, getOsTypeFilter } from '@/utils/common/tableFilter'
  17. import WindowsMixin from '@/mixins/windows'
  18. import GlobalSearchMixin from '@/mixins/globalSearch'
  19. import ListMixin from '@/mixins/list'
  20. import ResTemplateListMixin from '@/mixins/resTemplateList'
  21. import SingleActionsMixin from '../mixins/singleActions'
  22. import ColumnsMixin from '../mixins/columns'
  23. export default {
  24. name: 'ImageRecoveryList',
  25. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin, ResTemplateListMixin],
  26. props: {
  27. id: String,
  28. cloudEnv: String,
  29. getParams: {
  30. type: [Function, Object],
  31. default: () => ({}),
  32. },
  33. },
  34. data () {
  35. return {
  36. list: this.$list.createList(this, {
  37. ctx: this,
  38. id: this.id,
  39. resource: 'images',
  40. getParams: this.getParam,
  41. isTemplate: this.isTemplate,
  42. templateLimit: this.templateLimit,
  43. steadyStatus: Object.values(expectStatus.image).flat(),
  44. apiVersion: 'v1',
  45. filterOptions: {
  46. name: getNameFilter(),
  47. status: getStatusFilter(),
  48. os_type: getOsTypeFilter(),
  49. },
  50. responseData: this.responseData,
  51. }),
  52. exportDataOptions: {
  53. items: [
  54. { label: 'ID', key: 'id' },
  55. { label: this.$t('compute.text_228'), key: 'name' },
  56. { label: this.$t('compute.text_398'), key: 'disk_format' },
  57. { label: this.$t('table.title.image_size'), key: 'size' },
  58. { label: this.$t('dictionary.project'), key: 'tenant' },
  59. { label: this.$t('table.title.image_type'), key: 'is_standard' },
  60. { label: this.$t('compute.text_243'), key: 'created_at' },
  61. { label: this.$t('table.title.checksum'), key: 'checksum' },
  62. ],
  63. },
  64. groupActions: [
  65. {
  66. label: this.$t('compute.text_477'),
  67. permission: 'images_delete',
  68. action: () => {
  69. this.createDialog('DeleteResDialog', {
  70. vm: this,
  71. data: this.list.selectedItems,
  72. columns: this.columns,
  73. title: this.$t('compute.text_477'),
  74. name: this.$t('dictionary.image'),
  75. requestParams: { override_pending_delete: true },
  76. onManager: this.onManager,
  77. })
  78. },
  79. meta: () => {
  80. return {
  81. validate: this.list.allowDelete(),
  82. }
  83. },
  84. },
  85. {
  86. label: this.$t('compute.text_478'),
  87. permission: 'images_perform_cancel_delete',
  88. action: () => {
  89. this.createDialog('ImageRestoreDialog', {
  90. title: this.$t('compute.text_478'),
  91. data: this.list.selectedItems,
  92. columns: this.columns,
  93. refresh: this.refresh,
  94. cloudEnv: this.cloudEnv,
  95. })
  96. },
  97. meta: () => {
  98. if (this.list.selectedItems.length > 0 && this.list.selectedItems.find(v => v.status === 'deleting') === undefined) {
  99. return {
  100. validate: true,
  101. }
  102. }
  103. return {
  104. validate: false,
  105. }
  106. },
  107. },
  108. ],
  109. }
  110. },
  111. watch: {
  112. cloudEnv (val) {
  113. this.list.manager = new this.$Manager(val, 'v1')
  114. this.list.resource = this[`${val}Fetcher`]
  115. this.list.fetchData(0)
  116. },
  117. },
  118. created () {
  119. this.sm = new this.$Manager('images', 'v1')
  120. this.vm = new this.$Manager('guestimages', 'v1')
  121. this.list.fetchData()
  122. },
  123. methods: {
  124. getParam () {
  125. const ret = {
  126. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  127. details: true,
  128. pending_delete: true,
  129. }
  130. if (this.cloudEnv === 'images') {
  131. ret.details = true
  132. ret.pending_delete = true
  133. ret.is_guest_image = false
  134. }
  135. return ret
  136. },
  137. imagesFetcher (params) {
  138. return this.sm.list({ params })
  139. },
  140. guestimagesFetcher (params) {
  141. return this.vm.list({ params })
  142. },
  143. handleOpenSidepage (row) {
  144. this.sidePageTriggerHandle(this, 'ImageRecoverySidePage', {
  145. id: row.id,
  146. resource: this.cloudEnv,
  147. getParams: this.getParams,
  148. }, {
  149. list: this.list,
  150. })
  151. },
  152. },
  153. }
  154. </script>