ServerList.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :showSearchbox="showSearchbox"
  8. :showGroupActions="showGroupActions" />
  9. </template>
  10. <script>
  11. import { SERVER_TYPE } from '@Compute/constants'
  12. import PasswordFetcher from '@Compute/sections/PasswordFetcher'
  13. import { getNameDescriptionTableColumn, getTimeTableColumn, getStatusTableColumn, getIpsTableColumn, getCopyWithContentTableColumn } from '@/utils/common/tableColumn'
  14. import { getStatusFilter, getEnabledFilter, getHostFilter } from '@/utils/common/tableFilter'
  15. import expectStatus from '@/constants/expectStatus'
  16. import { sizestr } from '@/utils/utils'
  17. import WindowsMixin from '@/mixins/windows'
  18. import GlobalSearchMixin from '@/mixins/globalSearch'
  19. import SystemIcon from '@/sections/SystemIcon'
  20. import ListMixin from '@/mixins/list'
  21. import { findPlatform } from '@/utils/common/hypervisor'
  22. export default {
  23. name: 'ScalingGroupServerListSidePage',
  24. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin],
  25. props: {
  26. id: String,
  27. getParams: {
  28. type: [Function, Object],
  29. },
  30. data: {
  31. type: Object,
  32. },
  33. },
  34. data () {
  35. return {
  36. list: this.$list.createList(this, {
  37. id: 'ServerListForScalingGroupSidePage',
  38. key: 'id',
  39. resource: 'servers',
  40. getParams: this.getParams,
  41. steadyStatus: Object.values(expectStatus.scalingserver).flat().concat(Object.values(expectStatus.server).flat()),
  42. filterOptions: {
  43. name: {
  44. label: this.$t('compute.text_228'),
  45. filter: true,
  46. formatter: val => {
  47. return `name.contains("${val}")`
  48. },
  49. },
  50. status: getStatusFilter('server'),
  51. enabled: getEnabledFilter(),
  52. host: getHostFilter(),
  53. },
  54. }),
  55. columns: [
  56. getNameDescriptionTableColumn({
  57. onManager: this.onManager,
  58. hideField: true,
  59. addLock: true,
  60. addBackup: true,
  61. formRules: [
  62. { required: true, message: this.$t('compute.text_210') },
  63. { validator: this.$validate('serverCreateName') },
  64. ],
  65. slotCallback: row => {
  66. return (
  67. <side-page-trigger permission="server_get" name="VmInstanceSidePage" id={row.id} vm={this}>{ row.name }</side-page-trigger>
  68. )
  69. },
  70. }),
  71. getIpsTableColumn({ field: 'ip', title: 'IP' }),
  72. {
  73. field: 'os_type',
  74. title: this.$t('table.title.os'),
  75. width: 50,
  76. slots: {
  77. default: ({ row }) => {
  78. let name = (row.metadata && row.metadata.os_distribution) ? row.metadata.os_distribution : row.os_type || ''
  79. if (name.includes('Windows') || name.includes('windows')) {
  80. name = 'Windows'
  81. }
  82. const version = (row.metadata && row.metadata.os_version) ? `${row.metadata.os_version}` : ''
  83. const tooltip = (version.includes(name) ? version : `${name} ${version}`) || this.$t('compute.text_339') // 去重
  84. return [
  85. <SystemIcon tooltip={ tooltip } name={ name } />,
  86. ]
  87. },
  88. },
  89. },
  90. {
  91. field: 'password',
  92. title: this.$t('compute.text_340'),
  93. width: 50,
  94. slots: {
  95. default: ({ row }) => {
  96. return [<PasswordFetcher serverId={ row.id } resourceType='servers' />]
  97. },
  98. },
  99. },
  100. getStatusTableColumn({ field: 'scaling_status', title: this.$t('compute.text_268'), statusModule: 'scalingserver' }),
  101. getStatusTableColumn({ title: this.$t('compute.text_973'), statusModule: 'server', width: 130 }),
  102. {
  103. field: 'instance_type',
  104. title: this.$t('compute.text_295'),
  105. showOverflow: 'ellipsis',
  106. minWidth: 120,
  107. sortable: true,
  108. slots: {
  109. default: ({ row }) => {
  110. const ret = []
  111. if (row.instance_type) {
  112. ret.push(<div class='text-truncate' style={{ color: '#0A1F44' }}>{ row.instance_type }</div>)
  113. }
  114. const config = row.vcpu_count + 'C' + sizestr(row.vmem_size, 'M', 1024) + (row.disk ? sizestr(row.disk, 'M', 1024) : '')
  115. return ret.concat(<div class='text-truncate' style={{ color: '#53627C' }}>{ config }</div>)
  116. },
  117. },
  118. },
  119. getTimeTableColumn(),
  120. {
  121. field: 'host',
  122. title: this.$t('compute.text_111'),
  123. sortable: true,
  124. showOverflow: 'ellipsis',
  125. minWidth: 100,
  126. slots: {
  127. default: ({ row }) => {
  128. if (findPlatform(row.hypervisor, 'hypervisor') === SERVER_TYPE.public) {
  129. return '-'
  130. }
  131. const text = row.host || '-'
  132. return text
  133. },
  134. },
  135. },
  136. getCopyWithContentTableColumn({ field: 'account', title: this.$t('compute.text_269') }),
  137. ],
  138. singleActions: [
  139. {
  140. label: this.$t('compute.text_950'),
  141. permission: 'server_perform_detach_scaling_group',
  142. action: (row) => {
  143. this.createDialog('ScalingGroupServerRemoveDialog', {
  144. title: this.$t('compute.text_950'),
  145. data: [row],
  146. resId: this.data.id,
  147. columns: this.columns,
  148. refresh: this.refresh,
  149. onManager: this.onManager,
  150. })
  151. },
  152. },
  153. ],
  154. groupActions: [
  155. {
  156. label: this.$t('compute.text_950'),
  157. permission: 'server_perform_detach_scaling_group',
  158. action: (row) => {
  159. this.createDialog('ScalingGroupServerRemoveDialog', {
  160. title: this.$t('compute.text_950'),
  161. data: this.list.selectedItems,
  162. resId: this.data.id,
  163. columns: this.columns,
  164. refresh: this.refresh,
  165. onManager: this.onManager,
  166. })
  167. },
  168. meta: (row) => {
  169. return {
  170. validate: !!this.list.selectedItems.length,
  171. }
  172. },
  173. },
  174. ],
  175. }
  176. },
  177. created () {
  178. this.list.fetchData()
  179. },
  180. }
  181. </script>