index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="label" :required="isRequired">
  3. <a-row :gutter="8">
  4. <a-col :span="showIpConfig ? 8 : 12">
  5. <a-form-item
  6. :wrapperCol="{ span: 24 }"
  7. class="mb-0 mr-1">
  8. <base-select
  9. class="w-100"
  10. v-decorator="decorator.vpc"
  11. :resource="vpcResource"
  12. remote
  13. :label-format="vpcLabelFormat"
  14. :isDefaultSelect="true"
  15. :need-params="true"
  16. :params="vpcParmasConcat"
  17. :mapper="vpcResourceMapper"
  18. :item.sync="selectedVpc"
  19. :select-props="{ allowClear: true, placeholder: $t('compute.text_194') }" />
  20. </a-form-item>
  21. </a-col>
  22. <a-col :span="showIpConfig ? 8 : 12">
  23. <a-form-item
  24. :wrapperCol="{ span: 24 }"
  25. class="mb-0 mr-1">
  26. <base-select
  27. class="w-100"
  28. v-decorator="decorator.network"
  29. resource="networks"
  30. remote
  31. :need-params="true"
  32. :isDefaultSelect="true"
  33. :params="networkParamsConcat"
  34. :mapper="networkResourceMapper"
  35. :select-props="{ allowClear: true, placeholder: $t('compute.text_195') }" />
  36. <div slot="extra" v-if="helplink">
  37. {{helplink.ipSubnetHelp}}<help-link :href="helplink.ipSubnetHref">{{$t('network.text_26')}}</help-link>
  38. </div>
  39. </a-form-item>
  40. </a-col>
  41. <a-col :span="8" v-if="showIpConfig">
  42. <a-button v-if="!this.ipShow" type="link" class="mr-1 mt-1" @click="triggerShowIp">{{$t('compute.text_198')}}</a-button>
  43. <a-row v-else>
  44. <a-col :span="21">
  45. <a-form-item class="mb-0" :wrapperCol="{ span: 24 }">
  46. <a-input
  47. :placeholder="$t('compute.text_197')"
  48. v-decorator="decorator.ip_addr" />
  49. </a-form-item>
  50. </a-col>
  51. <a-col :span="3">
  52. <a-button type="link" class="mt-1" @click="triggerShowIp">{{$t('compute.text_135')}}</a-button>
  53. </a-col>
  54. </a-row>
  55. </a-col>
  56. </a-row>
  57. </a-form-item>
  58. </template>
  59. <script>
  60. import i18n from '@/locales'
  61. export default {
  62. name: 'IpSubnet',
  63. inject: ['form'],
  64. props: {
  65. labelCol: {
  66. type: Object,
  67. default: () => {
  68. return {
  69. span: 24,
  70. }
  71. },
  72. },
  73. wrapperCol: {
  74. type: Object,
  75. default: () => {
  76. return {
  77. span: 24,
  78. }
  79. },
  80. },
  81. label: {
  82. type: String,
  83. default: i18n.t('dictionary.region'),
  84. },
  85. isRequired: {
  86. type: Boolean,
  87. default: false,
  88. },
  89. decorator: {
  90. type: Object,
  91. required: true,
  92. },
  93. networkParams: {
  94. type: Object,
  95. },
  96. networkResourceMapper: {
  97. type: Function,
  98. default: (data) => { return data },
  99. },
  100. vpcParams: {
  101. type: Object,
  102. },
  103. vpcResource: {
  104. type: String,
  105. default: 'vpcs', // 还可能是这样的resource cloudregions/{region_id}/vpcs
  106. },
  107. vpcResourceMapper: {
  108. type: Function,
  109. default: data => { return data },
  110. },
  111. showIpConfig: {
  112. type: Boolean,
  113. default: true,
  114. },
  115. helplink: {
  116. type: Object,
  117. },
  118. },
  119. data () {
  120. return {
  121. ipShow: false,
  122. selectedVpc: {},
  123. }
  124. },
  125. computed: {
  126. vpcParmasConcat () {
  127. return {
  128. limit: 0,
  129. show_emulated: true,
  130. ...this.vpcParams,
  131. }
  132. },
  133. networkParamsConcat () {
  134. return {
  135. vpc: this.selectedVpc.id,
  136. usable: true,
  137. ...this.networkParams,
  138. }
  139. },
  140. },
  141. methods: {
  142. triggerShowIp () {
  143. this.ipShow = !this.ipShow
  144. },
  145. vpcLabelFormat (item) {
  146. if (!item.cidr_block) return item.name
  147. return `${item.name}(${item.cidr_block})`
  148. },
  149. },
  150. }
  151. </script>