List.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :export-data-options="exportDataOptions" />
  8. </template>
  9. <script>
  10. import * as R from 'ramda'
  11. import ColumnsMixin from '../mixins/columns'
  12. import SingleActionsMixin from '../mixins/singleActions'
  13. import WindowsMixin from '@/mixins/windows'
  14. import ListMixin from '@/mixins/list'
  15. import { getNameFilter, getTenantFilter, getStatusFilter, getEnabledFilter, getDescriptionFilter } from '@/utils/common/tableFilter'
  16. import expectStatus from '@/constants/expectStatus'
  17. import { getEnabledSwitchActions } from '@/utils/common/tableActions'
  18. import { levelMaps } from '@Monitor/constants'
  19. export default {
  20. name: 'CommonalertList',
  21. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  22. props: {
  23. listId: String,
  24. getParams: {
  25. type: Object,
  26. default: () => ({
  27. details: true,
  28. }),
  29. },
  30. alertType: {
  31. type: String,
  32. default: 'all',
  33. },
  34. },
  35. data () {
  36. return {
  37. list: this.$list.createList(this, {
  38. id: this.listId,
  39. resource: 'commonalerts',
  40. apiVersion: 'v1',
  41. getParams: this.getParam,
  42. steadyStatus: Object.values(expectStatus.commonalert).flat(),
  43. filterOptions: {
  44. name: getNameFilter(),
  45. description: getDescriptionFilter(),
  46. status: getStatusFilter('commonalert'),
  47. enabled: getEnabledFilter(),
  48. tenant: getTenantFilter(),
  49. res_type: {
  50. label: this.$t('monitor.text_97'),
  51. dropdown: true,
  52. distinctField: {
  53. type: 'extra_field',
  54. key: 'res_type',
  55. },
  56. mapper: data => {
  57. return data.map(val => {
  58. let label = val.label
  59. if (this.$te(`dictionary.${val.key}`)) label = this.$t(`dictionary.${val.key}`)
  60. return {
  61. key: val.key,
  62. label,
  63. }
  64. })
  65. },
  66. },
  67. level: {
  68. label: this.$t('monitor.level'),
  69. dropdown: true,
  70. items: Object.values(levelMaps),
  71. },
  72. },
  73. hiddenColumns: ['created_at'],
  74. }),
  75. groupActions: [
  76. {
  77. label: this.$t('common.create'),
  78. permission: 'commonalerts_create',
  79. action: () => {
  80. this.$router.push({
  81. path: '/commonalerts/create',
  82. })
  83. },
  84. meta: () => ({
  85. buttonType: 'primary',
  86. }),
  87. },
  88. {
  89. label: this.$t('common.batchAction'),
  90. actions: obj => {
  91. return [
  92. ...getEnabledSwitchActions(this, obj, ['commonalerts_perform_enable', 'commonalerts_perform_disable']),
  93. {
  94. label: this.$t('common.delete'),
  95. permission: 'commonalerts_delete',
  96. action: () => {
  97. const data = this.list.selectedItems
  98. this.createDialog('DeleteResDialog', {
  99. vm: this,
  100. data,
  101. columns: this.columns,
  102. title: this.$t('common.delete'),
  103. name: this.$t('dictionary.commonalert'),
  104. onManager: this.onManager,
  105. })
  106. },
  107. meta: () => this.$getDeleteResult(this.list.selectedItems),
  108. },
  109. ]
  110. },
  111. },
  112. ],
  113. exportDataOptions: {
  114. items: [
  115. { key: 'name', label: this.$t('common.name') },
  116. { key: 'status', label: this.$t('common.status') },
  117. { key: 'enabled', label: this.$t('table.title.enable_status') },
  118. { key: 'common_alert_metric_details', label: this.$t('monitor.strategy_detail') },
  119. { key: 'level', label: this.$t('monitor.level') },
  120. { key: 'tenant', label: this.$t('monitor.text00015') },
  121. { label: this.$t('common.createdAt'), key: 'created_at' },
  122. ],
  123. },
  124. }
  125. },
  126. watch: {
  127. alertType (val) {
  128. this.$nextTick(() => {
  129. this.list.fetchData(0)
  130. })
  131. },
  132. },
  133. created () {
  134. this.initSidePageTab('commonalert-detail')
  135. this.fetchData()
  136. },
  137. methods: {
  138. getParam () {
  139. const ret = {
  140. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  141. }
  142. if (this.alertType && this.alertType !== 'all') ret.alert_type = this.alertType
  143. return ret
  144. },
  145. fetchData () {
  146. this.list.fetchData()
  147. },
  148. handleOpenSidepage (row) {
  149. this.sidePageTriggerHandle(this, 'CommonalertsSidePage', {
  150. id: row.id,
  151. resource: 'commonalerts',
  152. getParams: this.getParam,
  153. apiVersion: 'v1',
  154. }, {
  155. list: this.list,
  156. })
  157. },
  158. },
  159. }
  160. </script>