List.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <page-list
  3. show-tag-columns
  4. show-tag-filter
  5. show-tag-config
  6. :list="list"
  7. :columns="columns"
  8. :single-actions="singleActions"
  9. :group-actions="groupActions"
  10. :showSearchbox="showSearchbox"
  11. :showGroupActions="showGroupActions"
  12. :showSingleActions="showSingleActions"
  13. :export-data-options="exportDataOptions"
  14. :tag-config-params="tagConfigParams"
  15. :ext-tag-params="{ service: 'identity' }" />
  16. </template>
  17. <script>
  18. import { mapGetters } from 'vuex'
  19. import WindowsMixin from '@/mixins/windows'
  20. import ListMixin from '@/mixins/list'
  21. // import { Manager } from '@/utils/manager'
  22. // import store from '@/store'
  23. import { getProjectDomainFilter, getDescriptionFilter, getCreatedAtFilter, getDistinctFieldFilter } from '@/utils/common/tableFilter'
  24. import GlobalSearchMixin from '@/mixins/globalSearch'
  25. import SingleActionsMixin from '../mixins/singleActions'
  26. import ColumnsMixin from '../mixins/columns'
  27. // const genUserProjectData = (data) => {
  28. // const userList = []
  29. // const groupList = []
  30. // data.forEach((item) => {
  31. // const { groups } = item
  32. // groups.forEach((group, index) => {
  33. // const { name } = item
  34. // const { id: groupId, name: groupName } = group
  35. // if (groupId && groupName) {
  36. // groupList.push(groupName)
  37. // } else {
  38. // userList.push(name)
  39. // }
  40. // })
  41. // })
  42. // return { groupList, userList }
  43. // }
  44. export default {
  45. name: 'ProjectList',
  46. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin],
  47. props: {
  48. id: String,
  49. getParams: {
  50. type: Object,
  51. default: () => ({}),
  52. },
  53. isAllowCreate: {
  54. type: Boolean,
  55. default: true,
  56. },
  57. showSingleActions: {
  58. type: Boolean,
  59. default: true,
  60. },
  61. },
  62. data () {
  63. return {
  64. list: this.$list.createList(this, {
  65. id: this.id,
  66. getParams: this.getParams,
  67. resource: 'projects',
  68. apiVersion: 'v1',
  69. filterOptions: {
  70. id: {
  71. label: this.$t('table.title.id'),
  72. },
  73. name: {
  74. label: this.$t('system.text_101'),
  75. filter: true,
  76. formatter: val => {
  77. return `name.contains("${val}")`
  78. },
  79. },
  80. description: getDescriptionFilter(),
  81. project_domain: getProjectDomainFilter(),
  82. created_at: getCreatedAtFilter(),
  83. user_id: {
  84. label: this.$t('dictionary.user'),
  85. },
  86. admin_id: getDistinctFieldFilter({ label: this.$t('iam.project_admin'), field: 'admin', type: 'extra_field' }),
  87. group_id: {
  88. label: this.$t('dictionary.group'),
  89. },
  90. idp_id: {
  91. label: this.$t('dictionary.identity_provider'),
  92. },
  93. },
  94. responseData: this.responseData,
  95. hiddenColumns: ['created_at'],
  96. }),
  97. tagConfigParams: {
  98. id: this.id,
  99. title: this.$t('common.text00124'),
  100. resource: 'projects',
  101. queryTreeId: 'tag-value-tree',
  102. tagFilterKey: 'tags',
  103. },
  104. }
  105. },
  106. computed: {
  107. ...mapGetters(['globalConfig']),
  108. groupActions () {
  109. const actions = [
  110. {
  111. label: this.$t('system.text_128'),
  112. permission: 'projects_create',
  113. action: () => {
  114. this.$router.push('/project/create')
  115. },
  116. meta: () => {
  117. return {
  118. buttonType: 'primary',
  119. }
  120. },
  121. },
  122. {
  123. label: this.$t('table.action.set_tag'),
  124. permission: 'projects_perform_set_user_metadata',
  125. action: () => {
  126. this.createDialog('SetTagDialog', {
  127. data: this.list.selectedItems,
  128. columns: this.columns,
  129. onManager: this.onManager,
  130. params: {
  131. resource: 'projects',
  132. with_cloud_meta: false,
  133. service: 'identity',
  134. },
  135. managerInstance: new this.$Manager('metadatas/tag-value-pairs', 'v2'),
  136. mode: 'add',
  137. })
  138. },
  139. meta: () => {
  140. return {
  141. validate: this.list.selectedItems.length > 0,
  142. }
  143. },
  144. },
  145. {
  146. label: this.$t('iam.set_project_admin'),
  147. permission: 'projects_perform_set_admin',
  148. action: () => {
  149. this.createDialog('ProjectSetAdminDialog', {
  150. vm: this,
  151. title: this.$t('iam.set_project_admin'),
  152. name: this.$t('system.text_9'),
  153. data: this.list.selectedItems,
  154. columns: this.columns,
  155. onManager: this.onManager,
  156. })
  157. },
  158. meta: () => {
  159. return {
  160. validate: this.list.selectedItems.length > 0,
  161. }
  162. },
  163. },
  164. {
  165. label: this.$t('system.text_129'),
  166. permission: 'projects_delete',
  167. action: () => {
  168. this.createDialog('DeleteResDialog', {
  169. vm: this,
  170. title: this.$t('system.text_129'),
  171. name: this.$t('dictionary.project'),
  172. data: this.list.selectedItems,
  173. columns: this.columns,
  174. onManager: this.onManager,
  175. })
  176. },
  177. meta: () => {
  178. return {
  179. validate: this.list.allowDelete(),
  180. }
  181. },
  182. },
  183. ]
  184. if (!this.isAllowCreate) actions.shift()
  185. return actions
  186. },
  187. exportDataOptions () {
  188. const ret = {
  189. downloadType: 'local',
  190. title: this.$t('dictionary.project'),
  191. items: [
  192. { label: 'ID', key: 'id' },
  193. ...this.columns,
  194. // {
  195. // key: 'users',
  196. // label: this.$t('iam.joined_user'),
  197. // },
  198. // {
  199. // key: 'groups',
  200. // label: this.$t('common_495'),
  201. // },
  202. ],
  203. // async callback (data, selectedExportKeys) {
  204. // if (!selectedExportKeys.includes('users') && !selectedExportKeys.includes('groups')) {
  205. // return data
  206. // }
  207. // const manager = new Manager('role_assignments', 'v1')
  208. // const allPromise = data.map(async item => {
  209. // let groupStr = ''
  210. // let userStr = ''
  211. // try {
  212. // const { data: { data } } = await manager.objectRpc({
  213. // methodname: 'GetProjectRole',
  214. // objId: item.id,
  215. // params: {
  216. // scope: store.getters.scope,
  217. // show_fail_reason: true,
  218. // effective: true,
  219. // resource: 'project',
  220. // group_by: 'user',
  221. // },
  222. // })
  223. // const { userList, groupList } = genUserProjectData(data)
  224. // groupStr = groupList.join(',')
  225. // userStr = userList.join(',')
  226. // } catch (error) {
  227. // console.log(`project: ${item.id}, user info fetch error!!!`)
  228. // throw error
  229. // }
  230. // return Promise.resolve({ id: item.id, groups: groupStr, users: userStr })
  231. // })
  232. // const results = Promise.all(allPromise).then(values => {
  233. // const realData = data.map(item => {
  234. // const curObj = values.find(v => v.id === item.id)
  235. // return {
  236. // ...item,
  237. // groups: curObj.groups,
  238. // users: curObj.users,
  239. // }
  240. // })
  241. // return realData
  242. // })
  243. // return results
  244. // },
  245. }
  246. return ret
  247. },
  248. },
  249. created () {
  250. this.initSidePageTab('project-detail')
  251. this.list.fetchData()
  252. this.$bus.$on('SystemProjectsListRefresh', args => {
  253. this.list.refresh()
  254. }, this)
  255. },
  256. methods: {
  257. handleOpenSidepage (row, tab) {
  258. this.sidePageTriggerHandle(this, 'ProjectSidePage', {
  259. id: row.id,
  260. resource: 'projects',
  261. apiVersion: 'v1',
  262. getParams: this.getParams,
  263. }, {
  264. list: this.list,
  265. tab,
  266. })
  267. },
  268. },
  269. }
  270. </script>