List.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 { getNameFilter, getTenantFilter, getStatusFilter, getDomainFilter, getDescriptionFilter } from '@/utils/common/tableFilter'
  15. import expectStatus from '@/constants/expectStatus'
  16. import WindowsMixin from '@/mixins/windows'
  17. import ListMixin from '@/mixins/list'
  18. import ResTemplateListMixin from '@/mixins/resTemplateList'
  19. import GlobalSearchMixin from '@/mixins/globalSearch'
  20. import SingleActionsMixin from '../mixins/singleActions'
  21. import ColumnsMixin from '../mixins/columns'
  22. export default {
  23. name: 'SnapshotPolicyList',
  24. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin, ResTemplateListMixin],
  25. props: {
  26. id: String,
  27. getParams: {
  28. type: Object,
  29. default: () => ({}),
  30. },
  31. cloudEnv: String,
  32. cloudEnvOptions: {
  33. type: Array,
  34. },
  35. },
  36. data () {
  37. return {
  38. list: this.$list.createList(this, {
  39. ctx: this,
  40. id: this.id,
  41. resource: 'snapshotpolicies',
  42. steadyStatus: Object.values(expectStatus.snapshotpolicy).flat(),
  43. getParams: this.getParam,
  44. isTemplate: this.isTemplate,
  45. templateLimit: this.templateLimit,
  46. filterOptions: {
  47. id: {
  48. label: this.$t('table.title.id'),
  49. },
  50. name: getNameFilter(),
  51. description: getDescriptionFilter(),
  52. status: getStatusFilter('snapshotpolicy'),
  53. type: {
  54. label: this.$t('common.resource_type'),
  55. dropdown: true,
  56. items: [
  57. { label: this.$t('dictionary.disk'), key: 'disk' },
  58. { label: this.$t('dictionary.server'), key: 'server' },
  59. ],
  60. },
  61. projects: getTenantFilter(),
  62. project_domains: getDomainFilter(),
  63. },
  64. hiddenColumns: ['created_at'],
  65. responseData: this.responseData,
  66. }),
  67. groupActions: [
  68. {
  69. label: this.$t('compute.perform_create'),
  70. permission: 'snapshotpolicy_create',
  71. action: () => {
  72. this.createDialog('CreateSnapshotPolicyDialog', {
  73. data: this.list.selectedItems,
  74. columns: this.columns,
  75. title: this.$t('compute.perform_create'),
  76. refresh: this.refresh,
  77. })
  78. },
  79. meta: () => {
  80. return {
  81. buttonType: 'primary',
  82. }
  83. },
  84. },
  85. {
  86. label: this.$t('compute.perform_delete'),
  87. permission: 'snapshotpolicy_delete',
  88. action: () => {
  89. this.createDialog('DeleteResDialog', {
  90. vm: this,
  91. data: this.list.selectedItems,
  92. columns: this.columns,
  93. title: this.$t('compute.perform_delete'),
  94. name: this.$t('dictionary.snapshotpolicy'),
  95. onManager: this.onManager,
  96. })
  97. },
  98. meta: () => this.$getDeleteResult(this.list.selectedItems),
  99. },
  100. ],
  101. }
  102. },
  103. computed: {
  104. exportDataOptions () {
  105. return {
  106. downloadType: 'local',
  107. title: this.$t('compute.text_103'),
  108. items: [
  109. { label: 'ID', key: 'id' },
  110. ...this.columns,
  111. ],
  112. }
  113. },
  114. },
  115. watch: {
  116. cloudEnv (val) {
  117. this.$nextTick(() => {
  118. this.list.fetchData(0)
  119. })
  120. },
  121. },
  122. created () {
  123. this.initSidePageTab('snapshot-policy-detail')
  124. this.list.fetchData()
  125. this.$bus.$on('refresh-snapshotpolicy-list', () => {
  126. this.list.fetchData()
  127. })
  128. },
  129. methods: {
  130. getParam () {
  131. const ret = {
  132. details: true,
  133. ...this.getParams,
  134. }
  135. if (this.cloudEnv) ret.cloud_env = this.cloudEnv
  136. if (this.isTemplate) {
  137. ret.order_by_snapshot_count = 'desc'
  138. }
  139. return ret
  140. },
  141. handleOpenSidepage (row, tab) {
  142. this.sidePageTriggerHandle(this, 'SnapshotPolicySidePage', {
  143. id: row.id,
  144. resource: 'snapshotpolicies',
  145. getParams: this.getParam,
  146. steadyStatus: Object.values(expectStatus.snapshotpolicy).flat(),
  147. }, {
  148. list: this.list,
  149. type: this.type,
  150. tab,
  151. })
  152. },
  153. },
  154. }
  155. </script>