DirectlyUnderUserList.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :showPage="false"
  8. default-search-key="users" />
  9. </template>
  10. <script>
  11. import * as R from 'ramda'
  12. import {
  13. getNameDescriptionTableColumn,
  14. getProjectDomainTableColumn,
  15. } from '@/utils/common/tableColumn'
  16. import i18n from '@/locales'
  17. import WindowsMixin from '@/mixins/windows'
  18. export default {
  19. name: 'ProjectDirectlyUnderUserList',
  20. mixins: [WindowsMixin],
  21. props: {
  22. resId: String,
  23. id: String,
  24. getParams: {
  25. type: Object,
  26. },
  27. onManager: {
  28. type: Function,
  29. },
  30. data: {
  31. type: Object,
  32. },
  33. },
  34. data () {
  35. return {
  36. list: this.$list.createList(this, {
  37. id: this.id,
  38. resource: this.getList,
  39. getParams: this.getParam,
  40. idKey: '__index',
  41. filterOptions: {
  42. users: {
  43. label: i18n.t('system.text_101'),
  44. },
  45. },
  46. }),
  47. columns: [
  48. {
  49. title: this.$t('common.name'),
  50. field: 'name',
  51. slots: {
  52. default: ({ row }) => {
  53. if (row.groupId && row.groupName) {
  54. return [
  55. <list-body-cell-wrap copy row={row} field='groupName' title={row.groupName} message={row.groupName} hideField={true}>
  56. <side-page-trigger permission='groups_get' name='GroupSidePage' id={row.groupId} vm={this}>{ row.groupName }</side-page-trigger>
  57. </list-body-cell-wrap>,
  58. ]
  59. }
  60. return [
  61. <list-body-cell-wrap copy row={row} field='name' title={row.name} message={row.name} hideField={true}>
  62. <side-page-trigger permission='users_get' name='UserSidePage' id={row.id} vm={this}>{ row.name }</side-page-trigger>
  63. </list-body-cell-wrap>,
  64. ]
  65. },
  66. },
  67. },
  68. {
  69. field: 'type',
  70. title: this.$t('system.text_48'),
  71. formatter: ({ row, cellValue }) => {
  72. if (row.groupId && row.groupName) {
  73. return this.$t('dictionary.group')
  74. }
  75. return this.$t('dictionary.user')
  76. },
  77. },
  78. {
  79. field: 'roles',
  80. title: this.$t('dictionary.role'),
  81. formatter: ({ cellValue }) => {
  82. return cellValue.map(x => x.name).join(', ')
  83. },
  84. },
  85. {
  86. title: this.$t('dictionary.policy'),
  87. field: 'role',
  88. slots: {
  89. default: ({ row }) => {
  90. if (R.isNil(row.policies) || R.isEmpty(row.policies)) return '-'
  91. Object.values(row.policies).flat(Infinity).join(', ')
  92. const policies = Object.values(row.policies).flat(Infinity)
  93. const ret = policies.map((item, idx) => {
  94. return (
  95. <div style="display: inline-block;">
  96. <side-page-trigger permission='policies_get' name='PolicySidePage' id={item} vm={this}>{ item }</side-page-trigger>
  97. { idx !== policies.length - 1 ? '、' : '' }
  98. </div>
  99. )
  100. })
  101. return ret
  102. },
  103. },
  104. },
  105. {
  106. title: this.$t('table.title.owner_domain'),
  107. field: 'project_domain',
  108. slots: {
  109. default: ({ row }) => {
  110. return row.domain?.name || '-'
  111. },
  112. },
  113. },
  114. ],
  115. groupActions: [
  116. {
  117. label: this.$t('common_114'),
  118. permission: 'projects_perform_join',
  119. action: () => {
  120. this.createDialog('ProjectAddUserOrGroupDialog', {
  121. data: [this.data],
  122. columns: [
  123. getNameDescriptionTableColumn({
  124. onManager: this.onManager,
  125. hideField: true,
  126. formRules: [
  127. { required: true, message: i18n.t('system.text_168') },
  128. ],
  129. slotCallback: row => {
  130. return (
  131. <side-page-trigger onTrigger={ () => this.handleOpenSidepage(row) }>{ row.name }</side-page-trigger>
  132. )
  133. },
  134. }),
  135. getProjectDomainTableColumn(),
  136. ],
  137. success: () => {
  138. this.list.refresh()
  139. this.$bus.$emit('SystemProjectsListRefresh')
  140. },
  141. })
  142. },
  143. meta: () => ({
  144. buttonType: 'primary',
  145. }),
  146. },
  147. {
  148. label: this.$t('compute.text_950'),
  149. permission: 'projects_perform_leave',
  150. action: () => {
  151. this.createDialog('ProjectDeleteResDialog', {
  152. vm: this,
  153. title: this.$t('system.text_129'),
  154. data: this.list.selectedItems,
  155. columns: this.columns,
  156. onManager: this.onManager,
  157. projectId: this.resId,
  158. success: () => {
  159. this.list.refresh()
  160. this.$bus.$emit('SystemProjectsListRefresh')
  161. },
  162. })
  163. },
  164. meta: () => {
  165. if (this.list.selectedItems.length <= 0) {
  166. return {
  167. validate: false,
  168. }
  169. }
  170. // if (this.list.selectedItems.some(item => { return item.groupId && item.groupName })) {
  171. // return {
  172. // validate: false,
  173. // }
  174. // }
  175. return {
  176. validate: true,
  177. }
  178. },
  179. },
  180. ],
  181. singleActions: [
  182. {
  183. label: this.$t('common_490'),
  184. permission: 'projects_perform_join',
  185. action: (obj) => {
  186. this.createDialog('ProjectEditRolesDialog', {
  187. data: [obj],
  188. columns: this.columns,
  189. title: this.$t('common_490'),
  190. uid: this.data.id,
  191. success: () => {
  192. this.list.refresh()
  193. },
  194. })
  195. },
  196. // meta: obj => ({
  197. // validate: !(obj.groupId && obj.groupName),
  198. // }),
  199. },
  200. {
  201. label: this.$t('compute.text_950'),
  202. permission: 'projects_delete',
  203. action: (obj) => {
  204. this.createDialog('ProjectDeleteResDialog', {
  205. vm: this,
  206. title: this.$t('system.text_129'),
  207. data: [obj],
  208. columns: this.columns,
  209. onManager: this.onManager,
  210. projectId: this.resId,
  211. success: () => {
  212. this.list.refresh()
  213. this.$bus.$emit('SystemProjectsListRefresh')
  214. },
  215. })
  216. },
  217. // meta: obj => ({
  218. // validate: !(obj.groupId && obj.groupName),
  219. // }),
  220. },
  221. ],
  222. }
  223. },
  224. created () {
  225. this.list.fetchData()
  226. this.$bus.$on('ProjectDirectlyUnderUserListRefresh', () => {
  227. this.list.refresh()
  228. }, this)
  229. },
  230. methods: {
  231. async getList (params) {
  232. if (params.users) {
  233. params.users.map((item, index) => {
  234. params[`users.${index}`] = item
  235. })
  236. Reflect.deleteProperty(params, 'users')
  237. }
  238. const { data: { data } } = await new this.$Manager('role_assignments', 'v1').objectRpc({
  239. methodname: 'GetProjectRole',
  240. objId: this.data.id,
  241. params: {
  242. ...params,
  243. ...this.getParams,
  244. scope: this.$store.getters.scope,
  245. show_fail_reason: true,
  246. effective: true,
  247. resource: 'project',
  248. group_by: 'user',
  249. limit: 20,
  250. },
  251. })
  252. return new Promise((resolve, reject) => {
  253. const ret = this.genResourceData(data)
  254. resolve(ret)
  255. })
  256. },
  257. genResourceData (data) {
  258. const arr = []
  259. data.forEach((item) => {
  260. const { groups, domain } = item
  261. groups.forEach((group, index) => {
  262. const { id, name } = item
  263. const obj = {
  264. id,
  265. name,
  266. __index: id + index,
  267. }
  268. const { id: groupId, name: groupName, roles, policies } = group
  269. if (groupId && groupName) {
  270. obj.id = groupId
  271. obj.name = groupName
  272. obj.__index = obj.id + index
  273. obj.groupId = groupId
  274. obj.groupName = groupName
  275. }
  276. obj.roles = roles
  277. obj.policies = policies
  278. obj.domain = domain
  279. arr.push(obj)
  280. })
  281. })
  282. for (let i = 0; i < arr.length; i++) {
  283. for (let j = i + 1; j < arr.length; j++) {
  284. if (arr[i].groupId && arr[i].groupId === arr[j].groupId) {
  285. arr.splice(j, 1)
  286. j--
  287. }
  288. }
  289. }
  290. const ret = {
  291. data: {
  292. data: arr,
  293. total: arr.length,
  294. },
  295. }
  296. return ret
  297. },
  298. getParam () {
  299. const ret = {
  300. ...this.getParams,
  301. resource: 'project',
  302. }
  303. return ret
  304. },
  305. },
  306. }
  307. </script>