| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <template>
- <base-dialog @cancel="cancelDialog">
- <div slot="header">{{params.title}}</div>
- <div slot="body">
- <a-form
- class="mt-3"
- :form="form.fc"
- @submit.prevent="handleSubmit"
- v-bind="formItemLayout">
- <area-selects
- class="mb-0"
- ref="areaSelects"
- :wrapperCol="formItemLayout.wrapperCol"
- :labelCol="formItemLayout.labelCol"
- :names="areaselectsName"
- :cloudregionParams="cloudregionParams"
- :isRequired="true"
- filterBrandResource="network_manage"
- @change="handleRegionChange" />
- <a-form-item label="VPC" v-bind="formItemLayout">
- <base-select
- v-decorator="decorators.vpc"
- resource="vpcs"
- :params="vpcParams"
- :isDefaultSelect="true"
- :needParams="true"
- :labelFormat="vpcLabelFormat"
- :select-props="{ placeholder: $t('common_226') }" />
- </a-form-item>
- </a-form>
- </div>
- <div slot="footer">
- <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
- <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
- </div>
- </base-dialog>
- </template>
- <script>
- import { mapGetters } from 'vuex'
- import DialogMixin from '@/mixins/dialog'
- import WindowsMixin from '@/mixins/windows'
- import AreaSelects from '@/sections/AreaSelects'
- export default {
- name: 'AssociateVpcDialog',
- components: {
- AreaSelects,
- },
- mixins: [DialogMixin, WindowsMixin],
- provide () {
- return {
- form: this.form,
- }
- },
- data () {
- return {
- loading: false,
- form: {
- fc: this.$form.createForm(this),
- },
- decorators: {
- vpc: [
- 'vpc',
- {
- rules: [
- { required: true, message: this.$t('network.text_274') },
- ],
- },
- ],
- },
- areaselectsName: ['cloudregion'],
- regionId: '',
- associateVpcIds: [],
- formItemLayout: {
- wrapperCol: {
- md: { span: 18 },
- xl: { span: 20 },
- xxl: { span: 22 },
- },
- labelCol: {
- md: { span: 6 },
- xl: { span: 4 },
- xxl: { span: 2 },
- },
- },
- }
- },
- computed: {
- ...mapGetters(['isAdminMode', 'scope']),
- vpcParams () {
- const params = {
- limit: 0,
- usable_vpc: true,
- scope: this.scope,
- cloudregion_id: this.regionId,
- }
- if (this.params.data[0].manager_id) {
- params.manager_id = this.params.data[0].manager_id
- }
- if (this.isAdminMode) {
- params.project_domain = this.params.data[0].project_domain
- delete params.scope
- }
- if (!this.regionId) return {}
- return params
- },
- cloudregionParams () {
- return {
- scope: this.scope,
- limit: 0,
- usable_vpc: true,
- show_emulated: true,
- provider: this.params.data[0].provider,
- }
- },
- },
- methods: {
- async handleConfirm () {
- this.loading = true
- try {
- const ids = this.params.data.map(item => item.id)
- const { vpc } = await this.form.fc.validateFields()
- const vpcManager = new this.$Manager('dns_zones')
- await vpcManager.batchPerformAction({
- ids: ids,
- action: 'add-vpcs',
- data: {
- vpc_ids: [vpc],
- },
- })
- this.params.refresh && this.params.refresh()
- this.$bus.$emit('DnsZoneListSingleRefresh', [this.params.data[0].id])
- this.cancelDialog()
- } finally {
- this.loading = false
- }
- },
- handleRegionChange (data) {
- const { cloudregion } = data
- if (cloudregion) {
- this.regionId = cloudregion.id
- }
- },
- vpcLabelFormat (item) {
- if (item.manager) {
- if (item.cidr_block) {
- 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>
- }
- 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>
- }
- return <div>{ item.name }</div>
- },
- },
- }
- </script>
|