CloudpolicyList.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :single-actions="singleActions"
  6. :group-actions="groupActions"
  7. :export-data-options="exportDataOptions" />
  8. </template>
  9. <script>
  10. import * as R from 'ramda'
  11. import { getNameFilter } from '@/utils/common/tableFilter'
  12. import WindowsMixin from '@/mixins/windows'
  13. import ListMixin from '@/mixins/list'
  14. export default {
  15. name: 'CloudpolicyListForCloudgroupSidepage',
  16. mixins: [WindowsMixin, ListMixin],
  17. props: {
  18. id: String,
  19. getParams: {
  20. type: Object,
  21. default: () => ({}),
  22. },
  23. resId: String,
  24. data: Object,
  25. },
  26. data () {
  27. return {
  28. list: this.$list.createList(this, {
  29. id: this.id,
  30. resource: 'cloudpolicies',
  31. apiVersion: 'v1',
  32. getParams: this.getParam,
  33. filterOptions: {
  34. name: getNameFilter(),
  35. description: {
  36. label: this.$t('cloudenv.text_331'),
  37. filter: true,
  38. formatter: val => `description.contains(${val})`,
  39. },
  40. },
  41. }),
  42. exportDataOptions: {
  43. items: [
  44. { label: 'ID', key: 'id' },
  45. { label: this.$t('table.title.name'), key: 'name' },
  46. { label: this.$t('table.title.desc'), key: 'description' },
  47. ],
  48. },
  49. groupActions: [
  50. {
  51. label: this.$t('common.remove'),
  52. permission: 'cloudpolicy_perform_revoke_group',
  53. action: () => {
  54. this.createDialog('DeleteResDialog', {
  55. vm: this,
  56. data: this.list.selectedItems,
  57. columns: this.columns,
  58. title: this.$t('common.remove'),
  59. name: this.$t('dictionary.cloudpolicy'),
  60. onManager: this.onManager,
  61. ok: async ids => {
  62. try {
  63. const response = await this.manager.batchPerformAction({
  64. ids,
  65. action: 'revoke-group',
  66. data: {
  67. cloudgroup_id: this.resId,
  68. },
  69. })
  70. this.list.refresh()
  71. return response
  72. } finally {}
  73. },
  74. })
  75. },
  76. meta: () => {
  77. if (!this.isOwner()) {
  78. return {
  79. validate: false,
  80. tooltip: this.$t('common_614'),
  81. }
  82. }
  83. return this.$getDeleteResult(this.list.selectedItems)
  84. },
  85. },
  86. ],
  87. singleActions: [
  88. {
  89. label: this.$t('common.remove'),
  90. permission: 'cloudpolicy_perform_revoke_group',
  91. action: (obj) => {
  92. this.createDialog('DeleteResDialog', {
  93. vm: this,
  94. data: [obj],
  95. columns: this.columns,
  96. title: this.$t('common.remove'),
  97. name: this.$t('dictionary.cloudpolicy'),
  98. onManager: this.onManager,
  99. ok: async ids => {
  100. try {
  101. const response = await this.manager.batchPerformAction({
  102. ids,
  103. action: 'revoke-group',
  104. data: {
  105. cloudgroup_id: this.resId,
  106. },
  107. })
  108. this.list.refresh()
  109. return response
  110. } finally {}
  111. },
  112. })
  113. },
  114. meta: (obj) => {
  115. const ret = {
  116. validate: true,
  117. }
  118. if (!this.isOwner()) {
  119. return {
  120. validate: false,
  121. tooltip: this.$t('common_614'),
  122. }
  123. }
  124. return ret
  125. },
  126. },
  127. ],
  128. columns: [
  129. {
  130. field: 'name',
  131. title: this.$t('common.name'),
  132. minWidth: 150,
  133. showOverflow: 'title',
  134. },
  135. {
  136. field: 'description',
  137. title: this.$t('table.title.desc'),
  138. minWidth: 250,
  139. showOverflow: 'title',
  140. },
  141. ],
  142. }
  143. },
  144. destroyed () {
  145. this.manager = null
  146. },
  147. created () {
  148. this.list.fetchData()
  149. this.$bus.$on('CloudpolicyListForCloudgroupSidepageRefresh', () => {
  150. this.list.refresh()
  151. }, this)
  152. this.manager = new this.$Manager('cloudpolicies', 'v1')
  153. },
  154. methods: {
  155. getParam () {
  156. const ret = {
  157. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  158. }
  159. return ret
  160. },
  161. isOwner () {
  162. return this.$store.getters.isAdminMode || (this.data && this.data.domain_id === this.$store.getters.userInfo.projectDomainId)
  163. },
  164. },
  165. }
  166. </script>