List.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <page-list
  3. show-tag-columns
  4. show-tag-columns2
  5. show-tag-filter
  6. :list="list"
  7. :columns="templateListColumns || columns"
  8. :group-actions="groupActions"
  9. :single-actions="singleActions"
  10. :export-data-options="exportDataOptions"
  11. :showSearchbox="showSearchbox"
  12. :showGroupActions="showGroupActions"
  13. :show-single-actions="!isTemplate"
  14. :show-page="!isTemplate" />
  15. </template>
  16. <script>
  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 {
  22. getNameFilter,
  23. getTenantFilter,
  24. getStatusFilter,
  25. getDomainFilter,
  26. getOsArchFilter,
  27. getRegionFilter,
  28. getDescriptionFilter,
  29. } from '@/utils/common/tableFilter'
  30. import SingleActionsMixin from '../mixins/singleActions'
  31. import ColumnsMixin from '../mixins/columns'
  32. import { steadyStatus } from '../constants'
  33. export default {
  34. name: 'InstanceSnapshotList',
  35. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin, ResTemplateListMixin],
  36. props: {
  37. id: String,
  38. getParams: {
  39. type: [Function, Object],
  40. },
  41. cloudEnv: String,
  42. },
  43. data () {
  44. return {
  45. list: this.$list.createList(this, {
  46. ctx: this,
  47. id: this.id,
  48. resource: 'instance_snapshots',
  49. getParams: this.getParam,
  50. isTemplate: this.isTemplate,
  51. templateLimit: this.templateLimit,
  52. steadyStatus,
  53. filterOptions: {
  54. id: {
  55. label: this.$t('table.title.id'),
  56. },
  57. name: getNameFilter(),
  58. description: getDescriptionFilter(),
  59. status: getStatusFilter('snapshot'),
  60. guest_id: {
  61. label: this.$t('res.server'),
  62. },
  63. projects: getTenantFilter(),
  64. project_domains: getDomainFilter(),
  65. region: getRegionFilter(),
  66. os_arch: getOsArchFilter(),
  67. with_memory: {
  68. label: this.$t('compute.mem_snapshot'),
  69. dropdown: true,
  70. items: [
  71. { label: this.$t('compute.contains'), key: 'true' },
  72. { label: this.$t('compute.not_contains'), key: 'false' },
  73. ],
  74. },
  75. },
  76. responseData: this.responseData,
  77. hiddenColumns: ['created_at'],
  78. }),
  79. groupActions: [
  80. {
  81. label: this.$t('table.action.set_tag'),
  82. permission: 'instance_snapshots_perform_set_user_metadata',
  83. action: () => {
  84. this.createDialog('SetTagDialog', {
  85. data: this.list.selectedItems,
  86. columns: this.columns,
  87. onManager: this.onManager,
  88. mode: 'add',
  89. params: {
  90. resources: 'instance_snapshot',
  91. },
  92. tipName: this.$t('compute.text_462'),
  93. })
  94. },
  95. meta: () => {
  96. return {
  97. validate: this.list.selected.length,
  98. tooltip: null,
  99. }
  100. },
  101. },
  102. {
  103. label: this.$t('compute.perform_delete'),
  104. permission: 'instance_snapshots_delete',
  105. action: () => {
  106. this.createDialog('DeleteResDialog', {
  107. vm: this,
  108. data: this.list.selectedItems,
  109. columns: this.columns,
  110. onManager: this.onManager,
  111. title: this.$t('compute.perform_delete'),
  112. name: this.$t('compute.text_462'),
  113. })
  114. },
  115. meta: () => {
  116. const ret = {
  117. validate: this.list.selected.length,
  118. tooltip: null,
  119. }
  120. if (this.list.selectedItems.some(item => !item.can_delete)) {
  121. ret.validate = false
  122. return ret
  123. }
  124. if (this.list.selectedItems.some(item => item.is_sub_snapshot)) {
  125. ret.validate = false
  126. ret.tooltip = this.$t('compute.text_1062')
  127. return ret
  128. }
  129. return ret
  130. },
  131. },
  132. ],
  133. }
  134. },
  135. computed: {
  136. exportDataOptions () {
  137. return {
  138. title: this.$t('compute.text_102'),
  139. downloadType: 'local',
  140. items: [
  141. { field: 'id', title: 'ID' },
  142. ...this.columns,
  143. ],
  144. }
  145. },
  146. },
  147. watch: {
  148. cloudEnv (val) {
  149. this.$nextTick(() => {
  150. this.list.fetchData(0)
  151. })
  152. },
  153. },
  154. created () {
  155. this.initSidePageTab('snapshot-detail')
  156. this.list.fetchData()
  157. },
  158. methods: {
  159. getParam () {
  160. const ret = {
  161. details: true,
  162. ...this.getParams,
  163. }
  164. if (this.cloudEnv) ret.cloud_env = this.cloudEnv
  165. return ret
  166. },
  167. handleOpenSidepage (row, tab) {
  168. this.sidePageTriggerHandle(this, 'SnapshotInstanceSidePage', {
  169. id: row.id,
  170. resource: 'instance_snapshots',
  171. getParams: this.getParam,
  172. steadyStatus: this.list.steadyStatus,
  173. }, {
  174. list: this.list,
  175. type: 'instance',
  176. tab,
  177. })
  178. },
  179. },
  180. }
  181. </script>