Create.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{params.title}}</div>
  4. <div slot="body">
  5. <a-form
  6. :form="form.fc">
  7. <a-form-item :label="$t('network.text_199')" class="mb-0" v-bind="formItemLayout">
  8. <cloudregion-zone
  9. :zone-params="resParams.zone"
  10. :cloudregion-params="resParams.region"
  11. :decorator="decorators.regionZone"
  12. filterBrandResource="loadbalancer_engine" />
  13. </a-form-item>
  14. <a-form-item :label="$t('network.text_21')" v-bind="formItemLayout">
  15. <a-input v-decorator="decorators.name" :placeholder="$t('network.text_44')" />
  16. </a-form-item>
  17. <a-form-item :label="$t('common.description')" v-bind="formItemLayout">
  18. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  19. </a-form-item>
  20. <a-form-item :label="$t('common.text00012')" class="mb-0" v-bind="formItemLayout">
  21. <tag
  22. v-decorator="decorators.__meta__" />
  23. </a-form-item>
  24. </a-form>
  25. </div>
  26. <div slot="footer">
  27. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  28. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  29. </div>
  30. </base-dialog>
  31. </template>
  32. <script>
  33. import CloudregionZone from '@/sections/CloudregionZone'
  34. import DialogMixin from '@/mixins/dialog'
  35. import WindowsMixin from '@/mixins/windows'
  36. import Tag from '@/sections/Tag'
  37. import validateForm from '@/utils/validate'
  38. export default {
  39. name: 'LoadbalancerclusterCreateDialog',
  40. components: {
  41. CloudregionZone,
  42. Tag,
  43. },
  44. mixins: [DialogMixin, WindowsMixin],
  45. data () {
  46. return {
  47. loading: false,
  48. form: {
  49. fc: this.$form.createForm(this),
  50. },
  51. decorators: {
  52. name: [
  53. 'name',
  54. {
  55. validateFirst: true,
  56. validateTrigger: ['blur'],
  57. rules: [
  58. { required: true, message: this.$t('network.text_116') },
  59. { validator: this.$validate('resourceName') },
  60. ],
  61. },
  62. ],
  63. description: ['description'],
  64. __meta__: [
  65. '__meta__',
  66. {
  67. rules: [
  68. { validator: validateForm('tagName') },
  69. ],
  70. },
  71. ],
  72. regionZone: {
  73. cloudregion: [
  74. 'cloudregion',
  75. {
  76. initialValue: { key: '', label: '' },
  77. rules: [
  78. { required: true, message: this.$t('network.text_286') },
  79. ],
  80. },
  81. ],
  82. zone: [
  83. 'zone',
  84. {
  85. initialValue: { key: '', label: '' },
  86. rules: [
  87. { required: true, message: this.$t('network.text_287') },
  88. ],
  89. },
  90. ],
  91. },
  92. },
  93. formItemLayout: {
  94. wrapperCol: {
  95. span: 20,
  96. },
  97. labelCol: {
  98. span: 4,
  99. },
  100. },
  101. resParams: {
  102. zone: {},
  103. region: {
  104. usable: true,
  105. is_on_premise: true,
  106. scope: this.$store.getters.scope,
  107. },
  108. },
  109. }
  110. },
  111. provide () {
  112. return {
  113. form: this.form,
  114. }
  115. },
  116. methods: {
  117. doCreate (data) {
  118. const params = {
  119. name: data.name,
  120. description: data.description,
  121. cloudregion_id: data.cloudregion.key,
  122. zone: data.zone.key,
  123. zoneData: {
  124. id: data.zone.key,
  125. name: data.zone.label,
  126. regionId: data.cloudregion.key,
  127. },
  128. __meta__: data.__meta__,
  129. }
  130. return new this.$Manager('loadbalancerclusters').create({
  131. data: params,
  132. })
  133. },
  134. async handleConfirm () {
  135. this.loading = true
  136. try {
  137. const values = await this.form.fc.validateFields()
  138. await this.doCreate(values)
  139. this.loading = false
  140. this.cancelDialog()
  141. this.params.refresh()
  142. } catch (error) {
  143. this.loading = false
  144. }
  145. },
  146. },
  147. }
  148. </script>