resourceProps.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import {
  2. getNameDescriptionTableColumn,
  3. getStatusTableColumn,
  4. } from '@/utils/common/tableColumn'
  5. import {
  6. getNameFilter,
  7. } from '@/utils/common/tableFilter'
  8. import { sizestr, percentstr } from '@/utils/utils'
  9. export default {
  10. computed: {
  11. resourceProps () {
  12. return {
  13. list: this.$list.createList(this, {
  14. id: 'VmHostsListForTransferDialog',
  15. resource: 'hosts',
  16. getParams: {
  17. ...this.hostsParams,
  18. },
  19. filterOptions: {
  20. id: {
  21. label: this.$t('table.title.id'),
  22. },
  23. name: getNameFilter(),
  24. any_ip: {
  25. label: 'IP',
  26. },
  27. },
  28. // fetchDataCb: this.fetchDataCb,
  29. }),
  30. columns: [
  31. getNameDescriptionTableColumn({
  32. hideField: true,
  33. addLock: true,
  34. addBackup: true,
  35. edit: false,
  36. editDesc: false,
  37. minWidth: 120,
  38. slotCallback: row => {
  39. return [
  40. <list-body-cell-wrap field='name' row={row} />,
  41. ]
  42. },
  43. }),
  44. getStatusTableColumn({
  45. statusModule: 'host',
  46. minWidth: 100,
  47. }),
  48. {
  49. field: 'custom_ip',
  50. title: 'IP',
  51. minWidth: 200,
  52. showOverflow: 'ellipsis',
  53. slots: {
  54. default: ({ row }) => {
  55. const cellWrap = []
  56. if (row.access_ip) {
  57. if (row.ipmi_ip) {
  58. cellWrap.push(
  59. <div class="d-flex">
  60. <list-body-cell-wrap row={row} field="access_ip" copy><span class="text-color-help">{this.$t('compute.text_1319')}</span></list-body-cell-wrap>
  61. </div>,
  62. )
  63. } else {
  64. cellWrap.push(
  65. <div class="d-flex">
  66. <list-body-cell-wrap row={row} field="access_ip" copy></list-body-cell-wrap>
  67. </div>,
  68. )
  69. }
  70. }
  71. if (row.ipmi_ip) {
  72. if (row.access_ip) {
  73. cellWrap.push(
  74. <div class="d-flex">
  75. <list-body-cell-wrap row={row} field="ipmi_ip" copy><span class="text-color-help">{this.$t('compute.text_1320')}</span></list-body-cell-wrap>
  76. </div>,
  77. )
  78. } else {
  79. cellWrap.push(
  80. <div class="d-flex">
  81. <list-body-cell-wrap row={row} field="ipmi_ip" copy></list-body-cell-wrap>
  82. </div>,
  83. )
  84. }
  85. }
  86. return cellWrap
  87. },
  88. },
  89. },
  90. {
  91. field: 'cpu_count',
  92. title: this.$t('compute.text_563'),
  93. minWidth: 100,
  94. showOverflow: 'title',
  95. sortFields: ['cpu_count', ''],
  96. sortByList: ['', 'order_by_cpu_commit_rate'],
  97. slots: {
  98. default: ({ row }) => {
  99. if (row.cpu_commit_rate === undefined) return [<data-loading />]
  100. return row.cpu_count ? `${row.cpu_count}/${percentstr(row.cpu_commit_rate)}` : 'N/A'
  101. },
  102. },
  103. },
  104. {
  105. field: 'mem_size',
  106. title: this.$t('compute.text_564'),
  107. minWidth: 100,
  108. sortFields: ['mem_size', ''],
  109. sortByList: ['', 'order_by_mem_commit_rate'],
  110. slots: {
  111. default: ({ row }) => {
  112. if (row.mem_commit_rate === undefined) return [<data-loading />]
  113. return row.mem_size ? `${sizestr(row.mem_size, 'M', 1024)}/${percentstr(row.mem_commit_rate)}` : 'N/A'
  114. },
  115. },
  116. },
  117. {
  118. field: 'storage',
  119. title: this.$t('compute.text_565'),
  120. minWidth: 80,
  121. sortByList: ['order_by_storage', 'order_by_storage_commit_rate'],
  122. slots: {
  123. default: ({ row }) => {
  124. if (row.storage === undefined) return [<data-loading />]
  125. return row.storage ? `${sizestr(row.storage, 'M', 1024)}/${percentstr(row.storage_commit_rate)}` : 'N/A'
  126. },
  127. },
  128. },
  129. {
  130. field: 'model',
  131. title: this.$t('compute.text_580'),
  132. minWidth: 100,
  133. formatter: ({ cellValue, row }) => {
  134. return ((row.sys_info || {}).model) || '-'
  135. },
  136. },
  137. {
  138. field: 'nonsystem_guests',
  139. sortBy: 'order_by_server_count',
  140. title: '#VM',
  141. minWidth: 80,
  142. sortable: true,
  143. slots: {
  144. default: ({ row }, h) => {
  145. if (row.nonsystem_guests === undefined) return [<data-loading />]
  146. return `${row.nonsystem_guests}`
  147. },
  148. },
  149. },
  150. ],
  151. }
  152. },
  153. },
  154. methods: {
  155. fetchDataCb () {
  156. const { total, data } = this.resourceProps.list
  157. if (total > 0) {
  158. const hostIds = this.forcastData?.filtered_candidates?.map(v => v.id) || []
  159. if (this.forcastData?.can_create === false) {
  160. this.resourceProps.list.data = []
  161. }
  162. for (const key in data) {
  163. const obj = data[key].data
  164. if (hostIds.includes(obj.id)) {
  165. delete data[obj.id]
  166. --this.resourceProps.list.total
  167. }
  168. }
  169. }
  170. },
  171. },
  172. }