Create.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('storage.access.group.create')}}</div>
  4. <div slot="body">
  5. <a-form
  6. v-bind="formItemLayout"
  7. :form="form.fc">
  8. <a-form-item :label="$t('storage.text_40')">
  9. <a-input v-decorator="decorators.name" :placeholder="$t('storage.text_56')" />
  10. </a-form-item>
  11. <area-selects
  12. class="mb-0"
  13. ref="areaSelects"
  14. :wrapperCol="formItemLayout.wrapperCol"
  15. :labelCol="formItemLayout.labelCol"
  16. :names="['provider', 'cloudregion']"
  17. :cloudregionParams="cloudregionParams"
  18. :isRequired="true"
  19. :providerParams="providerParams"
  20. filterBrandResource="nas"
  21. @change="handleRegionChange" />
  22. <a-form-item :label="$t('compute.text_15')">
  23. <base-select
  24. resource="cloudproviders"
  25. v-decorator="decorators.cloudprovider"
  26. :params="cloudproviderParams"
  27. :isDefaultSelect="true"
  28. :showSync="true"
  29. :select-props="{ placeholder: $t('compute.text_149') }"
  30. @update:item="cloudproviderSelected" />
  31. </a-form-item>
  32. <a-form-item :label="$t('common.description')">
  33. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  34. </a-form-item>
  35. </a-form>
  36. </div>
  37. <div slot="footer">
  38. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  39. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  40. </div>
  41. </base-dialog>
  42. </template>
  43. <script>
  44. import DialogMixin from '@/mixins/dialog'
  45. import WindowsMixin from '@/mixins/windows'
  46. import { isRequired } from '@/utils/validate'
  47. import AreaSelects from '@/sections/AreaSelects'
  48. export default {
  49. name: 'AccessGroupCreateDialog',
  50. components: {
  51. AreaSelects,
  52. },
  53. mixins: [DialogMixin, WindowsMixin],
  54. data () {
  55. return {
  56. loading: false,
  57. form: {
  58. fc: this.$form.createForm(this),
  59. },
  60. decorators: {
  61. domain: [
  62. 'domain',
  63. {
  64. // initialValue: domain || this.$store.getters.userInfo.projectDomainId,
  65. rules: [
  66. { validator: isRequired(), message: this.$t('rules.domain'), trigger: 'change' },
  67. ],
  68. },
  69. ],
  70. name: [
  71. 'name',
  72. {
  73. validateFirst: true,
  74. rules: [
  75. { required: true, message: this.$t('storage.text_56') },
  76. ],
  77. },
  78. ],
  79. cloudprovider: [
  80. 'cloudprovider',
  81. {
  82. rules: [{ required: true, message: this.$t('common.tips.input', [this.$t('storage.text_40')]) }],
  83. },
  84. ],
  85. description: ['description'],
  86. },
  87. formItemLayout: {
  88. wrapperCol: {
  89. span: 20,
  90. },
  91. labelCol: {
  92. span: 4,
  93. },
  94. },
  95. cloudRegionParams: {
  96. scope: this.$store.getters.scope,
  97. limit: 20,
  98. usable: false,
  99. cloud_env: 'public',
  100. },
  101. providerParams: {
  102. scope: this.$store.getters.scope,
  103. usable: false,
  104. },
  105. regionProvider: '',
  106. regionId: '',
  107. }
  108. },
  109. computed: {
  110. cloudproviderParams () {
  111. const params = {
  112. limit: 20,
  113. // brand: this.form.fd.provider,
  114. cloudregion: this.regionId,
  115. enabled: true,
  116. read_only: false,
  117. scope: this.$store.getters.scope,
  118. }
  119. return params
  120. },
  121. },
  122. methods: {
  123. handleRegionChange (data) {
  124. const { cloudregion } = data
  125. if (cloudregion) {
  126. const { provider } = cloudregion.value
  127. this.regionProvider = provider
  128. this.regionId = cloudregion.id
  129. }
  130. },
  131. doCreate (data) {
  132. return new this.$Manager('access_groups').create({ data: data })
  133. },
  134. async handleConfirm () {
  135. this.loading = true
  136. try {
  137. const values = await this.form.fc.validateFields()
  138. await this.doCreate({ ...values, cloudregion: this.regionId })
  139. this.loading = false
  140. this.cancelDialog()
  141. this.params.refresh && this.params.refresh()
  142. this.params.success && this.params.success()
  143. } catch (error) {
  144. this.loading = false
  145. throw error
  146. }
  147. },
  148. },
  149. }
  150. </script>