Detail.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <detail
  3. :on-manager="onManager"
  4. resource="servertemplates"
  5. status-module="servertemplate"
  6. :data="data"
  7. :base-info="baseInfo"
  8. :extra-info="extraInfo" />
  9. </template>
  10. <script>
  11. import * as R from 'ramda'
  12. import { LOGIN_TYPES_MAP } from '@Compute/constants'
  13. import { STORAGE_TYPES } from '@/constants/compute'
  14. // import { HYPERVISORS_MAP } from '@/constants'
  15. import { sizestrWithUnit } from '@/utils/utils'
  16. import {
  17. getBrandTableColumn,
  18. getBillingTypeTableColumn,
  19. getCopyWithContentTableColumn,
  20. getTagTableColumn,
  21. getOsArch,
  22. } from '@/utils/common/tableColumn'
  23. import WindowsMixin from '@/mixins/windows'
  24. export default {
  25. name: 'ServertemplateDetail',
  26. mixins: [WindowsMixin],
  27. props: {
  28. data: {
  29. type: Object,
  30. required: true,
  31. },
  32. onManager: {
  33. type: Function,
  34. required: true,
  35. },
  36. },
  37. data () {
  38. const getDiskObj = (row, type) => {
  39. const { disks } = row.config_info
  40. const { hypervisor } = row.content
  41. const diskList = disks.filter(val => val.disk_type === type)
  42. if (!diskList.length) return ''
  43. const diskObj = STORAGE_TYPES[hypervisor][diskList[0].backend]
  44. const diskType = diskObj ? `(${diskObj.label})` : ''
  45. const size = diskList.reduce((a, b) => a.size_mb + b.size_mb, { size_mb: 0 })
  46. return `${sizestrWithUnit(size, 'M', 1024)}${diskType}`
  47. }
  48. return {
  49. baseInfo: [
  50. {
  51. field: 'keypair',
  52. title: this.$t('compute.text_33'),
  53. formatter: ({ row }) => {
  54. return row.config_info.keypair || '-'
  55. },
  56. },
  57. getBrandTableColumn(),
  58. getBillingTypeTableColumn(),
  59. ],
  60. extraInfo: [
  61. {
  62. title: this.$t('compute.text_368'),
  63. items: [
  64. getOsArch({ field: 'content.os_arch' }),
  65. {
  66. field: 'os_type',
  67. title: this.$t('compute.text_267'),
  68. },
  69. getCopyWithContentTableColumn({
  70. field: 'image',
  71. title: this.$t('compute.text_97'),
  72. hideField: true,
  73. slotCallback: row => {
  74. if (!row.config_info || !row.config_info.image) return '-'
  75. return row.config_info.image
  76. // return [
  77. // <side-page-trigger permission='images_get' name='SystemImageSidePage' id={this.diskInfos.imageId} vm={this}>{ row.config_info.image }</side-page-trigger>,
  78. // ]
  79. },
  80. }),
  81. getCopyWithContentTableColumn({
  82. field: 'vpc',
  83. title: 'VPC',
  84. hideField: true,
  85. slotCallback: row => {
  86. if (!row.vpc) return '-'
  87. return [
  88. <side-page-trigger permission='vpcs_get' name='VpcSidePage' id={row.vpc_id} vm={this}>{ row.vpc }</side-page-trigger>,
  89. ]
  90. },
  91. }),
  92. {
  93. field: 'config_info.network',
  94. title: this.$t('compute.text_106'),
  95. slots: {
  96. default: ({ row }) => {
  97. if (row.config_info.nets && row.config_info.nets.length) {
  98. const _ = row.config_info.nets.map(net => {
  99. if (net.guest_ip_start) {
  100. return <div><a-tag>{ `${net.name}(${net.guest_ip_start} - ${net.guest_ip_end}, vlan=${net.vlan_id})` }</a-tag></div>
  101. }
  102. return net.network || net.id
  103. }).filter(v => !!v)
  104. return _.length > 0 ? _ : this.$t('common_563')
  105. }
  106. return this.$t('common_563')
  107. },
  108. },
  109. },
  110. {
  111. field: 'config_info.secgroup',
  112. title: this.$t('compute.text_105'),
  113. formatter: ({ row }) => {
  114. if (row.secgroups && row.secgroups.length > 0) {
  115. return row.secgroups.map(item => <a-tag>{item}</a-tag>)
  116. }
  117. return '-'
  118. },
  119. },
  120. {
  121. field: 'config_info.sys',
  122. title: this.$t('compute.text_49'),
  123. formatter: ({ row }) => {
  124. return getDiskObj(row, 'sys')
  125. },
  126. },
  127. {
  128. field: 'config_info.disk',
  129. title: this.$t('compute.text_50'),
  130. formatter: ({ row }) => {
  131. return getDiskObj(row, 'data')
  132. },
  133. },
  134. {
  135. field: 'config_info.cpu_core_count',
  136. title: 'CPU',
  137. formatter: ({ row }) => {
  138. const { sku } = row.config_info
  139. if (R.is(Object, sku)) {
  140. return this.$t('compute.text_120', [sku.cpu_core_count || 0])
  141. }
  142. return '-'
  143. },
  144. },
  145. {
  146. field: 'config_info.memory_size_mb',
  147. title: this.$t('compute.text_369'),
  148. formatter: ({ row }) => {
  149. const { sku } = row.config_info
  150. if (R.is(Object, sku)) {
  151. return sizestrWithUnit(sku.memory_size_mb, 'M', 1024)
  152. }
  153. return '-'
  154. },
  155. },
  156. {
  157. field: 'config_info.isolated_device_config',
  158. title: 'GPU',
  159. formatter: ({ row }) => {
  160. const gpu = row.isolated_device_config
  161. if (R.is(Object, gpu)) {
  162. return `${gpu.vendor}/${gpu.model}`
  163. }
  164. return '-'
  165. },
  166. },
  167. {
  168. field: 'config_info.gcounts',
  169. title: this.$t('compute.text_1049'),
  170. formatter: ({ row }) => {
  171. return this.$t('compute.text_1050', [row.config_info.gcounts || 0])
  172. },
  173. },
  174. // {
  175. // field: 'config_info.spec',
  176. // title: '规格',
  177. // formatter: ({ row }) => {
  178. // const { hypervisor, sku } = row.config_info
  179. // if (R.is(String, sku)) return sku
  180. // const category = this.getI18NValue(`skuCategoryOptions['${hypervisor}']['${sku.instance_type_category}']`, sku.instance_type_category)
  181. // return `${sku.name} (${category} ${sku.cpu_core_count}核 ${sizestrWithUnit(sku.memory_size_mb, 'M', 1024)})`
  182. // },
  183. // },
  184. {
  185. field: 'config_info.reset_password',
  186. title: this.$t('compute.text_308'),
  187. formatter: ({ row }) => {
  188. if (row.config_info.reset_password === true) {
  189. return LOGIN_TYPES_MAP.random.label
  190. }
  191. if (row.config_info.reset_password === false) {
  192. return LOGIN_TYPES_MAP.image.label
  193. }
  194. return '-'
  195. },
  196. },
  197. getTagTableColumn({ field: 'config_info.metadata', resource: 'servertemplates', tipName: this.$t('dictionary.servertemplate') }),
  198. ],
  199. },
  200. ],
  201. }
  202. },
  203. methods: {
  204. getI18NValue (key, originVal) {
  205. if (this.$t(key)) {
  206. return this.$t(key)
  207. }
  208. return originVal
  209. },
  210. },
  211. }
  212. </script>