columns.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import * as R from 'ramda'
  2. import { NODE_ROLE_MAP } from '@K8S/views/cluster/constants'
  3. import {
  4. getNameDescriptionTableColumn,
  5. getStatusTableColumn,
  6. } from '@/utils/common/tableColumn'
  7. import { HYPERVISORS_MAP } from '@/constants'
  8. import BrandIcon from '@/sections/BrandIcon'
  9. import { sizestr } from '@/utils/utils'
  10. import i18n from '@/locales'
  11. export default {
  12. created () {
  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: 'cluster',
  26. title: i18n.t('k8s.text_19'),
  27. minWidth: 50,
  28. },
  29. {
  30. field: 'role',
  31. title: i18n.t('k8s.text_24'),
  32. minWidth: 50,
  33. slots: {
  34. default: ({ row }, h) => {
  35. const cnRole = NODE_ROLE_MAP[row.role] || row.role
  36. return [<a-tag class="mr-2 d-block text-truncate" title={cnRole} color="blue">{cnRole}</a-tag>]
  37. },
  38. },
  39. },
  40. getStatusTableColumn({ statusModule: 'kubemachines' }),
  41. {
  42. field: 'cpuRequests/cpuCapacity',
  43. title: i18n.t('k8s.text_282'),
  44. minWidth: 70,
  45. formatter: ({ row }) => {
  46. if (row.machine_node && R.is(Object, row.machine_node.allocatedResources)) {
  47. const nodeInfo = row.machine_node.allocatedResources
  48. return (nodeInfo.cpuRequests / 1000) + ' / ' + (nodeInfo.cpuCapacity / 1000)
  49. }
  50. return '-/-'
  51. },
  52. },
  53. {
  54. field: 'memoryRequests/memoryCapacity',
  55. title: i18n.t('k8s.text_101'),
  56. minWidth: 70,
  57. formatter: ({ row }) => {
  58. if (row.machine_node && R.is(Object, row.machine_node.allocatedResources)) {
  59. const nodeInfo = row.machine_node.allocatedResources
  60. return sizestr(nodeInfo.memoryRequests, 'B', 1024) + ' / ' + sizestr(nodeInfo.memoryCapacity, 'B', 1024)
  61. }
  62. return '-/-'
  63. },
  64. },
  65. {
  66. field: 'address',
  67. title: i18n.t('k8s.text_283'),
  68. minWidth: 100,
  69. showOverflow: 'ellipsis',
  70. },
  71. {
  72. title: i18n.t('k8s.platform'),
  73. field: 'hypervisor',
  74. slots: {
  75. default: ({ row }, h) => {
  76. if (!row.hypervisor) return '-'
  77. const brand = HYPERVISORS_MAP[row.hypervisor].brand
  78. if (!brand) return '-'
  79. return [
  80. <BrandIcon name={ brand } />,
  81. ]
  82. },
  83. },
  84. },
  85. ]
  86. },
  87. }