storageResourceProps.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import _ from 'lodash'
  2. import {
  3. getNameDescriptionTableColumn,
  4. getEnabledTableColumn,
  5. getStatusTableColumn,
  6. getBrandTableColumn,
  7. getPublicScopeTableColumn,
  8. getProjectDomainTableColumn,
  9. getRegionTableColumn,
  10. getTimeTableColumn,
  11. } from '@/utils/common/tableColumn'
  12. import {
  13. getNameFilter,
  14. } from '@/utils/common/tableFilter'
  15. import { sizestr } from '@/utils/utils'
  16. import { STORAGE_TYPES, MEDIUM_TYPES } from '@Storage/constants'
  17. export default {
  18. computed: {
  19. resourceProps () {
  20. return {
  21. list: this.$list.createList(this, {
  22. id: 'VmStoragesListForChangeBlockStorageDialog',
  23. resource: 'storages',
  24. getParams: {
  25. host_id: this.selectedItems[0].host_id,
  26. filter: `id.notin(${this.selectedItemsStorageIds.join(',')})`,
  27. },
  28. filterOptions: {
  29. id: {
  30. label: this.$t('table.title.id'),
  31. },
  32. name: getNameFilter(),
  33. },
  34. }),
  35. columns: [
  36. getNameDescriptionTableColumn({
  37. hideField: true,
  38. addLock: true,
  39. addBackup: true,
  40. edit: false,
  41. editDesc: false,
  42. minWidth: 120,
  43. slotCallback: row => {
  44. return [
  45. <list-body-cell-wrap field='name' row={row} />,
  46. ]
  47. },
  48. }),
  49. getStatusTableColumn({
  50. statusModule: 'blockstorage',
  51. minWidth: 100,
  52. }),
  53. getEnabledTableColumn(),
  54. {
  55. field: 'capacity',
  56. title: this.$t('storage.text_177'),
  57. width: 180,
  58. slots: {
  59. default: ({ row }, h) => {
  60. const capacity = sizestr(row.capacity, 'M', 1024)
  61. const allowedBrands = ['VMware', 'OneCloud']
  62. const actual_capacity_used = allowedBrands.includes(row.brand) ? sizestr(row.actual_capacity_used, 'M', 1024) : '-'
  63. return [<div>
  64. <div>{this.$t('storage.text_178', [actual_capacity_used])}</div>
  65. <div>{this.$t('storage.text_180', [capacity])}</div>
  66. </div>]
  67. },
  68. },
  69. },
  70. {
  71. field: 'virtual_capacity',
  72. title: this.$t('storage.text_43'),
  73. width: 180,
  74. slots: {
  75. default: ({ row }, h) => {
  76. const virtual_capacity = sizestr(row.virtual_capacity, 'M', 1024)
  77. const used_capacity = sizestr(row.used_capacity, 'M', 1024)
  78. return [<div>
  79. <div>{this.$t('storage.text_181', [used_capacity])}</div>
  80. <div>{this.$t('storage.text_180', [virtual_capacity])}</div>
  81. </div>]
  82. },
  83. },
  84. },
  85. {
  86. field: 'storage_type',
  87. title: this.$t('storage.text_38'),
  88. width: 100,
  89. formatter: ({ row }) => {
  90. return STORAGE_TYPES[row.storage_type] || row.storage_type
  91. },
  92. },
  93. {
  94. field: 'medium_type',
  95. title: this.$t('storage.text_39'),
  96. width: 120,
  97. formatter: ({ row }) => {
  98. return MEDIUM_TYPES[row.medium_type] || row.medium_type
  99. },
  100. },
  101. getBrandTableColumn(),
  102. {
  103. field: 'schedtag',
  104. title: this.$t('storage.text_45'),
  105. width: 120,
  106. slots: {
  107. default: ({ row }) => {
  108. const tags = _.sortBy(row.schedtags, ['default', 'name'])
  109. if (!tags.length) {
  110. return [
  111. <div class='text-color-help'>{ this.$t('storage.text_171') }</div>,
  112. ]
  113. }
  114. const list = tags.map(tag => <a-tag class='mb-2 mr-1' color='blue'>{tag.name}</a-tag>)
  115. return [<list-body-cell-popover text={this.$t('compute.text_619', [tags.length])} max-width="400px">
  116. <div style="display: inline-flex; flex-wrap: wrap; max-width: 40vw;">
  117. {...list}
  118. </div>
  119. </list-body-cell-popover>]
  120. },
  121. },
  122. },
  123. getPublicScopeTableColumn({ vm: this, resource: 'storages' }),
  124. getProjectDomainTableColumn(),
  125. getRegionTableColumn(),
  126. getTimeTableColumn(),
  127. ],
  128. }
  129. },
  130. },
  131. methods: {},
  132. }