columns.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {
  2. getNameDescriptionTableColumn,
  3. getProjectDomainTableColumn,
  4. getPublicScopeTableColumn,
  5. getTimeTableColumn,
  6. } from '@/utils/common/tableColumn'
  7. export default {
  8. destroyed () {
  9. this.pm = null
  10. },
  11. created () {
  12. this.pm = new this.$Manager('policies', 'v1')
  13. this.columns = [
  14. getNameDescriptionTableColumn({
  15. onManager: this.onManager,
  16. hideField: true,
  17. edit: false,
  18. slotCallback: row => {
  19. return (
  20. <side-page-trigger onTrigger={ () => this.handleOpenSidepage(row) }>{ row.name }</side-page-trigger>
  21. )
  22. },
  23. }),
  24. {
  25. field: 'match_policies',
  26. title: this.$t('dictionary.policy'),
  27. width: 100,
  28. slots: {
  29. default: ({ row }) => {
  30. const handleVisibleChange = async (visible) => {
  31. if (!visible) return
  32. if (row._policies || !row.match_policies || row.match_policies.length === 0) return
  33. await this.fetchPolicies({ row })
  34. }
  35. if (!row.match_policies || row.match_policies.length === 0) return this.$t('common.notData')
  36. const columns = [
  37. { field: 'name', title: this.$t('table.title.name') },
  38. { field: 'description', title: this.$t('table.title.desc') },
  39. ]
  40. const policies = row._policies
  41. const hasData = Array.isArray(policies) && policies.length > 0
  42. return [<a-popover trigger="hover" destroyTooltipOnHide onVisibleChange={handleVisibleChange} key={`role-policies-${row.id}-${hasData ? policies.length : 0}`}>
  43. <div slot="content" style={hasData ? { minWidth: '480px' } : {}}>
  44. {Array.isArray(policies)
  45. ? (hasData
  46. ? <vxe-grid data={ policies } columns={ columns } showOverflow={false} row-config={{ isHover: true }} column-config={{ resizable: false }} />
  47. : <div>{ this.$t('common.notData') }</div>)
  48. : <data-loading />}
  49. </div>
  50. <span style="color: var(--antd-wave-shadow-color)">{ (row.match_policies && row.match_policies.length) || 0 }</span>
  51. </a-popover>]
  52. },
  53. },
  54. },
  55. getPublicScopeTableColumn({ vm: this, resource: 'roles' }),
  56. getProjectDomainTableColumn(),
  57. getTimeTableColumn(),
  58. ]
  59. },
  60. methods: {
  61. async fetchPolicies ({ row }) {
  62. const policies = row.match_policies || []
  63. if (policies.length <= 0) {
  64. return true
  65. }
  66. try {
  67. const response = await this.pm.list({
  68. params: {
  69. name: policies,
  70. },
  71. })
  72. const data = response.data.data || []
  73. row._policies = data
  74. return response
  75. } catch (error) {
  76. throw error
  77. }
  78. },
  79. },
  80. }