| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <template>
- <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="label" :required="isRequired">
- <a-row :gutter="8">
- <a-col :span="showIpConfig ? 8 : 12">
- <a-form-item
- :wrapperCol="{ span: 24 }"
- class="mb-0 mr-1">
- <base-select
- class="w-100"
- v-decorator="decorator.vpc"
- :resource="vpcResource"
- remote
- :label-format="vpcLabelFormat"
- :isDefaultSelect="true"
- :need-params="true"
- :params="vpcParmasConcat"
- :mapper="vpcResourceMapper"
- :item.sync="selectedVpc"
- :select-props="{ allowClear: true, placeholder: $t('compute.text_194') }" />
- </a-form-item>
- </a-col>
- <a-col :span="showIpConfig ? 8 : 12">
- <a-form-item
- :wrapperCol="{ span: 24 }"
- class="mb-0 mr-1">
- <base-select
- class="w-100"
- v-decorator="decorator.network"
- resource="networks"
- remote
- :need-params="true"
- :isDefaultSelect="true"
- :params="networkParamsConcat"
- :mapper="networkResourceMapper"
- :select-props="{ allowClear: true, placeholder: $t('compute.text_195') }" />
- <div slot="extra" v-if="helplink">
- {{helplink.ipSubnetHelp}}<help-link :href="helplink.ipSubnetHref">{{$t('network.text_26')}}</help-link>
- </div>
- </a-form-item>
- </a-col>
- <a-col :span="8" v-if="showIpConfig">
- <a-button v-if="!this.ipShow" type="link" class="mr-1 mt-1" @click="triggerShowIp">{{$t('compute.text_198')}}</a-button>
- <a-row v-else>
- <a-col :span="21">
- <a-form-item class="mb-0" :wrapperCol="{ span: 24 }">
- <a-input
- :placeholder="$t('compute.text_197')"
- v-decorator="decorator.ip_addr" />
- </a-form-item>
- </a-col>
- <a-col :span="3">
- <a-button type="link" class="mt-1" @click="triggerShowIp">{{$t('compute.text_135')}}</a-button>
- </a-col>
- </a-row>
- </a-col>
- </a-row>
- </a-form-item>
- </template>
- <script>
- import i18n from '@/locales'
- export default {
- name: 'IpSubnet',
- inject: ['form'],
- props: {
- labelCol: {
- type: Object,
- default: () => {
- return {
- span: 24,
- }
- },
- },
- wrapperCol: {
- type: Object,
- default: () => {
- return {
- span: 24,
- }
- },
- },
- label: {
- type: String,
- default: i18n.t('dictionary.region'),
- },
- isRequired: {
- type: Boolean,
- default: false,
- },
- decorator: {
- type: Object,
- required: true,
- },
- networkParams: {
- type: Object,
- },
- networkResourceMapper: {
- type: Function,
- default: (data) => { return data },
- },
- vpcParams: {
- type: Object,
- },
- vpcResource: {
- type: String,
- default: 'vpcs', // 还可能是这样的resource cloudregions/{region_id}/vpcs
- },
- vpcResourceMapper: {
- type: Function,
- default: data => { return data },
- },
- showIpConfig: {
- type: Boolean,
- default: true,
- },
- helplink: {
- type: Object,
- },
- },
- data () {
- return {
- ipShow: false,
- selectedVpc: {},
- }
- },
- computed: {
- vpcParmasConcat () {
- return {
- limit: 0,
- show_emulated: true,
- ...this.vpcParams,
- }
- },
- networkParamsConcat () {
- return {
- vpc: this.selectedVpc.id,
- usable: true,
- ...this.networkParams,
- }
- },
- },
- methods: {
- triggerShowIp () {
- this.ipShow = !this.ipShow
- },
- vpcLabelFormat (item) {
- if (!item.cidr_block) return item.name
- return `${item.name}(${item.cidr_block})`
- },
- },
- }
- </script>
|