VmContainer.vue 6.6 KB

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