| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- <template>
- <page-list
- :list="list"
- :columns="columns"
- :group-actions="groupActions"
- :single-actions="singleActions"
- :export-data-options="exportDataOptions"
- default-search-key="projects" />
- </template>
- <script>
- import * as R from 'ramda'
- import {
- getNameDescriptionTableColumn,
- getProjectDomainTableColumn,
- } from '@/utils/common/tableColumn'
- import i18n from '@/locales'
- import WindowsMixin from '@/mixins/windows'
- import ListMixin from '@/mixins/list'
- export default {
- name: 'GroupProjectList',
- mixins: [WindowsMixin, ListMixin],
- props: {
- resId: String,
- id: String,
- getParams: {
- type: Object,
- },
- data: {
- type: Object,
- },
- },
- data () {
- return {
- list: this.$list.createList(this, {
- id: this.id,
- resource: this.getList,
- getParams: this.getParam,
- idKey: '__index',
- filterOptions: {
- projects: {
- label: i18n.t('dictionary.project'),
- },
- },
- }),
- // exportDataOptions: {
- // items: [
- // { label: 'ID', key: 'id' },
- // { label: this.$t('table.title.name'), key: 'name' },
- // { label: this.$t('dictionary.role'), key: 'roles' },
- // ],
- // },
- columns: [
- {
- title: this.$t('common_389'),
- field: 'name',
- slots: {
- default: ({ row }) => {
- return [
- <list-body-cell-wrap copy row={row} onManager={this.onManager} field='name' title={row.name} message={row.name} hideField={true}>
- <side-page-trigger permission='projects_get' name='ProjectSidePage' id={row.id} vm={this}>{ row.name }</side-page-trigger>
- </list-body-cell-wrap>,
- ]
- },
- },
- },
- {
- field: 'roles',
- title: this.$t('dictionary.role'),
- formatter: ({ cellValue }) => {
- return cellValue.map(x => x.name).join(', ')
- },
- },
- {
- title: this.$t('dictionary.policy'),
- field: 'role',
- slots: {
- default: ({ row }) => {
- if (R.isNil(row.policies) || R.isEmpty(row.policies)) return '-'
- Object.values(row.policies).flat(Infinity).join(', ')
- const policies = Object.values(row.policies).flat(Infinity)
- const ret = policies.map((item, idx) => {
- return (
- <div style="display: inline-block;">
- <side-page-trigger permission='policies_get' name='PolicySidePage' id={item} vm={this}>{ item }</side-page-trigger>
- { idx !== policies.length - 1 ? '、' : '' }
- </div>
- )
- })
- return ret
- },
- },
- },
- {
- title: this.$t('table.title.owner_domain'),
- field: 'project_domain',
- slots: {
- default: ({ row }) => {
- return row.domain?.name || '-'
- },
- },
- },
- ],
- groupActions: [
- {
- label: this.$t('common_384'),
- permission: 'projects_perform_join',
- action: () => {
- this.createDialog('GroupJoinProjectDialog', {
- data: [this.data],
- columns: [
- getNameDescriptionTableColumn({
- onManager: this.onManager,
- hideField: true,
- slotCallback: row => {
- return (
- <side-page-trigger onTrigger={ () => this.handleOpenSidepage(row) }>{ row.name }</side-page-trigger>
- )
- },
- formRules: [{
- required: true,
- message: i18n.t('system.text_168'),
- whitespace: true,
- }],
- }),
- getProjectDomainTableColumn(),
- ],
- success: () => {
- this.refresh()
- this.$bus.$emit('GroupUserListRefresh')
- },
- })
- },
- meta: () => {
- return {
- buttonType: 'primary',
- }
- },
- },
- {
- label: this.$t('compute.text_950'),
- permission: 'projects_perform_leave',
- action: () => {
- this.createDialog('GroupLeaveProjectDialog', {
- data: this.list.selectedItems,
- columns: this.columns,
- resId: this.resId,
- success: () => {
- this.list.refresh()
- },
- })
- },
- meta: () => {
- return {
- validate: this.list.selectedItems.length >= 1,
- }
- },
- },
- ],
- singleActions: [
- {
- label: this.$t('common_490'),
- permission: 'projects_perform_join',
- action: (obj) => {
- this.createDialog('GroupEditRolesDialog', {
- data: [obj],
- columns: this.columns,
- title: this.$t('common_490'),
- uid: this.data.id,
- refresh: this.refresh,
- })
- },
- },
- {
- label: this.$t('compute.text_950'),
- permission: 'projects_perform_leave',
- action: (obj) => {
- this.createDialog('GroupLeaveProjectDialog', {
- data: [obj],
- columns: this.columns,
- resId: this.resId,
- success: () => {
- this.list.refresh()
- },
- })
- },
- },
- ],
- }
- },
- created () {
- this.list.fetchData()
- },
- methods: {
- async getList (params) {
- if (params.projects) {
- params.projects.map((item, index) => {
- params[`projects.${index}`] = item
- })
- Reflect.deleteProperty(params, 'projects')
- }
- const { data: { data } } = await new this.$Manager('role_assignments', 'v1').objectRpc({
- methodname: 'GetProjectRole',
- objId: this.data.id,
- params: {
- ...params,
- ...this.getParams,
- scope: this.$store.getters.scope,
- show_fail_reason: true,
- resource: 'group',
- group_by: 'project',
- limit: 20,
- },
- })
- return new Promise((resolve, reject) => {
- const ret = this.genResourceData(data)
- resolve(ret)
- })
- },
- genResourceData (data) {
- const arr = []
- data.map((item) => {
- const { groups, domain } = item
- groups.map((group, index) => {
- const { id, name } = item
- const obj = {
- id,
- name,
- __index: id + index,
- }
- const { id: groupId, name: groupName, roles, policies } = group
- if (groupId && groupName) {
- obj.groupId = groupId
- obj.groupName = groupName
- }
- obj.roles = roles
- obj.policies = policies
- obj.domain = domain
- arr.push(obj)
- })
- })
- const ret = {
- data: {
- data: arr,
- total: arr.length,
- },
- }
- return ret
- },
- getParam () {
- const ret = {
- ...this.getParams,
- details: true,
- }
- return ret
- },
- },
- }
- </script>
|