Projects.vue 10 KB

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