AssociateVpcDialog.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{params.title}}</div>
  4. <div slot="body">
  5. <a-form
  6. class="mt-3"
  7. :form="form.fc"
  8. @submit.prevent="handleSubmit"
  9. v-bind="formItemLayout">
  10. <area-selects
  11. class="mb-0"
  12. ref="areaSelects"
  13. :wrapperCol="formItemLayout.wrapperCol"
  14. :labelCol="formItemLayout.labelCol"
  15. :names="areaselectsName"
  16. :cloudregionParams="cloudregionParams"
  17. :isRequired="true"
  18. filterBrandResource="network_manage"
  19. @change="handleRegionChange" />
  20. <a-form-item label="VPC" v-bind="formItemLayout">
  21. <base-select
  22. v-decorator="decorators.vpc"
  23. resource="vpcs"
  24. :params="vpcParams"
  25. :isDefaultSelect="true"
  26. :needParams="true"
  27. :labelFormat="vpcLabelFormat"
  28. :select-props="{ placeholder: $t('common_226') }" />
  29. </a-form-item>
  30. </a-form>
  31. </div>
  32. <div slot="footer">
  33. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  34. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  35. </div>
  36. </base-dialog>
  37. </template>
  38. <script>
  39. import { mapGetters } from 'vuex'
  40. import DialogMixin from '@/mixins/dialog'
  41. import WindowsMixin from '@/mixins/windows'
  42. import AreaSelects from '@/sections/AreaSelects'
  43. export default {
  44. name: 'AssociateVpcDialog',
  45. components: {
  46. AreaSelects,
  47. },
  48. mixins: [DialogMixin, WindowsMixin],
  49. provide () {
  50. return {
  51. form: this.form,
  52. }
  53. },
  54. data () {
  55. return {
  56. loading: false,
  57. form: {
  58. fc: this.$form.createForm(this),
  59. },
  60. decorators: {
  61. vpc: [
  62. 'vpc',
  63. {
  64. rules: [
  65. { required: true, message: this.$t('network.text_274') },
  66. ],
  67. },
  68. ],
  69. },
  70. areaselectsName: ['cloudregion'],
  71. regionId: '',
  72. associateVpcIds: [],
  73. formItemLayout: {
  74. wrapperCol: {
  75. md: { span: 18 },
  76. xl: { span: 20 },
  77. xxl: { span: 22 },
  78. },
  79. labelCol: {
  80. md: { span: 6 },
  81. xl: { span: 4 },
  82. xxl: { span: 2 },
  83. },
  84. },
  85. }
  86. },
  87. computed: {
  88. ...mapGetters(['isAdminMode', 'scope']),
  89. vpcParams () {
  90. const params = {
  91. limit: 0,
  92. usable_vpc: true,
  93. scope: this.scope,
  94. cloudregion_id: this.regionId,
  95. }
  96. if (this.params.data[0].manager_id) {
  97. params.manager_id = this.params.data[0].manager_id
  98. }
  99. if (this.isAdminMode) {
  100. params.project_domain = this.params.data[0].project_domain
  101. delete params.scope
  102. }
  103. if (!this.regionId) return {}
  104. return params
  105. },
  106. cloudregionParams () {
  107. return {
  108. scope: this.scope,
  109. limit: 0,
  110. usable_vpc: true,
  111. show_emulated: true,
  112. provider: this.params.data[0].provider,
  113. }
  114. },
  115. },
  116. methods: {
  117. async handleConfirm () {
  118. this.loading = true
  119. try {
  120. const ids = this.params.data.map(item => item.id)
  121. const { vpc } = await this.form.fc.validateFields()
  122. const vpcManager = new this.$Manager('dns_zones')
  123. await vpcManager.batchPerformAction({
  124. ids: ids,
  125. action: 'add-vpcs',
  126. data: {
  127. vpc_ids: [vpc],
  128. },
  129. })
  130. this.params.refresh && this.params.refresh()
  131. this.$bus.$emit('DnsZoneListSingleRefresh', [this.params.data[0].id])
  132. this.cancelDialog()
  133. } finally {
  134. this.loading = false
  135. }
  136. },
  137. handleRegionChange (data) {
  138. const { cloudregion } = data
  139. if (cloudregion) {
  140. this.regionId = cloudregion.id
  141. }
  142. },
  143. vpcLabelFormat (item) {
  144. if (item.manager) {
  145. if (item.cidr_block) {
  146. return <div><span class="text-color-secondary">VPC:</span> { item.name }<span>({ item.cidr_block })</span><span class="ml-2 text-color-secondary">{this.$t('common_711')}: { item.manager }</span></div>
  147. }
  148. return <div><span class="text-color-secondary">VPC:</span> { item.name }<span class="ml-2 text-color-secondary">{this.$t('common_711')}: { item.manager }</span></div>
  149. }
  150. return <div>{ item.name }</div>
  151. },
  152. },
  153. }
  154. </script>