Disk.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns" />
  5. </template>
  6. <script>
  7. import { ALL_STORAGE } from '@Compute/constants'
  8. import { getStatusTableColumn } from '@/utils/common/tableColumn'
  9. import { sizestr } from '@/utils/utils'
  10. import expectStatus from '@/constants/expectStatus'
  11. export default {
  12. name: 'DiskListForVmInstanceSidepage',
  13. props: {
  14. resId: String,
  15. data: {
  16. type: Object,
  17. required: true,
  18. },
  19. },
  20. data () {
  21. return {
  22. list: this.$list.createList(this, {
  23. resource: 'disks',
  24. ctx: [['servers', this.resId]],
  25. idKey: 'disk_id',
  26. steadyStatus: Object.values(expectStatus.disk).flat(),
  27. getParams: {
  28. order_by: 'index',
  29. order: 'asc',
  30. },
  31. }),
  32. columns: [
  33. {
  34. field: 'index',
  35. title: this.$t('compute.text_375'),
  36. width: 50,
  37. formatter: ({ row }) => {
  38. return row.index ? row.index : '0'
  39. },
  40. },
  41. {
  42. field: 'disk',
  43. title: this.$t('compute.text_376'),
  44. sortable: true,
  45. showOverflow: 'ellipsis',
  46. minWidth: 100,
  47. slots: {
  48. default: ({ row }, h) => {
  49. const ret = [
  50. <list-body-cell-wrap copy row={row} hideField={ true }>
  51. <side-page-trigger onTrigger={ () => this.handleOpenDiskDetail(row.disk_id) }>{ row.disk }</side-page-trigger>
  52. </list-body-cell-wrap>,
  53. ]
  54. return ret
  55. },
  56. },
  57. },
  58. {
  59. field: 'disk_size',
  60. title: this.$t('compute.text_377'),
  61. sortable: true,
  62. showOverflow: 'ellipsis',
  63. minWidth: 60,
  64. formatter: ({ row }) => {
  65. return sizestr(row.disk_size, 'M', 1024)
  66. },
  67. },
  68. {
  69. field: 'driver',
  70. title: this.$t('compute.text_378'),
  71. width: 80,
  72. },
  73. {
  74. field: 'cache_mode',
  75. title: this.$t('compute.text_379'),
  76. width: 150,
  77. formatter: ({ row }) => {
  78. return row.cache_mode ? row.cache_mode : '-'
  79. },
  80. },
  81. getStatusTableColumn({ statusModule: 'disk' }),
  82. {
  83. field: 'storage_type',
  84. title: this.$t('compute.text_380'),
  85. width: 80,
  86. formatter: ({ row }) => {
  87. if (row.storage_type) {
  88. if (row.storage_type === 'baremetal') return this.$t('compute.text_92')
  89. return (ALL_STORAGE[row.storage_type] && ALL_STORAGE[row.storage_type].label) || row.storage_type
  90. }
  91. return '-'
  92. },
  93. },
  94. {
  95. field: 'disk_type',
  96. title: this.$t('compute.text_381'),
  97. width: 80,
  98. formatter: ({ row }) => {
  99. const diskType = {
  100. sys: this.$t('compute.text_49'),
  101. data: this.$t('compute.text_50'),
  102. }
  103. if (row.disk_type) {
  104. return diskType[row.disk_type] || row.disk_type
  105. }
  106. return '-'
  107. },
  108. },
  109. ],
  110. }
  111. },
  112. created () {
  113. this.list.fetchData()
  114. },
  115. methods: {
  116. handleOpenDiskDetail (id) {
  117. this.initSidePageTab('disk-detail')
  118. this.sidePageTriggerHandle(this, 'DiskSidePage', {
  119. id,
  120. resource: 'disks',
  121. steadyStatus: {
  122. status: Object.values(expectStatus.disk).flat(),
  123. guest_status: [...Object.values(expectStatus.server).flat(), '', undefined],
  124. },
  125. })
  126. },
  127. },
  128. }
  129. </script>