columns.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { sizestr } from '@/utils/utils'
  2. import SystemIcon from '@/sections/SystemIcon'
  3. import { getStatusTableColumn, getNameDescriptionTableColumn, getProjectTableColumn, getPublicScopeTableColumn, getTimeTableColumn, getTagTableColumn, getOsArch } from '@/utils/common/tableColumn'
  4. import i18n from '@/locales'
  5. export default {
  6. created () {
  7. this.columns = [
  8. getNameDescriptionTableColumn({
  9. width: 200,
  10. addLock: true,
  11. addEncrypt: true,
  12. onManager: this.onManager,
  13. hideField: true,
  14. formRules: [
  15. { required: true, message: this.$t('compute.text_210') },
  16. { validator: this.$validate('imageName') },
  17. ],
  18. slotCallback: row => {
  19. return (
  20. <side-page-trigger onTrigger={ () => this.handleOpenSidepage(row) }>{ row.name }</side-page-trigger>
  21. )
  22. },
  23. }),
  24. getStatusTableColumn({ statusModule: 'image', vm: this }),
  25. getTagTableColumn({ onManager: this.onManager, resource: 'guestimages', columns: () => this.columns }),
  26. {
  27. field: 'child_image',
  28. title: i18n.t('table.title.child_image'),
  29. width: 150,
  30. slots: {
  31. default: ({ row }) => {
  32. if (this.isPreLoad && !row.data_images) return [<data-loading />]
  33. const arr = [...(row.data_images || [])]
  34. arr.push(row.root_image.name)
  35. const len = arr.length
  36. let list = []
  37. if (row.data_images && row.data_images.length > 0) {
  38. list = row.data_images.map(val => (
  39. <a-tag class='mb-2 mr-1'>{ val.name }</a-tag>
  40. ))
  41. }
  42. list.push(
  43. <a-tag class='mb-2 mr-1'>{ row.root_image?.name }</a-tag>,
  44. )
  45. return [<list-body-cell-popover text={i18n.t('compute.text_619', [len])} max-width="400px">
  46. <div style="display: inline-flex; flex-wrap: wrap; max-width: 40vw;">
  47. {...list}
  48. </div>
  49. </list-body-cell-popover>]
  50. },
  51. },
  52. formatter: ({ row }) => {
  53. let list = []
  54. if (row.data_images && row.data_images.length > 0) {
  55. list = row.data_images.map(val => (
  56. val.name
  57. ))
  58. }
  59. if (row.root_image?.name) {
  60. list.push(row.root_image?.name)
  61. }
  62. return list.join(',')
  63. },
  64. },
  65. {
  66. field: 'disk_format',
  67. title: i18n.t('table.title.disk_format'),
  68. width: 100,
  69. slots: {
  70. default: ({ row }) => {
  71. if (!row.disk_format) return [<data-loading />]
  72. return row.disk_format.toUpperCase()
  73. },
  74. },
  75. formatter: ({ row }) => {
  76. return (row.disk_format || '').toUpperCase()
  77. },
  78. },
  79. getOsArch(),
  80. {
  81. field: 'os_type',
  82. title: i18n.t('table.title.os'),
  83. width: 60,
  84. slots: {
  85. default: ({ row }) => {
  86. if (this.isPreLoad && !row.properties) return [<data-loading />]
  87. let name = row.properties?.os_distribution ? decodeURI(row.properties?.os_distribution) : row.properties?.os_type || ''
  88. if (name.includes('Windows') || name.includes('windows')) {
  89. name = 'Windows'
  90. }
  91. const tooltip = (row.properties?.os_version ? `${name} ${row.properties?.os_version}` : name) || i18n.t('compute.text_339')
  92. return [
  93. <SystemIcon tooltip={ tooltip } name={ name } />,
  94. ]
  95. },
  96. },
  97. formatter: ({ row }) => {
  98. let name = row.properties?.os_distribution ? decodeURI(row.properties?.os_distribution) : row.properties?.os_type || ''
  99. if (name.includes('Windows') || name.includes('windows')) {
  100. name = 'Windows'
  101. }
  102. return name
  103. },
  104. },
  105. {
  106. field: 'size',
  107. title: i18n.t('table.title.image_size'),
  108. minWidth: 100,
  109. slots: {
  110. default: ({ row }) => {
  111. if (this.isPreLoad && row.size === undefined) return [<data-loading />]
  112. return sizestr(row.size, 'B', 1024)
  113. },
  114. },
  115. formatter: ({ row }) => {
  116. return sizestr(row.size, 'B', 1024)
  117. },
  118. },
  119. {
  120. field: 'is_standard',
  121. title: i18n.t('table.title.image_type'),
  122. width: 100,
  123. formatter: ({ cellValue }) => {
  124. if (cellValue) return i18n.t('compute.text_620')
  125. return i18n.t('compute.text_621')
  126. },
  127. },
  128. getTimeTableColumn(),
  129. getPublicScopeTableColumn({ vm: this, resource: 'guestimages' }),
  130. getProjectTableColumn(),
  131. ]
  132. },
  133. }