columns.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { serverTypeMap } from '../constants'
  2. import {
  3. getRegionTableColumn,
  4. getBrandTableColumn,
  5. } from '@/utils/common/tableColumn'
  6. import i18n from '@/locales'
  7. import { BUY_DURATIONS_OPTIONS } from '@Compute/constants'
  8. const parseDuration = (s) => {
  9. const w = /(\d)+(W)/
  10. const m = /(\d)+(M)/
  11. const y = /(\d)+(Y)/
  12. let duration = 1
  13. if (m.exec(s)) {
  14. duration = parseInt(m.exec(s)[1])
  15. } else if (y.exec(s)) {
  16. duration = parseInt(y.exec(s)[1]) * 12
  17. } else if (w.exec(s)) {
  18. duration = parseInt(w.exec(s)[1]) * 7 / 30
  19. }
  20. return duration
  21. }
  22. const parseFee = (fee) => {
  23. const m = new RegExp(/(\D)(\d*\.?\d*)/).exec(fee)
  24. const currency = m && m[1] ? m[1] : ''
  25. const price = m && m[2] ? parseFloat(m[2]) : 0
  26. return [currency, price]
  27. }
  28. export default {
  29. created () {
  30. const columns = [
  31. {
  32. field: 'type',
  33. title: i18n.t('table.title.obj_type'),
  34. minWidth: 50,
  35. slots: {
  36. default: ({ row }) => {
  37. return serverTypeMap[row.type]
  38. },
  39. },
  40. },
  41. {
  42. field: 'config',
  43. title: i18n.t('table.title.flavor'),
  44. showOverflow: 'ellipsis',
  45. minWidth: 120,
  46. slots: {
  47. default: ({ row }) => {
  48. return row.config || '-'
  49. },
  50. },
  51. },
  52. {
  53. field: 'systemDisk',
  54. title: i18n.t('compute.text_49'),
  55. showOverflow: 'ellipsis',
  56. minWidth: 120,
  57. slots: {
  58. default: ({ row }) => {
  59. return row.systemDisk || '-'
  60. },
  61. },
  62. },
  63. {
  64. field: 'dataDisk',
  65. title: i18n.t('compute.text_50'),
  66. showOverflow: 'ellipsis',
  67. minWidth: 120,
  68. slots: {
  69. default: ({ row }) => {
  70. if (parseInt(row.dataDisk) === 0) return '-'
  71. return row.dataDisk
  72. },
  73. },
  74. },
  75. getBrandTableColumn(),
  76. getRegionTableColumn(),
  77. {
  78. field: 'billing_type',
  79. title: i18n.t('compute.text_498'),
  80. minWidth: 50,
  81. slots: {
  82. default: ({ row }, h) => {
  83. const ret = []
  84. if (row.billing_type === 'postpaid') {
  85. ret.push(<div style={{ color: '#0A1F44' }}>{i18n.t('billingType.postpaid')}</div>)
  86. } else if (row.billing_type === 'prepaid') {
  87. ret.push(<div style={{ color: '#0A1F44' }}>{i18n.t('billingType.prepaid')}</div>)
  88. }
  89. return ret
  90. },
  91. },
  92. },
  93. {
  94. field: 'count',
  95. title: i18n.t('cloudenv.buy_num'),
  96. minWidth: 50,
  97. slots: {
  98. default: ({ row }) => {
  99. return `${row.count}${this.$t('common_62')}`
  100. },
  101. },
  102. },
  103. {
  104. field: 'duration',
  105. title: i18n.t('compute.text_1230'),
  106. minWidth: 50,
  107. slots: {
  108. default: ({ row }) => {
  109. const curObj = BUY_DURATIONS_OPTIONS.find(v => v.value === row.duration)
  110. return curObj?.label || (row.duration === '1W' ? i18n.t('compute.text_24') : i18n.t('compute.text_139'))
  111. },
  112. },
  113. },
  114. {
  115. field: 'fee',
  116. title: i18n.t('common_419'),
  117. minWidth: 50,
  118. slots: {
  119. default: ({ row }, h) => {
  120. return [
  121. <div style={{ color: '#f5222d', fontSize: '14px' }}>{ row.fee }</div>,
  122. ]
  123. },
  124. },
  125. },
  126. {
  127. field: 'fee',
  128. title: i18n.t('cloudenv.month_expense'),
  129. minWidth: 50,
  130. slots: {
  131. default: ({ row }, h) => {
  132. const d = parseDuration(row.duration)
  133. const [c, p] = parseFee(row.fee)
  134. const fee = row.billing_type === 'postpaid' ? p * 24 * 30 : p / d
  135. return [
  136. <div style={{ color: '#f5222d', fontSize: '14px' }}>{ `${c}${fee.toFixed(2)}` }</div>,
  137. ]
  138. },
  139. },
  140. },
  141. {
  142. field: 'fee',
  143. title: i18n.t('cloudenv.year_expense'),
  144. minWidth: 50,
  145. slots: {
  146. default: ({ row }, h) => {
  147. const d = parseDuration(row.duration)
  148. const [c, p] = parseFee(row.fee)
  149. const fee = row.billing_type === 'postpaid' ? p * 24 * 30 * 12 : p * 12 / d
  150. return [
  151. <div style={{ color: '#f5222d', fontSize: '14px' }}>{ `${c}${fee.toFixed(2)}` }</div>,
  152. ]
  153. },
  154. },
  155. },
  156. ]
  157. if (this.hideColumnFields) {
  158. this.columns = columns.filter((column) => { return !this.hideColumnFields.includes(column.field) })
  159. } else {
  160. this.columns = columns
  161. }
  162. },
  163. }