List.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :showSearchbox="showSearchbox"
  8. :showGroupActions="showGroupActions"
  9. :export-data-options="exportDataOptions" />
  10. </template>
  11. <script>
  12. import { mapGetters } from 'vuex'
  13. import WindowsMixin from '@/mixins/windows'
  14. import ListMixin from '@/mixins/list'
  15. import { getProjectDomainFilter, getEnabledFilter, getCreatedAtFilter } from '@/utils/common/tableFilter'
  16. import {
  17. getSetPublicAction,
  18. } from '@/utils/common/tableActions'
  19. import GlobalSearchMixin from '@/mixins/globalSearch'
  20. import SingleActionsMixin from '../mixins/singleActions'
  21. import ColumnsMixin from '../mixins/columns'
  22. export default {
  23. name: 'PolicyList',
  24. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin],
  25. props: {
  26. id: String,
  27. getParams: {
  28. type: Object,
  29. },
  30. type: String,
  31. },
  32. data () {
  33. return {
  34. list: this.$list.createList(this, {
  35. id: this.id,
  36. resource: 'policies',
  37. apiVersion: 'v1',
  38. getParams: this.getParam,
  39. filterOptions: {
  40. id: {
  41. label: this.$t('table.title.id'),
  42. },
  43. name: {
  44. label: this.$t('system.text_101'),
  45. filter: true,
  46. formatter: val => {
  47. return `name.contains("${val}")`
  48. },
  49. },
  50. project_domain: getProjectDomainFilter(),
  51. enabled: getEnabledFilter(),
  52. created_at: getCreatedAtFilter(),
  53. },
  54. responseData: this.responseData,
  55. hiddenColumns: ['created_at'],
  56. }),
  57. groupActions: [
  58. {
  59. label: this.$t('system.text_128'),
  60. permission: 'policies_create',
  61. action: () => {
  62. this.$router.push('/policy/create')
  63. },
  64. meta: () => {
  65. return {
  66. buttonType: 'primary',
  67. }
  68. },
  69. },
  70. {
  71. label: this.$t('system.text_226'),
  72. permission: 'policies_update',
  73. action: () => {
  74. this.createDialog('DisableDialog', {
  75. title: this.$t('system.text_341', [this.$t('dictionary.policy')]),
  76. name: this.$t('dictionary.policy'),
  77. columns: this.columns,
  78. data: this.list.selectedItems,
  79. ok: async () => {
  80. try {
  81. const response = await this.list.batchPerformAction('disable')
  82. return response
  83. } catch (error) {
  84. throw error
  85. }
  86. },
  87. })
  88. },
  89. meta: () => {
  90. let validate = true
  91. if (this.list.selectedItems.length <= 0) {
  92. validate = false
  93. }
  94. if (this.list.selectedItems.some(item => item.enabled === false)) {
  95. validate = false
  96. }
  97. if (this.list.selectedItems.some(item => !this.isOwnerPublic(item))) {
  98. validate = false
  99. }
  100. return {
  101. validate,
  102. }
  103. },
  104. },
  105. {
  106. label: this.$t('system.text_225'),
  107. permission: 'policies_update',
  108. action: () => {
  109. this.createDialog('DisableDialog', {
  110. title: this.$t('system.text_342', [this.$t('dictionary.policy')]),
  111. name: this.$t('dictionary.policy'),
  112. columns: this.columns,
  113. data: this.list.selectedItems,
  114. ok: async () => {
  115. try {
  116. const response = await this.list.batchPerformAction('enable')
  117. return response
  118. } catch (error) {
  119. throw error
  120. }
  121. },
  122. })
  123. },
  124. meta: () => {
  125. let validate = true
  126. if (this.list.selectedItems.length <= 0) {
  127. validate = false
  128. }
  129. if (this.list.selectedItems.some(item => item.enabled === true)) {
  130. validate = false
  131. }
  132. if (this.list.selectedItems.some(item => !this.isOwnerPublic(item))) {
  133. validate = false
  134. }
  135. return {
  136. validate,
  137. }
  138. },
  139. },
  140. getSetPublicAction(this, {
  141. name: this.$t('res.policy'),
  142. scope: 'domain',
  143. resource: 'policies',
  144. apiVersion: 'v1',
  145. noCandidateDomains: true,
  146. }, {
  147. permission: 'policies_perform_public',
  148. meta: () => {
  149. if (this.list.selectedItems.some(obj => obj.is_system)) {
  150. return {
  151. validate: false,
  152. tooltip: this.$t('policy.tooltip.system_policy'),
  153. }
  154. }
  155. return {
  156. validate: this.list.selectedItems.length,
  157. }
  158. },
  159. }),
  160. {
  161. label: this.$t('system.text_129'),
  162. permission: 'policies_delete',
  163. action: () => {
  164. this.createDialog('DeleteResDialog', {
  165. vm: this,
  166. data: this.list.selectedItems,
  167. columns: this.columns,
  168. title: this.$t('system.text_129'),
  169. name: this.$t('dictionary.policy'),
  170. onManager: this.onManager,
  171. })
  172. },
  173. meta: () => {
  174. return {
  175. validate: this.list.allowDelete(),
  176. }
  177. },
  178. },
  179. ],
  180. }
  181. },
  182. computed: {
  183. ...mapGetters(['isAdminMode', 'userInfo']),
  184. exportDataOptions () {
  185. return {
  186. title: this.$t('dictionary.policy'),
  187. downloadType: 'local',
  188. items: [
  189. { label: 'ID', field: 'id' },
  190. ...this.columns,
  191. ],
  192. }
  193. },
  194. },
  195. watch: {
  196. type (val) {
  197. this.$nextTick(() => {
  198. this.list.fetchData(0)
  199. })
  200. },
  201. },
  202. created () {
  203. this.initSidePageTab('policy-detail')
  204. this.list.fetchData()
  205. },
  206. methods: {
  207. getParam () {
  208. const ret = {
  209. ...this.getParams,
  210. details: true,
  211. }
  212. if (this.type === 'custom') {
  213. ret.is_system = false
  214. return ret
  215. }
  216. if (this.type === 'system') {
  217. ret.is_system = true
  218. return ret
  219. }
  220. return ret
  221. },
  222. isOwnerPublic (obj) {
  223. // fix by http://bug.yunion.io/zentao/bug-view-2958.html 共享的权限在其他域下时应该不能做任何操作
  224. if (obj.is_public) {
  225. if (this.isAdminMode) return true
  226. if (obj.domain_id !== this.userInfo.domain.id) return false
  227. }
  228. return true
  229. },
  230. handleOpenSidepage (row) {
  231. this.sidePageTriggerHandle(this, 'PolicySidePage', {
  232. id: row.id,
  233. resource: 'policies',
  234. apiVersion: 'v1',
  235. getParams: this.getParam,
  236. }, {
  237. list: this.list,
  238. })
  239. },
  240. },
  241. }
  242. </script>