List.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 ColumnsMixin from '../mixins/columns'
  11. import SingleActionsMixin from '../mixins/singleActions'
  12. import { NOTIFY_SUBSCRIBER_TYPES_MAP } from '../../../constants'
  13. import WindowsMixin from '@/mixins/windows'
  14. import ListMixin from '@/mixins/list'
  15. import { getEnabledFilter } from '@/utils/common/tableFilter'
  16. import { getEnabledSwitchActions } from '@/utils/common/tableActions'
  17. export default {
  18. name: 'NotifySubscriberList',
  19. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  20. props: {
  21. id: {
  22. type: String,
  23. },
  24. resId: {
  25. type: String,
  26. },
  27. getParams: {
  28. type: Object,
  29. },
  30. },
  31. data () {
  32. return {
  33. list: this.$list.createList(this, {
  34. id: this.id,
  35. resource: 'subscribers',
  36. apiVersion: 'v1',
  37. getParams: this.getParam,
  38. filterOptions: {
  39. resource_scope: {
  40. label: this.$t('system.notify.topic.receiver.resource_scope'),
  41. dropdown: true,
  42. distinctField: {
  43. type: 'extra_field',
  44. key: 'resource_scope',
  45. },
  46. },
  47. enabled: getEnabledFilter(),
  48. type: {
  49. label: this.$t('system.text_48'),
  50. filter: true,
  51. dropdown: true,
  52. distinctField: {
  53. type: 'field',
  54. key: 'type',
  55. getParams: this.getParam,
  56. },
  57. formatter: val => {
  58. return `type.contains("${val}")`
  59. },
  60. mapper: list => {
  61. return list.map(({ key, label }) => {
  62. return {
  63. key,
  64. label: NOTIFY_SUBSCRIBER_TYPES_MAP[key] ? NOTIFY_SUBSCRIBER_TYPES_MAP[key].label : label,
  65. }
  66. })
  67. },
  68. },
  69. },
  70. }),
  71. groupActions: [
  72. // 新建
  73. {
  74. label: this.$t('system.text_128'),
  75. permission: 'subscribers_create',
  76. action: () => {
  77. this.createDialog('SetupNotifyReceiverDialog', {
  78. resId: this.resId,
  79. columns: this.columns,
  80. success: (res) => {
  81. this.list.fetchData()
  82. },
  83. })
  84. },
  85. meta: () => {
  86. return {
  87. buttonType: 'primary',
  88. }
  89. },
  90. },
  91. {
  92. label: this.$t('common.batchAction'),
  93. actions: obj => {
  94. return [
  95. // 启用禁用
  96. ...getEnabledSwitchActions(this, undefined, undefined, {
  97. resourceName: this.$t('system.notify.subscriber.receivers'),
  98. fields: ['resource_scope', 'enabled', 'type', 'receivers'],
  99. actions: [
  100. async (obj) => {
  101. const ids = this.list.selectedItems.map(item => item.id)
  102. await this.onManager('batchPerformAction', {
  103. id: ids,
  104. managerArgs: {
  105. action: 'enable',
  106. },
  107. })
  108. },
  109. async (obj) => {
  110. const ids = this.list.selectedItems.map(item => item.id)
  111. await this.onManager('batchPerformAction', {
  112. id: ids,
  113. managerArgs: {
  114. action: 'disable',
  115. },
  116. })
  117. },
  118. ],
  119. }),
  120. // 删除
  121. {
  122. label: this.$t('system.text_129'),
  123. permission: 'subscribers_delete',
  124. fields: ['resource_scope', 'enabled', 'type', 'receivers'],
  125. action: () => {
  126. this.createDialog('DeleteResDialog', {
  127. vm: this,
  128. data: this.list.selectedItems,
  129. columns: this.columns,
  130. fields: ['resource_scope', 'enabled', 'type', 'receivers'],
  131. title: this.$t('common.delete'),
  132. name: this.$t('system.notify.subscriber.receivers'),
  133. onManager: this.onManager,
  134. })
  135. },
  136. meta: () => this.$getDeleteResult(this.list.selectedItems),
  137. },
  138. ]
  139. },
  140. meta: () => {
  141. let validate = true
  142. if (this.list.selectedItems.length <= 0) {
  143. validate = false
  144. }
  145. return { validate }
  146. },
  147. },
  148. ],
  149. }
  150. },
  151. computed: {
  152. exportDataOptions () {
  153. return {
  154. title: this.$t('system.notify.topic.receiver.management'),
  155. downloadType: 'local',
  156. items: this.columns,
  157. }
  158. },
  159. },
  160. created () {
  161. this.list.fetchData()
  162. },
  163. methods: {
  164. getParam () {
  165. const ret = {
  166. ...this.getParams,
  167. topic_id: this.resId,
  168. details: true,
  169. }
  170. return ret
  171. },
  172. },
  173. }
  174. </script>
  175. <style scoped>
  176. </style>