List.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="templateListColumns || columns"
  5. :group-actions="groupActions"
  6. :showSingleActions="isTemplate ? false : showActions"
  7. :showGroupActions="showActions && showGroupActions"
  8. :export-data-options="exportDataOptions"
  9. :showSearchbox="showSearchbox"
  10. :show-page="!isTemplate" />
  11. </template>
  12. <script>
  13. import { mapGetters } from 'vuex'
  14. import {
  15. getNameFilter,
  16. getDomainFilter,
  17. getTenantFilter,
  18. } from '@/utils/common/tableFilter'
  19. import WindowsMixin from '@/mixins/windows'
  20. import GlobalSearchMixin from '@/mixins/globalSearch'
  21. import ListMixin from '@/mixins/list'
  22. import ResTemplateListMixin from '@/mixins/resTemplateList'
  23. import ColumnsMixin from '../mixins/columns'
  24. export default {
  25. name: 'DeadlyResourceList',
  26. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, ResTemplateListMixin],
  27. props: {
  28. id: String,
  29. getParams: {
  30. type: [Function, Object],
  31. },
  32. hiddenColumns: {
  33. type: Array,
  34. default: () => ([]),
  35. },
  36. hiddenFilterOptions: {
  37. type: Array,
  38. default: () => ([]),
  39. },
  40. },
  41. data () {
  42. const filterOptions = {
  43. id: {
  44. label: this.$t('table.title.id'),
  45. },
  46. name: getNameFilter(),
  47. projects: getTenantFilter(),
  48. project_domains: getDomainFilter(),
  49. }
  50. for (let i = 0, len = this.hiddenFilterOptions.length; i < len; i++) {
  51. delete filterOptions[this.hiddenFilterOptions[i]]
  52. }
  53. return {
  54. list: this.$list.createList(this, {
  55. ctx: this,
  56. id: this.id,
  57. resource: 'billing_resource_checks',
  58. apiVersion: 'v1',
  59. getParams: this.getParam,
  60. filterOptions,
  61. hiddenColumns: this.hiddenColumns,
  62. isTemplate: this.isTemplate,
  63. templateLimit: this.templateLimit,
  64. }),
  65. groupActions: [
  66. {
  67. label: this.$t('compute.check_deadly_resource'),
  68. permission: 'billing_resource_checks_perform_check',
  69. action: async () => {
  70. await new this.$Manager('billing_resource_checks/check', 'v1').create()
  71. this.list.fetchData()
  72. this.$message.success(this.$t('common_360'))
  73. },
  74. meta: () => {
  75. return {
  76. buttonType: 'primary',
  77. validate: true,
  78. }
  79. },
  80. },
  81. ],
  82. }
  83. },
  84. computed: {
  85. ...mapGetters(['isProjectMode']),
  86. showActions () {
  87. return true
  88. },
  89. exportDataOptions () {
  90. return {
  91. downloadType: 'local',
  92. title: this.$t('compute.deadly_resource'),
  93. items: [
  94. { label: 'ID', key: 'id' },
  95. ...this.columns,
  96. ],
  97. }
  98. },
  99. },
  100. created () {
  101. this.initSidePageTab('deadly-resource-detail')
  102. this.list.fetchData()
  103. },
  104. methods: {
  105. getParam () {
  106. const ret = { ...(typeof this.getParams === 'function' ? this.getParams() : this.getParams) }
  107. if (this.isTemplate) {
  108. ret.order_by = 'release_at'
  109. ret.order = 'asc'
  110. }
  111. return ret
  112. },
  113. handleOpenSidepage (row, tab) {
  114. // 根据资源类型打开对应的 sidepage
  115. const resourceTypeMap = {
  116. server: {
  117. sidePageName: 'VmInstanceSidePage',
  118. resource: 'servers',
  119. initTab: 'vm-instance-detail',
  120. },
  121. dbinstance: {
  122. sidePageName: 'RDSSidePage',
  123. resource: 'dbinstances',
  124. initTab: 'detail',
  125. },
  126. elasticcache: {
  127. sidePageName: 'RedisSidePage',
  128. resource: 'elasticcaches',
  129. initTab: 'redis-detail',
  130. },
  131. }
  132. const resourceInfo = resourceTypeMap[row.resource_type]
  133. if (resourceInfo && row.id) {
  134. // 打开对应资源的 sidepage
  135. this.initSidePageTab(resourceInfo.initTab)
  136. this.sidePageTriggerHandle(this, resourceInfo.sidePageName, {
  137. id: row.id,
  138. resource: resourceInfo.resource,
  139. getParams: this.getParam,
  140. }, {
  141. list: this.list,
  142. hiddenColumns: this.hiddenColumns,
  143. tab,
  144. })
  145. } else {
  146. // 如果没有匹配的资源类型或没有 resource_id,打开默认的 deadly-resource sidepage
  147. this.initSidePageTab('deadly-resource-detail')
  148. this.sidePageTriggerHandle(this, 'DeadlyResourceSidePage', {
  149. id: row.id,
  150. resource: 'billing_resource_checks',
  151. getParams: this.getParam,
  152. }, {
  153. list: this.list,
  154. hiddenColumns: this.hiddenColumns,
  155. tab,
  156. })
  157. }
  158. },
  159. },
  160. }
  161. </script>