BackupCreate.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <base-dialog @cancel="cancelDialog" :width="900">
  3. <div slot="header">{{$t('db.text_215')}}</div>
  4. <a-form slot="body" :form="form.fc" class="mt-3">
  5. <a-form-item v-bind="formItemLayout" :label="$t('db.text_60')">
  6. <a-input v-decorator="decorators.name" :placeholder="$t('db.text_216')" />
  7. <name-repeated v-slot:extra res="dbinstancebackups" :name="form.fc.getFieldValue('name')" />
  8. </a-form-item>
  9. <a-form-item v-bind="formItemLayout" :label="$t('db.text_217')" v-if="!params.rdsItem">
  10. <a-select v-decorator="decorators.dbinstance" :placeholder="$t('db.text_218')" :loading="rdsListLoading">
  11. <a-select-option :key="item.id" v-for="item in rdsList">{{item.name}}</a-select-option>
  12. </a-select>
  13. </a-form-item>
  14. <a-form-item v-bind="formItemLayout" :label="$t('db.text_219')">
  15. <a-textarea :autosize="{ minRows: 2, maxRows: 6 }" v-decorator="decorators.description" :placeholder="$t('db.text_220')" />
  16. </a-form-item>
  17. </a-form>
  18. <div slot="footer">
  19. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  20. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  21. </div>
  22. </base-dialog>
  23. </template>
  24. <script>
  25. import { CreateServerForm } from '@Compute/constants'
  26. import NameRepeated from '@/sections/NameRepeated'
  27. import DialogMixin from '@/mixins/dialog'
  28. import WindowsMixin from '@/mixins/windows'
  29. import validateForm from '@/utils/validate'
  30. export default {
  31. name: 'RDSBackupCreate',
  32. components: {
  33. NameRepeated,
  34. },
  35. mixins: [DialogMixin, WindowsMixin],
  36. data () {
  37. return {
  38. loading: false,
  39. form: {
  40. fc: this.$form.createForm(this),
  41. },
  42. formItemLayout: {
  43. wrapperCol: { span: CreateServerForm.wrapperCol },
  44. labelCol: { span: CreateServerForm.labelCol },
  45. },
  46. rdsListLoading: false,
  47. rdsList: [],
  48. }
  49. },
  50. provide () {
  51. return {
  52. form: this.form,
  53. }
  54. },
  55. computed: {
  56. decorators () {
  57. const decorators = {
  58. name: [
  59. 'generate_name',
  60. {
  61. validateFirst: true,
  62. rules: [
  63. { required: true, message: this.$t('db.text_136') },
  64. { validator: validateForm('serverName') },
  65. ],
  66. },
  67. ],
  68. description: [
  69. 'description',
  70. {
  71. rules: [
  72. { max: 200 },
  73. ],
  74. },
  75. ],
  76. dbinstance: [
  77. 'dbinstance',
  78. {
  79. rules: [
  80. { required: true, message: this.$t('db.text_136') },
  81. ],
  82. },
  83. ],
  84. }
  85. return decorators
  86. },
  87. },
  88. created () {
  89. if (!this.params.rdsItem) {
  90. this.fetchQueryRDSList()
  91. }
  92. },
  93. methods: {
  94. async fetchQueryRDSList () {
  95. const manager = new this.$Manager('dbinstances', 'v2')
  96. this.rdsListLoading = true
  97. try {
  98. const { data } = await manager.list({
  99. params: {
  100. scope: this.$store.getters.scope,
  101. limit: 0,
  102. status: 'running',
  103. },
  104. })
  105. this.rdsList = data.data
  106. } catch (err) {
  107. throw err
  108. } finally {
  109. this.rdsListLoading = false
  110. }
  111. },
  112. validateForm () {
  113. return new Promise((resolve, reject) => {
  114. this.form.fc.validateFields((err, values) => {
  115. if (!err) {
  116. if (this.params.rdsItem) {
  117. values.dbinstance_id = this.params.rdsItem.id
  118. values.dbinstance = this.params.rdsItem.id
  119. }
  120. resolve(values)
  121. } else {
  122. reject(err)
  123. }
  124. })
  125. })
  126. },
  127. async handleConfirm () {
  128. this.loading = true
  129. try {
  130. const values = await this.validateForm()
  131. await this.params.list.onManager('create', {
  132. managerArgs: {
  133. data: values,
  134. },
  135. })
  136. this.cancelDialog()
  137. } catch (err) {
  138. throw err
  139. } finally {
  140. this.loading = false
  141. }
  142. },
  143. },
  144. }
  145. </script>