List.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 { mapGetters } from 'vuex'
  11. import { NOTIFY_TOPIC_TYPES_MAP } from '@IAM/constants'
  12. import ColumnsMixin from '../mixins/columns'
  13. import SingleActionsMixin from '../mixins/singleActions'
  14. import WindowsMixin from '@/mixins/windows'
  15. import ListMixin from '@/mixins/list'
  16. import { getEnabledFilter } from '@/utils/common/tableFilter'
  17. export default {
  18. name: 'NotifyTopicList',
  19. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  20. props: {
  21. id: String,
  22. getParams: {
  23. type: Object,
  24. default: () => {},
  25. },
  26. },
  27. data () {
  28. return {
  29. list: this.$list.createList(this, {
  30. id: this.id,
  31. resource: 'topics',
  32. apiVersion: 'v1',
  33. getParams: this.getParam,
  34. filterOptions: {
  35. type: {
  36. label: this.$t('system.text_48'),
  37. filter: true,
  38. dropdown: true,
  39. distinctField: {
  40. type: 'field',
  41. key: 'type',
  42. getParams: this.getParam,
  43. },
  44. formatter: val => {
  45. return `type.contains("${val}")`
  46. },
  47. mapper: list => {
  48. return list.map(({ key, label }) => {
  49. return {
  50. key,
  51. label: NOTIFY_TOPIC_TYPES_MAP[key] ? NOTIFY_TOPIC_TYPES_MAP[key].label : label,
  52. }
  53. })
  54. },
  55. },
  56. enabled: getEnabledFilter(),
  57. },
  58. }),
  59. exportDataOptions: {
  60. items: [
  61. { label: 'ID', key: 'id' },
  62. { label: this.$t('system.notify.topic.name'), key: 'name' },
  63. { label: this.$t('system.notify.topic.type'), key: 'type' },
  64. { label: this.$t('system.text_163'), key: 'enabled' },
  65. ],
  66. },
  67. groupActions: [
  68. {
  69. label: this.$t('system.text_225'),
  70. permission: 'topics_perform_enable',
  71. action: () => {
  72. this.createDialog('DisableDialog', {
  73. title: this.$t('system.text_225'),
  74. name: this.$t('dictionary.notify-topic'),
  75. columns: this.columns,
  76. data: this.list.selectedItems,
  77. ok: async () => {
  78. try {
  79. const response = await this.list.batchPerformAction('enable', null)
  80. return response
  81. } catch (error) {
  82. throw error
  83. }
  84. },
  85. })
  86. },
  87. meta: () => {
  88. let validate = true
  89. if (this.list.selectedItems.length <= 0) {
  90. validate = false
  91. }
  92. if (this.list.selectedItems.some(item => item.enabled === true)) {
  93. validate = false
  94. }
  95. if (!this.isAdminMode) {
  96. validate = false
  97. }
  98. return {
  99. validate,
  100. }
  101. },
  102. },
  103. {
  104. label: this.$t('system.text_226'),
  105. permission: 'topics_perform_disable',
  106. action: () => {
  107. this.createDialog('DisableDialog', {
  108. title: this.$t('system.text_226'),
  109. name: this.$t('dictionary.notify-topic'),
  110. columns: this.columns,
  111. data: this.list.selectedItems,
  112. ok: async () => {
  113. try {
  114. const response = await this.list.batchPerformAction('disable', null)
  115. return response
  116. } catch (error) {
  117. throw error
  118. }
  119. },
  120. })
  121. },
  122. meta: () => {
  123. let validate = true
  124. if (this.list.selectedItems.length <= 0) {
  125. validate = false
  126. }
  127. if (this.list.selectedItems.some(item => item.enabled === false)) {
  128. validate = false
  129. }
  130. if (!this.isAdminMode) {
  131. validate = false
  132. }
  133. return {
  134. validate,
  135. }
  136. },
  137. },
  138. ],
  139. }
  140. },
  141. computed: {
  142. ...mapGetters(['isAdminMode']),
  143. },
  144. created () {
  145. this.list.fetchData()
  146. },
  147. methods: {
  148. getParam () {
  149. return {
  150. ...this.getParams,
  151. details: true,
  152. }
  153. },
  154. handleOpenSidepage (row) {
  155. this.sidePageTriggerHandle(this, 'NotifyTopicSidePage', {
  156. id: row.id,
  157. resource: 'topics',
  158. apiVersion: 'v1',
  159. getParams: this.getParam,
  160. }, {
  161. list: this.list,
  162. })
  163. },
  164. },
  165. }
  166. </script>
  167. <style scoped>
  168. </style>