Create.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('cloudenv.text_480')}}</div>
  4. <div slot="body">
  5. <a-form
  6. :form="form.fc">
  7. <a-form-item :label="$t('cloudenv.text_95')" v-bind="formItemLayout">
  8. <a-input v-decorator="decorators.name" :placeholder="$t('cloudenv.text_190')" />
  9. </a-form-item>
  10. <a-form-item :label="$t('common.description')" v-bind="formItemLayout">
  11. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  12. </a-form-item>
  13. <a-form-item :label="$t('cloudenv.text_10')" v-bind="formItemLayout">
  14. <base-select
  15. resource="cloudregions"
  16. v-decorator="decorators.region"
  17. :selectProps="{ 'placeholder': $t('cloudenv.text_231') }"
  18. :params="{ 'cloud_env': 'private_or_onpremise', 'brand': 'OneCloud' }" />
  19. </a-form-item>
  20. <a-form-item :label="$t('cloudenv.text_374')" v-bind="formItemLayout">
  21. <a-input v-decorator="decorators.location" :placeholder="$t('cloudenv.text_481')" />
  22. </a-form-item>
  23. </a-form>
  24. </div>
  25. <div slot="footer">
  26. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  27. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  28. </div>
  29. </base-dialog>
  30. </template>
  31. <script>
  32. import DialogMixin from '@/mixins/dialog'
  33. import WindowsMixin from '@/mixins/windows'
  34. export default {
  35. name: 'CreateZoneDialog',
  36. mixins: [DialogMixin, WindowsMixin],
  37. data () {
  38. return {
  39. loading: false,
  40. form: {
  41. fc: this.$form.createForm(this),
  42. },
  43. decorators: {
  44. name: [
  45. 'name',
  46. {
  47. validateFirst: true,
  48. rules: [
  49. { required: true, message: this.$t('cloudenv.text_190') },
  50. // { validator: this.$validate('resourceName') },
  51. ],
  52. },
  53. ],
  54. description: ['description'],
  55. region: [
  56. 'region',
  57. {
  58. rules: [
  59. { required: true, message: this.$t('cloudenv.text_231') },
  60. ],
  61. },
  62. ],
  63. location: [
  64. 'location',
  65. {
  66. rules: [
  67. { required: true, message: this.$t('cloudenv.text_482') },
  68. ],
  69. },
  70. ],
  71. },
  72. formItemLayout: {
  73. wrapperCol: {
  74. span: 21,
  75. },
  76. labelCol: {
  77. span: 3,
  78. },
  79. },
  80. }
  81. },
  82. methods: {
  83. validateForm () {
  84. return new Promise((resolve, reject) => {
  85. this.form.fc.validateFields((err, values) => {
  86. if (!err) {
  87. resolve(values)
  88. } else {
  89. reject(err)
  90. }
  91. })
  92. })
  93. },
  94. doCreate (data) {
  95. return this.params.onManager('create', {
  96. managerArgs: {
  97. data,
  98. },
  99. })
  100. },
  101. async handleConfirm () {
  102. this.loading = true
  103. try {
  104. const values = await this.validateForm()
  105. this.loading = true
  106. await this.doCreate(values)
  107. this.loading = false
  108. this.cancelDialog()
  109. } catch (error) {
  110. this.loading = false
  111. }
  112. },
  113. },
  114. }
  115. </script>