Server.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <page-list
  3. show-tag-filter
  4. show-tag-columns
  5. :list="list"
  6. :columns="columns"
  7. :group-actions="groupActions"
  8. :single-actions="singleActions"
  9. :export-data-options="exportDataOptions" />
  10. </template>
  11. <script>
  12. import { mapGetters } from 'vuex'
  13. import ColumnMixin from '@Compute/views/vminstance/mixins/columns'
  14. import ListMixin from '@/mixins/list'
  15. import {
  16. getNameFilter,
  17. getBrandFilter,
  18. getStatusFilter,
  19. getTenantFilter,
  20. getAccountFilter,
  21. getIpFilter,
  22. getHostFilter,
  23. } from '@/utils/common/tableFilter'
  24. import expectStatus from '@/constants/expectStatus'
  25. import WindowsMixin from '@/mixins/windows'
  26. export default {
  27. name: 'ServerList',
  28. mixins: [WindowsMixin, ListMixin, ColumnMixin],
  29. props: {
  30. id: String,
  31. getParams: {
  32. type: Object,
  33. default: () => ({}),
  34. },
  35. cloudEnv: String,
  36. data: Object,
  37. },
  38. data () {
  39. return {
  40. hideColumnFields: ['is_gpu', 'instance_type', 'os_type', 'host', 'account'],
  41. list: this.$list.createList(this, {
  42. id: this.id,
  43. resource: 'servers',
  44. getParams: this.getParam,
  45. steadyStatus: Object.values(expectStatus.server).flat(),
  46. filterOptions: {
  47. name: getNameFilter(),
  48. brand: getBrandFilter('compute_engine_brands'),
  49. ips: getIpFilter(),
  50. status: getStatusFilter('server'),
  51. os_type: {
  52. label: this.$t('compute.text_721'),
  53. dropdown: true,
  54. multiple: true,
  55. items: [
  56. { label: 'Windows', key: 'windows' },
  57. { label: 'Linux', key: 'linux' },
  58. { label: 'VMware', key: 'VMWare' },
  59. ],
  60. filter: true,
  61. formatter: val => {
  62. return `os_type.in(${val})`
  63. },
  64. },
  65. tenant: getTenantFilter(),
  66. billing_type: {
  67. label: this.$t('compute.text_498'),
  68. dropdown: true,
  69. items: [
  70. { label: this.$t('compute.text_22'), key: 'postpaid' },
  71. { label: this.$t('compute.text_23'), key: 'prepaid' },
  72. ],
  73. },
  74. account: getAccountFilter(),
  75. host: getHostFilter(),
  76. gpu: {
  77. label: this.$t('compute.text_175'),
  78. dropdown: true,
  79. items: [
  80. { label: this.$t('compute.text_1033'), key: false },
  81. { label: this.$t('compute.text_1034'), key: true },
  82. ],
  83. },
  84. },
  85. responseData: this.responseData,
  86. }),
  87. singleActions: [
  88. {
  89. label: this.$t('compute.text_723'),
  90. permission: 'server_perform_assign_secgroup',
  91. action: (obj) => {
  92. this.createDialog('UnbindSecgroupDialog', {
  93. data: [obj],
  94. detailData: this.data,
  95. columns: this.columns,
  96. title: this.$t('compute.text_723'),
  97. onManager: this.onManager,
  98. refresh: this.refresh,
  99. })
  100. },
  101. meta: (obj) => {
  102. const ret = { validate: false, tooltip: null }
  103. if (obj.secgroups && obj.secgroups.length === 1) {
  104. ret.tooltip = this.$t('compute.text_1026')
  105. return ret
  106. }
  107. ret.validate = ['running', 'ready'].includes(obj.status)
  108. return ret
  109. },
  110. },
  111. ],
  112. groupActions: [
  113. {
  114. label: this.$t('compute.text_483', [this.$t('dictionary.server')]),
  115. permission: 'server_perform_assign_secgroup',
  116. action: () => {
  117. this.createDialog('SetServerDialog', {
  118. data: [this.data],
  119. columns: this.columns,
  120. title: this.$t('compute.text_483', [this.$t('dictionary.server')]),
  121. resourceName: this.$t('dictionary.server'),
  122. onManager: this.onManager,
  123. refresh: this.refresh,
  124. })
  125. },
  126. },
  127. {
  128. label: this.$t('compute.text_723'),
  129. permission: 'server_perform_assign_secgroup',
  130. action: () => {
  131. this.createDialog('UnbindSecgroupDialog', {
  132. data: this.list.selectedItems,
  133. detailData: this.data,
  134. columns: this.columns,
  135. title: this.$t('compute.text_723'),
  136. onManager: this.onManager,
  137. refresh: this.refresh,
  138. })
  139. },
  140. meta: () => {
  141. const ret = { validate: false, tooltip: null }
  142. const isSomeOneSecgroup = this.list.selectedItems.some((obj) => obj.secgroups && obj.secgroups.length === 1)
  143. if (isSomeOneSecgroup) {
  144. ret.tooltip = this.$t('compute.text_1037')
  145. return ret
  146. }
  147. ret.validate = this.list.selectedItems.length > 0 && this.list.selectedItems.every(item => ['running', 'ready'].includes(item.status))
  148. return ret
  149. },
  150. },
  151. ],
  152. }
  153. },
  154. computed: {
  155. ...mapGetters(['isAdminMode']),
  156. isSameHyper () {
  157. if (this.list.selectedItems.length > 0) {
  158. const arr = this.list.selectedItems.map(v => v.hypervisor)
  159. const noRepeatArr = Array.from(new Set(arr))
  160. return noRepeatArr.length === 1
  161. }
  162. return true
  163. },
  164. exportDataOptions () {
  165. return {
  166. title: this.$t('dictionary.server'),
  167. downloadType: 'local',
  168. items: this.columns,
  169. fixedItems: [
  170. { key: 'metadata.os_distribution', label: this.$t('table.title.os') },
  171. { key: 'disk', label: this.$t('table.title.disk') + '(M)' },
  172. { key: 'vmem_size', label: this.$t('table.title.vmem_size') + '(M)' },
  173. { key: 'eip', title: this.$t('common.eip') },
  174. { key: 'ips', title: 'IP' },
  175. { key: 'is_gpu', title: `${this.$t('table.title.type')}(${this.$t('compute.text_113')}${this.$t('dictionary.server')})` },
  176. ],
  177. hiddenFields: ['os_dist', 'elastic_ip', 'ip'],
  178. }
  179. },
  180. },
  181. watch: {
  182. cloudEnv (val) {
  183. this.$nextTick(() => {
  184. this.list.fetchData(0)
  185. })
  186. },
  187. },
  188. created () {
  189. this.initSidePageTab('vm-instance-detail')
  190. this.list.fetchData()
  191. this.$bus.$on('VMInstanceListSingleUpdate', args => {
  192. this.list.singleUpdate(...args)
  193. }, this)
  194. this.$bus.$on('VMInstanceListSingleRefresh', args => {
  195. this.list.singleRefresh(...args)
  196. }, this)
  197. },
  198. methods: {
  199. refresh () {
  200. this.list.refresh()
  201. this.$bus.$emit('secgroup-list-refresh')
  202. },
  203. getParam () {
  204. const ret = {
  205. details: true,
  206. with_meta: true,
  207. filter: 'hypervisor.notin(baremetal,container,pod)',
  208. ...this.getParams,
  209. }
  210. return ret
  211. },
  212. handleOpenSidepage (row) {
  213. this.sidePageTriggerHandle(this, 'VmInstanceSidePage', {
  214. id: row.id,
  215. resource: 'servers',
  216. getParams: this.getParam,
  217. steadyStatus: Object.values(expectStatus.server).flat(),
  218. }, {
  219. list: this.list,
  220. })
  221. },
  222. openVmSetDurationDialog (obj) {
  223. this.createDialog('VmSetDurationDialog', {
  224. data: [obj],
  225. columns: this.columns,
  226. onManager: this.onManager,
  227. refresh: this.refresh,
  228. })
  229. },
  230. },
  231. }
  232. </script>