columns.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { NOTIFY_SUBSCRIBER_TYPES_MAP, NOTIFY_ROLE_SCOPES_MAP } from '@IAM/constants'
  2. import {
  3. getEnabledTableColumn,
  4. } from '@/utils/common/tableColumn'
  5. import i18n from '@/locales'
  6. export default {
  7. created () {
  8. // 资源范围、启用状态、类型、接收对象
  9. this.columns = [
  10. {
  11. title: i18n.t('system.notify.topic.receiver.resource_scope'),
  12. field: 'resource_scope',
  13. sortable: true,
  14. showOverflow: 'ellipsis',
  15. formatter: ({ row }) => {
  16. if (row.resource_scope === 'system') {
  17. return this.$t('cloudenv.text_504')
  18. } else if (row.resource_scope === 'domain') {
  19. return this.$t('cloudenv.text_505', [row.resource_attribution_name || row.resource_attribution_id])
  20. } else if (row.resource_scope === 'project') {
  21. return this.$t('cloudenv.text_506', [row.resource_attribution_name || row.resource_attribution_id])
  22. } else {
  23. return this.resource_scope
  24. }
  25. },
  26. },
  27. getEnabledTableColumn(),
  28. {
  29. title: i18n.t('system.text_48'),
  30. field: 'type',
  31. sortable: true,
  32. minWidth: 100,
  33. showOverflow: 'title',
  34. formatter: ({ row }) => {
  35. return NOTIFY_SUBSCRIBER_TYPES_MAP[row.type] ? NOTIFY_SUBSCRIBER_TYPES_MAP[row.type].label : '-'
  36. },
  37. },
  38. {
  39. title: i18n.t('system.notify.subscriber.receivers'),
  40. field: 'receivers',
  41. sortable: true,
  42. showOverflow: 'ellipsis',
  43. minWidth: 100,
  44. formatter: ({ row }) => {
  45. if (row.type === 'robot') {
  46. return row.robot ? row.robot.name : '-'
  47. } else if (row.type === 'role') {
  48. if (!row.role) return '-'
  49. if (!row.role_scope) return row.role.name
  50. const scope = NOTIFY_ROLE_SCOPES_MAP[row.role_scope]
  51. if (!scope) return row.role.name
  52. return `${row.role.name} (${scope.label})`
  53. } else if (row.type === 'receiver') {
  54. if (!row.receivers) return '-'
  55. const ret = []
  56. for (const r of row.receivers) {
  57. if (r.name) {
  58. ret.push(r.name)
  59. }
  60. }
  61. return ret.join(' ,')
  62. } else {
  63. return '-'
  64. }
  65. },
  66. },
  67. {
  68. title: i18n.t('iam.notify_silent'),
  69. field: 'group_times',
  70. minWidth: 100,
  71. formatter: ({ row }) => {
  72. const { group_times = 0 } = row
  73. if (!group_times) return '-'
  74. if (group_times < 60) {
  75. return i18n.t('iam.silent.minute', [group_times])
  76. } else {
  77. return i18n.t('iam.silent.hour', [parseInt(group_times / 60)])
  78. }
  79. },
  80. },
  81. ]
  82. },
  83. }