AttachNetwork.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.instancegroup')" :count="params.data.length" :action="$t('compute.create_vip')" />
  6. <dialog-table :data="params.data" :columns="columns" :showOverflow="true" />
  7. <a-form-model
  8. ref="configForm"
  9. class="mt-3"
  10. :model="form"
  11. :rules="rules"
  12. v-bind="formItemLayout">
  13. <a-form-model-item :label="$t('compute.text_386')" prop="ip_type">
  14. <div class="d-flex align-items-center">
  15. <a-radio-group v-model="form.ip_type">
  16. <a-radio-button value="auto_allocation">{{$t('compute.auto_allocation')}}</a-radio-button>
  17. <a-radio-button value="specify_ip">{{$t('compute.specify_ip')}}</a-radio-button>
  18. </a-radio-group>
  19. <!-- <a-checkbox v-model="form.require_ipv6" class="ml-2">{{ $t('compute.server_create.require_ipv6_all') }}</a-checkbox> -->
  20. <span class="ml-3 d-flex align-items-center">
  21. <a-checkbox style="width: max-content" v-model="form.require_ipv6" />
  22. <a-dropdown>
  23. <a-menu slot="overlay" v-model="form.ipv6_mode" @click="handleIpv6Mode">
  24. <a-menu-item key="all">{{ $t('compute.server_create.require_ipv6_all') }}</a-menu-item>
  25. <a-menu-item key="only">{{ $t('compute.server_create.require_ipv6_only') }}</a-menu-item>
  26. </a-menu>
  27. <a-button type="link" class="pl-1">{{ form.ipv6_mode === 'only' ? $t('compute.server_create.require_ipv6_only') : $t('compute.server_create.require_ipv6_all') }}<a-icon type="down" /> </a-button>
  28. </a-dropdown>
  29. </span>
  30. </div>
  31. </a-form-model-item>
  32. <a-form-model-item label="IPv4" v-if="form.ip_type === 'specify_ip' && !(form.require_ipv6 && form.ipv6_mode === 'only')" prop="ip_addr">
  33. <a-input v-model="form.ip_addr" :placeholder="$t('common.tips.input', [$t('compute.text_386')])" />
  34. </a-form-model-item>
  35. <a-form-model-item label="IPv6" v-if="form.ip_type === 'specify_ip' && form.require_ipv6" prop="ip6_addr">
  36. <a-input v-model="form.ip6_addr" :placeholder="$t('common.tips.input', [$t('compute.ipv6.address')])" />
  37. </a-form-model-item>
  38. </a-form-model>
  39. </div>
  40. <div slot="footer">
  41. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  42. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  43. </div>
  44. </base-dialog>
  45. </template>
  46. <script>
  47. import DialogMixin from '@/mixins/dialog'
  48. import WindowsMixin from '@/mixins/windows'
  49. export default {
  50. name: 'InstanceGroupAddVipNetworkDialog',
  51. mixins: [DialogMixin, WindowsMixin],
  52. data () {
  53. return {
  54. loading: false,
  55. form: {
  56. ip_type: 'auto_allocation',
  57. ip_addr: '',
  58. require_ipv6: false,
  59. ipv6_mode: 'all',
  60. },
  61. rules: {
  62. ip_addr: {
  63. require: true, validator: this.$validate('IPv4'),
  64. },
  65. ip6_addr: {
  66. require: true, validator: this.$validate('IPv6'),
  67. },
  68. },
  69. formItemLayout: {
  70. wrapperCol: {
  71. span: 21,
  72. },
  73. labelCol: {
  74. span: 3,
  75. },
  76. },
  77. secgroupsInitLoaded: false,
  78. bindedSecgroups: [],
  79. bindedSecgroupsLoaded: false,
  80. vpcObj: {
  81. id: this.params.data[0].vpc_id,
  82. name: this.params.data[0].vpc,
  83. },
  84. }
  85. },
  86. computed: {
  87. networkLimit () {
  88. return 8 - (this.params.total || 0)
  89. },
  90. columns () {
  91. return this.params.columns.filter(item => ['name', 'status', 'vips'].includes(item.field))
  92. },
  93. },
  94. methods: {
  95. handleIpv6Mode (e) {
  96. this.form.ipv6_mode = e.key
  97. },
  98. async handleConfirm () {
  99. this.loading = true
  100. try {
  101. const validate = await this.$refs.configForm.validate()
  102. if (!validate) {
  103. this.loading = false
  104. return
  105. }
  106. const data = {}
  107. if (this.form.require_ipv6) {
  108. data.require_ipv6 = true
  109. }
  110. if (this.form.ip_type === 'specify_ip') {
  111. data.ip_addr = this.form.ip_addr
  112. data.require_designated_ip = true
  113. if (this.form.require_ipv6) {
  114. data.ip6_addr = this.form.ip6_addr
  115. }
  116. }
  117. if (this.form.ipv6_mode === 'only') {
  118. delete data.ip_addr
  119. }
  120. const manager = new this.$Manager('instancegroups')
  121. await manager.performAction({
  122. id: this.params.data[0].id,
  123. action: 'attachnetwork',
  124. data,
  125. })
  126. this.params.refresh()
  127. this.$bus.$emit('VMInstanceListSingleRefresh', [this.params.resId])
  128. this.cancelDialog()
  129. } finally {
  130. this.loading = false
  131. }
  132. },
  133. },
  134. }
  135. </script>
  136. <style lang="less" scoped>
  137. /deep/ .network-item {
  138. width: 260px;
  139. }
  140. </style>