columns.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import _ from 'lodash'
  2. import { STORAGE_TYPES, MEDIUM_TYPES } from '@Storage/constants/index.js'
  3. import { sizestr } from '@/utils/utils'
  4. import { getNameDescriptionTableColumn, getEnabledTableColumn, getStatusTableColumn, getBrandTableColumn, getPublicScopeTableColumn, getProjectDomainTableColumn, getTagTableColumn, getRegionTableColumn, getTimeTableColumn } from '@/utils/common/tableColumn'
  5. import i18n from '@/locales'
  6. export default {
  7. created () {
  8. this.columns = [
  9. getNameDescriptionTableColumn({
  10. onManager: this.onManager,
  11. hideField: true,
  12. formRules: [
  13. { required: true, message: this.$t('storage.text_56') },
  14. { validator: this.$validate('blockStorageName') },
  15. ],
  16. slotCallback: row => {
  17. return (
  18. <side-page-trigger onTrigger={ () => this.handleOpenSidepage(row) }>{ row.name_cn ? `${row.name}(${row.name_cn})` : row.name }</side-page-trigger>
  19. )
  20. },
  21. }),
  22. getStatusTableColumn({ statusModule: 'blockstorage', vm: this }),
  23. getEnabledTableColumn(),
  24. getTagTableColumn({
  25. onManager: this.onManager,
  26. resource: 'storages',
  27. columns: () => this.columns,
  28. tipName: this.$t('dictionary.blockstorage'),
  29. editCheck: (row) => (row.provider || '').toLowerCase() !== 'bingocloud',
  30. }),
  31. {
  32. field: 'capacity',
  33. title: this.$t('storage.text_177'),
  34. width: 180,
  35. slots: {
  36. default: ({ row }, h) => {
  37. const title = `${this.$t('common_407')}: ${sizestr(row.actual_capacity_used, 'M', 1024)}\n${this.$t('common_234')}: ${sizestr(row.capacity, 'M', 1024)}`
  38. return [<UsedPercent title={title} used={row.actual_capacity_used} total={row.capacity} usedFormatter={(val) => sizestr(val, 'M', 1024)} totalFormatter={(val) => sizestr(val, 'M', 1024)} />]
  39. },
  40. },
  41. formatter: ({ row }) => {
  42. const title = `${this.$t('common_407')}: ${sizestr(row.actual_capacity_used, 'M', 1024)}\n${this.$t('common_234')}: ${sizestr(row.capacity, 'M', 1024)}`
  43. return title
  44. },
  45. },
  46. {
  47. field: 'virtual_capacity',
  48. title: i18n.t('storage.text_43'),
  49. width: 180,
  50. slots: {
  51. default: ({ row }, h) => {
  52. const title = `${this.$t('common_233')}: ${sizestr(row.used_capacity, 'M', 1024)}\n${this.$t('common_234')}: ${sizestr(row.virtual_capacity, 'M', 1024)}`
  53. return [<UsedPercent title={title} used={row.used_capacity} total={row.virtual_capacity} usedFormatter={(val) => sizestr(val, 'M', 1024)} totalFormatter={(val) => sizestr(val, 'M', 1024)} />]
  54. },
  55. },
  56. formatter: ({ row }) => {
  57. const title = `${this.$t('common_233')}: ${sizestr(row.used_capacity, 'M', 1024)}\n${this.$t('common_234')}: ${sizestr(row.virtual_capacity, 'M', 1024)}`
  58. return title
  59. },
  60. },
  61. {
  62. field: 'storage_type',
  63. title: i18n.t('storage.text_38'),
  64. width: 100,
  65. formatter: ({ row }) => {
  66. return STORAGE_TYPES[row.storage_type] || row.storage_type
  67. },
  68. },
  69. {
  70. field: 'medium_type',
  71. title: i18n.t('storage.text_39'),
  72. width: 120,
  73. formatter: ({ row }) => {
  74. return MEDIUM_TYPES[row.medium_type] || row.medium_type
  75. },
  76. },
  77. getBrandTableColumn(),
  78. {
  79. field: 'schedtag',
  80. title: i18n.t('storage.text_45'),
  81. width: 120,
  82. slots: {
  83. default: ({ row }) => {
  84. const tags = _.sortBy(row.schedtags, ['default', 'name'])
  85. if (!tags.length) {
  86. return [
  87. <div class='text-color-help'>{ this.$t('storage.text_171') }</div>,
  88. ]
  89. }
  90. const list = tags.map(tag => <a-tag class='mb-2 mr-1' color='blue'>{tag.name}</a-tag>)
  91. return [<list-body-cell-popover text={this.$t('compute.text_619', [tags.length])} max-width="400px">
  92. <div style="display: inline-flex; flex-wrap: wrap; max-width: 40vw;">
  93. {...list}
  94. </div>
  95. </list-body-cell-popover>]
  96. },
  97. },
  98. },
  99. getPublicScopeTableColumn({ vm: this, resource: 'storages' }),
  100. getProjectDomainTableColumn(),
  101. getRegionTableColumn(),
  102. getTimeTableColumn(),
  103. ]
  104. },
  105. }