BindEip.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_1179')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.instancegroup')" :count="params.data.length" :action="$t('compute.text_1179')" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" hideRequiredMark>
  8. <eip-config
  9. hidden-none-type
  10. :decorators="decorators.eipConfig"
  11. :eip-params="eipParams"
  12. :hypervisor="hypervisor"
  13. :cloud-env="params.data[0].cloud_env"
  14. :form="form"
  15. :formItemLayout="formItemLayout" />
  16. </a-form>
  17. </div>
  18. <div slot="footer">
  19. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  20. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  21. </div>
  22. </base-dialog>
  23. </template>
  24. <script>
  25. import EipConfig from '@Compute/sections/EipConfig'
  26. import { SERVER_TYPE } from '@Compute/constants'
  27. import DialogMixin from '@/mixins/dialog'
  28. import WindowsMixin from '@/mixins/windows'
  29. import { findPlatform } from '@/utils/common/hypervisor'
  30. export default {
  31. name: 'InstanceGroupBindEipDialog',
  32. components: {
  33. EipConfig,
  34. },
  35. mixins: [DialogMixin, WindowsMixin],
  36. data () {
  37. let typeInitialValue = 'new'
  38. const hypervisor = this.params.data[0].hypervisor
  39. if (findPlatform(hypervisor) === SERVER_TYPE.private) {
  40. typeInitialValue = 'bind'
  41. }
  42. return {
  43. loading: false,
  44. form: {
  45. fc: this.$form.createForm(this),
  46. },
  47. decorators: {
  48. eipConfig: {
  49. type: [
  50. 'type',
  51. {
  52. initialValue: typeInitialValue,
  53. },
  54. ],
  55. charge_type: [
  56. 'charge_type',
  57. {
  58. initialValue: (this.params.data[0].hypervisor == null || this.params.data[0].hypervisor === 'kvm') ? 'bandwidth' : 'traffic',
  59. },
  60. ],
  61. bgp_type: [
  62. 'bgp_type',
  63. {
  64. initialValue: '',
  65. },
  66. ],
  67. bandwidth: [
  68. 'bandwidth',
  69. {
  70. initialValue: 30,
  71. validateFirst: true,
  72. },
  73. ],
  74. eip: [
  75. 'eip',
  76. {
  77. rules: [
  78. { required: true, message: this.$t('compute.text_145'), trigger: 'change' },
  79. ],
  80. },
  81. ],
  82. },
  83. },
  84. formItemLayout: {
  85. wrapperCol: {
  86. span: 20,
  87. },
  88. labelCol: {
  89. span: 4,
  90. },
  91. },
  92. }
  93. },
  94. computed: {
  95. hypervisor () {
  96. return this.params.data[0].hypervisor
  97. },
  98. isPublic () {
  99. return findPlatform(this.hypervisor) === 'public'
  100. },
  101. eipParams () {
  102. return {
  103. usable_eip_for_associate_type: 'instancegroup',
  104. usable_eip_for_associate_id: this.params.data[0].id,
  105. scope: this.$store.getters.scope,
  106. }
  107. },
  108. columns () {
  109. const fields = ['name', 'metadata', 'ip']
  110. return this.params.columns.filter(item => {
  111. const { field } = item
  112. return fields.indexOf(field) > -1
  113. })
  114. },
  115. },
  116. methods: {
  117. doCreateEip (ids, values) {
  118. return this.params.onManager('batchPerformAction', {
  119. id: ids,
  120. managerArgs: {
  121. action: 'create-eip',
  122. steadyStatus: ['init'],
  123. data: {
  124. charge_type: values.charge_type,
  125. bandwidth: values.bandwidth,
  126. bgp_type: values.bgp_type,
  127. },
  128. },
  129. })
  130. },
  131. doBindEip (ids, values) {
  132. return this.params.onManager('batchPerformAction', {
  133. id: ids,
  134. managerArgs: {
  135. action: 'associate-eip',
  136. steadyStatus: ['init'],
  137. data: {
  138. eip: values.eip,
  139. },
  140. },
  141. })
  142. },
  143. async handleConfirm () {
  144. this.loading = true
  145. try {
  146. const values = await this.form.fc.validateFields()
  147. const ids = this.params.data.map(item => item.id)
  148. if (values.type === 'new') {
  149. await this.doCreateEip(ids, values)
  150. }
  151. if (values.type === 'bind') {
  152. await this.doBindEip(ids, values)
  153. }
  154. this.$bus.$emit('InstanceGroupListRefresh', ids)
  155. this.cancelDialog()
  156. } finally {
  157. this.loading = false
  158. }
  159. },
  160. },
  161. }
  162. </script>