List.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div>
  3. <a-alert :message="alertMessage" class="mb-2" type="info" />
  4. <page-list
  5. :list="list"
  6. :columns="columns"
  7. :group-actions="groupActions"
  8. :single-actions="singleActions" />
  9. </div>
  10. </template>
  11. <script>
  12. import { getNameFilter, getEnabledFilter, getStatusFilter, getDescriptionFilter, getCreatedAtFilter } from '@/utils/common/tableFilter'
  13. import WindowsMixin from '@/mixins/windows'
  14. import ListMixin from '@/mixins/list'
  15. import { getEnabledSwitchActions, getSetPublicAction } from '@/utils/common/tableActions'
  16. import SingleActionsMixin from '../mixins/singleActions'
  17. import ColumnsMixin from '../mixins/columns'
  18. export default {
  19. name: 'ProjectMappingList',
  20. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  21. props: {
  22. id: String,
  23. },
  24. data () {
  25. return {
  26. alertMessage: this.$t('cloudenv.text_581'),
  27. list: this.$list.createList(this, {
  28. id: this.id,
  29. resource: 'project_mappings',
  30. getParams: { details: true },
  31. filterOptions: {
  32. name: getNameFilter(),
  33. description: getDescriptionFilter(),
  34. enabled: getEnabledFilter(),
  35. status: getStatusFilter({ statusModule: 'projectMapping' }),
  36. created_at: getCreatedAtFilter(),
  37. },
  38. hiddenColumns: ['created_at'],
  39. }),
  40. exportDataOptions: {
  41. items: [
  42. { label: 'ID', key: 'id' },
  43. { label: this.$t('cloudenv.text_95'), key: 'name' },
  44. { label: this.$t('common.createdAt'), key: 'created_at' },
  45. ],
  46. },
  47. groupActions: [
  48. {
  49. label: this.$t('cloudenv.text_104'),
  50. permission: 'projectmappings_create',
  51. action: () => {
  52. this.createDialog('ProjectMappingCreateDialog', {
  53. success: () => {
  54. this.list.fetchData()
  55. },
  56. })
  57. },
  58. meta: () => {
  59. return {
  60. buttonType: 'primary',
  61. }
  62. },
  63. },
  64. {
  65. label: this.$t('common.batchAction'),
  66. actions: () => {
  67. return [
  68. ...getEnabledSwitchActions(this, undefined, ['projectmappings_perform_enable', 'projectmappings_perform_disable'], {
  69. resourceName: this.$t('cloudenv.text_580'),
  70. metas: [
  71. () => {
  72. const isEnable = !!this.list.selectedItems.find(item => item.enabled)
  73. return {
  74. validate: this.list.selectedItems.length && !isEnable,
  75. }
  76. },
  77. () => {
  78. const isDisable = !!this.list.selectedItems.find(item => !item.enabled)
  79. return {
  80. validate: this.list.selectedItems.length && !isDisable,
  81. }
  82. },
  83. ],
  84. }),
  85. getSetPublicAction(this, {
  86. name: this.$t('cloudenv.text_580'),
  87. scope: 'domain',
  88. resource: 'project_mappings',
  89. }, {
  90. permission: 'project_mappings_perform_public',
  91. }),
  92. {
  93. label: this.$t('cloudenv.text_108'),
  94. permission: 'projectmappings_delete',
  95. action: () => {
  96. this.createDialog('DeleteResDialog', {
  97. vm: this,
  98. data: this.list.selectedItems,
  99. columns: this.columns,
  100. title: this.$t('resourceowner_delete'),
  101. name: this.$t('cloudenv.text_580'),
  102. onManager: this.onManager,
  103. })
  104. },
  105. meta: () => {
  106. const deleteResult = this.$getDeleteResult(this.list.selectedItems)
  107. if (!deleteResult.validate) {
  108. return deleteResult
  109. }
  110. return {
  111. validate: true,
  112. }
  113. },
  114. },
  115. ]
  116. },
  117. meta: () => {
  118. const ownerDomain = this.$store.getters.isAdminMode || this.list.selectedItems.every(obj => obj.domain_id === this.$store.getters.userInfo.projectDomainId)
  119. if (!ownerDomain) {
  120. return {
  121. validate: false,
  122. tooltip: this.$t('cloudenv.text_597'),
  123. }
  124. }
  125. return {
  126. validate: this.list.selectedItems && this.list.selectedItems.length > 0,
  127. }
  128. },
  129. },
  130. ],
  131. }
  132. },
  133. created () {
  134. this.list.fetchData()
  135. this.$bus.$on('ProjectMappingRuleUpdate', (res) => {
  136. this.list.fetchData()
  137. })
  138. },
  139. methods: {
  140. refresh () {
  141. this.list.fetchData()
  142. },
  143. handleOpenSidepage (row) {
  144. this.sidePageTriggerHandle(this, 'ProjectMappingSidePage', {
  145. id: row.id,
  146. resource: 'project_mappings',
  147. getParams: this.getParams,
  148. refresh: this.refresh,
  149. }, {
  150. list: this.list,
  151. hiddenActions: this.hiddenActions,
  152. })
  153. this.initSidePageTab('')
  154. },
  155. openSidePageRuleList (row) {
  156. this.sidePageTriggerHandle(this, 'ProjectMappingSidePage', {
  157. id: row.id,
  158. resource: 'project_mappings',
  159. getParams: this.getParams,
  160. refresh: this.refresh,
  161. }, {
  162. list: this.list,
  163. hiddenActions: this.hiddenActions,
  164. })
  165. this.initSidePageTab('rule-list')
  166. },
  167. checkEnable (list) {
  168. const ret = {
  169. validate: true,
  170. }
  171. list.map(item => {
  172. if (item.enabled) {
  173. ret.validate = false
  174. ret.tooltip = this.$t('cloudenv.text_595')
  175. }
  176. })
  177. return ret
  178. },
  179. },
  180. }
  181. </script>