columns.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import * as R from 'ramda'
  2. import {
  3. getNameDescriptionTableColumn,
  4. getBrandTableColumn,
  5. getStatusTableColumn,
  6. getProjectDomainTableColumn,
  7. getPublicScopeTableColumn,
  8. getAccountTableColumn,
  9. getTimeTableColumn,
  10. } from '@/utils/common/tableColumn'
  11. import i18n from '@/locales'
  12. export default {
  13. created () {
  14. this.columns = [
  15. getNameDescriptionTableColumn({
  16. onManager: this.onManager,
  17. hideField: true,
  18. formRules: [
  19. { required: true, message: i18n.t('common.text00042') },
  20. ],
  21. slotCallback: row => {
  22. return (
  23. <side-page-trigger permission='cloudgroup_get' name='CloudgroupSidePage' id={row.id} list={this.list} vm={this}>{ row.name }</side-page-trigger>
  24. )
  25. },
  26. }),
  27. getStatusTableColumn({ statusModule: 'cloudgroup' }),
  28. {
  29. field: 'cloudpolicies',
  30. title: i18n.t('cloudenv.text_329'),
  31. slots: {
  32. default: ({ row }) => {
  33. const handleVisibleChange = async (visible) => {
  34. if (visible && !row.feCloudpolicies && row.cloudpolicies && row.cloudpolicies.length > 0) {
  35. await this.loadPolicy({ row })
  36. }
  37. }
  38. if (R.isNil(row.cloudpolicies) || R.isEmpty(row.cloudpolicies)) {
  39. return i18n.t('cloudenv.text_330')
  40. }
  41. const columns = [
  42. {
  43. field: 'name',
  44. title: this.$t('common.name'),
  45. },
  46. {
  47. field: 'description',
  48. title: this.$t('table.title.desc'),
  49. formatter: ({ cellValue }) => cellValue || '-',
  50. },
  51. ]
  52. return [<a-popover trigger="hover" onVisibleChange={handleVisibleChange} key={`popover-${row.id}-${row.feCloudpolicies ? row.feCloudpolicies.length : 0}`}>
  53. <div slot="content" style={row.feCloudpolicies && row.feCloudpolicies.length > 0 ? { minWidth: '600px' } : {}}>
  54. {row.feCloudpolicies && row.feCloudpolicies.length > 0 ? (
  55. <vxe-grid
  56. showOverflow={false}
  57. row-config={{ isHover: true }}
  58. column-config={{ resizable: false }}
  59. data={ row.feCloudpolicies }
  60. columns={ columns } />
  61. ) : (
  62. <data-loading />
  63. )}
  64. </div>
  65. <span style="color: var(--antd-wave-shadow-color)">{i18n.t('cloudenv.text_245', [row.cloudpolicies.length])}</span>
  66. </a-popover>]
  67. },
  68. },
  69. formatter: ({ row }) => {
  70. return [i18n.t('cloudenv.text_245', [(row.cloudpolicies && row.cloudpolicies.length) || 0])]
  71. },
  72. },
  73. getBrandTableColumn({ field: 'provider' }),
  74. getAccountTableColumn({ field: 'cloudaccount', title: this.$t('common.text00108') }),
  75. getPublicScopeTableColumn({ vm: this, resource: 'cloudgroups' }),
  76. getProjectDomainTableColumn(),
  77. getTimeTableColumn(),
  78. ]
  79. },
  80. methods: {
  81. async loadPolicy ({ row }) {
  82. let manager = new this.$Manager('cloudpolicies', 'v1')
  83. try {
  84. const response = await manager.list({
  85. params: {
  86. cloudgroup_id: row.id,
  87. scope: this.$store.getters.scope,
  88. },
  89. })
  90. this.$set(row, 'feCloudpolicies', response.data.data || [])
  91. return response
  92. } catch (error) {
  93. throw error
  94. } finally {
  95. manager = null
  96. }
  97. },
  98. },
  99. }