VmNetwork.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div>
  3. <a-alert :showIcon="false" banner>
  4. <div slot="message">{{$t('cloudenv.text_225')}}<div style="margin-left: 68px">{{$t('cloudenv.text_226')}}</div>
  5. </div>
  6. </a-alert>
  7. <a-form class="mt-3" :form="form.fc">
  8. <a-divider orientation="left">{{$t('cloudenv.text_227')}}</a-divider>
  9. <a-form-item :label="$t('cloudenv.text_228')" v-bind="formLayout">
  10. <a-switch :checkedChildren="$t('cloudenv.text_84')" :unCheckedChildren="$t('cloudenv.text_85')" v-model="configNetwork" />
  11. </a-form-item>
  12. <template v-if="configNetwork">
  13. <a-form-item :label="$t('cloudenv.text_184')" v-bind="formLayout">
  14. <a-input v-decorator="decorators.name" :placeholder="$t('validator.resourceName')" />
  15. </a-form-item>
  16. <a-form-item :label="$t('cloudenv.text_229')" class="mb-0" v-bind="formLayout">
  17. <cloudregion-vpc-wire
  18. :vpc-params="params.vpc"
  19. :cloudregion-params="params.cloudregion"
  20. :wire-params="params.wire"
  21. :vpcMapper="vpcMapper"
  22. :decorator="decorators.cloudregionVpcWire" />
  23. </a-form-item>
  24. <a-form-item v-bind="formLayout">
  25. <span slot="label">{{$t('cloudenv.text_181')}}<help-tooltip class="ml-1" name="networkIpSubnets" /></span>
  26. <ip-subnets :decorator="decorators.ipSubnets" />
  27. </a-form-item>
  28. </template>
  29. </a-form>
  30. </div>
  31. </template>
  32. <script>
  33. import createMixin from './components/createMixin'
  34. import IpSubnets from './components/IpSubnets'
  35. import CloudregionVpcWire from '@/sections/CloudregionVpcWire'
  36. import { isRequired } from '@/utils/validate'
  37. function validateGateway (rule, value, callback) {
  38. // 只需要查看是否是以 0 结尾
  39. const ipItems = value.split('.')
  40. const msg = this.$t('cloudenv.text_230')
  41. if (ipItems[ipItems.length - 1] === '0') {
  42. callback(msg)
  43. } else {
  44. callback()
  45. }
  46. }
  47. export default {
  48. name: 'VmNetworkCreate',
  49. components: {
  50. CloudregionVpcWire,
  51. IpSubnets,
  52. },
  53. mixins: [createMixin],
  54. provide () {
  55. return {
  56. form: this.form,
  57. }
  58. },
  59. data () {
  60. return {
  61. configNetwork: true,
  62. decorators: {
  63. name: [
  64. 'name',
  65. {
  66. validateTrigger: ['change', 'blur'],
  67. validateFirst: true,
  68. rules: [
  69. { required: true, message: this.$t('cloudenv.text_190') },
  70. { validator: this.$validate('resourceName') },
  71. ],
  72. },
  73. ],
  74. cloudregionVpcWire: {
  75. cloudregion: [
  76. 'cloudregion',
  77. {
  78. rules: [
  79. { validator: isRequired(), message: this.$t('cloudenv.text_231') },
  80. ],
  81. },
  82. ],
  83. vpc: [
  84. 'vpc',
  85. {
  86. rules: [
  87. { validator: isRequired(), message: this.$t('cloudenv.text_232') },
  88. ],
  89. },
  90. ],
  91. wire: [
  92. 'wire',
  93. {
  94. rules: [
  95. { validator: isRequired(), message: this.$t('cloudenv.text_233') },
  96. ],
  97. },
  98. ],
  99. },
  100. ipSubnets: {
  101. startip: i => [
  102. `startip[${i}]`,
  103. {
  104. validateTrigger: ['change', 'blur'],
  105. validateFirst: true,
  106. rules: [
  107. { required: true, message: this.$t('cloudenv.text_191') },
  108. { validator: this.$validate('IPv4') },
  109. ],
  110. },
  111. ],
  112. endip: i => [
  113. `endip[${i}]`,
  114. {
  115. validateTrigger: ['change', 'blur'],
  116. validateFirst: true,
  117. rules: [
  118. { required: true, message: this.$t('cloudenv.text_192') },
  119. { validator: this.$validate('IPv4') },
  120. ],
  121. },
  122. ],
  123. netmask: i => [
  124. `netmask[${i}]`,
  125. {
  126. initialValue: '24',
  127. validateTrigger: ['change', 'blur'],
  128. rules: [
  129. { required: true, message: this.$t('cloudenv.text_234') },
  130. ],
  131. },
  132. ],
  133. gateway: i => [
  134. `gateway[${i}]`,
  135. {
  136. validateTrigger: ['change', 'blur'],
  137. validateFirst: true,
  138. rules: [
  139. { required: true, message: this.$t('cloudenv.text_235') },
  140. { validator: this.$validate('IPv4') },
  141. { validator: validateGateway },
  142. ],
  143. },
  144. ],
  145. vlan: i => [
  146. `vlan[${i}]`,
  147. ],
  148. },
  149. },
  150. params: {
  151. cloudregion: {
  152. scope: this.$store.getters.scope,
  153. limit: 0,
  154. is_on_premise: true,
  155. },
  156. vpc: {
  157. scope: this.$store.getters.scope,
  158. limit: 0,
  159. },
  160. wire: {
  161. scope: this.$store.getters.scope,
  162. },
  163. },
  164. keepAliveFields: true,
  165. }
  166. },
  167. methods: {
  168. vpcMapper (list) {
  169. return list.filter(val => val.id === 'default')
  170. },
  171. },
  172. }
  173. </script>