BackupListCreate.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('db.text_287')}}</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 :placeholder="$t('db.text_288')" v-decorator="decorators.name" />
  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_219')">
  10. <a-textarea :placeholder="$t('db.text_220')"
  11. :autosize="{ minRows: 4, maxRows: 7 }"
  12. v-decorator="decorators.description" />
  13. </a-form-item>
  14. </a-form>
  15. <div slot="footer">
  16. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  17. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  18. </div>
  19. </base-dialog>
  20. </template>
  21. <script>
  22. import { ACCOUNT_PRIVILEGES } from '../constants'
  23. import { CreateServerForm } from '@Compute/constants'
  24. import DialogMixin from '@/mixins/dialog'
  25. import WindowsMixin from '@/mixins/windows'
  26. import validateForm from '@/utils/validate'
  27. export default {
  28. name: 'BackupListCreate',
  29. mixins: [DialogMixin, WindowsMixin],
  30. data () {
  31. return {
  32. loading: false,
  33. privileges: ACCOUNT_PRIVILEGES,
  34. form: {
  35. fc: this.$form.createForm(this),
  36. },
  37. formItemLayout: {
  38. wrapperCol: { span: CreateServerForm.wrapperCol },
  39. labelCol: { span: CreateServerForm.labelCol },
  40. },
  41. }
  42. },
  43. computed: {
  44. decorators () {
  45. const { initialValues = {} } = this.params
  46. const decorators = {
  47. name: [
  48. 'name',
  49. {
  50. initialValue: initialValues.name,
  51. validateFirst: true,
  52. rules: [
  53. { required: true, message: this.$t('db.text_136') },
  54. { validator: validateForm('serverName') },
  55. ],
  56. },
  57. ],
  58. description: [
  59. 'description',
  60. {
  61. initialValue: initialValues.ip_list,
  62. rules: [
  63. { max: 200, message: this.$t('db.text_289') },
  64. ],
  65. },
  66. ],
  67. }
  68. return decorators
  69. },
  70. },
  71. methods: {
  72. rulesCheckPassword (rule, value, callback) {
  73. const form = this.form.fc
  74. if (value && value !== form.getFieldValue('password')) {
  75. callback(new Error(this.$t('db.text_209')))
  76. } else {
  77. callback()
  78. }
  79. },
  80. validateForm () {
  81. return new Promise((resolve, reject) => {
  82. this.form.fc.validateFields((err, values) => {
  83. if (!err) {
  84. resolve(values)
  85. } else {
  86. reject(err)
  87. }
  88. })
  89. })
  90. },
  91. async handleConfirm () {
  92. this.loading = true
  93. try {
  94. const values = await this.validateForm()
  95. const params = {
  96. ...values,
  97. elasticcache: this.params.redisItem.id,
  98. }
  99. delete params.checkPassword
  100. await this.params.list.onManager('create', {
  101. managerArgs: {
  102. data: params,
  103. },
  104. })
  105. this.loading = false
  106. this.cancelDialog()
  107. } catch (error) {
  108. this.loading = false
  109. }
  110. },
  111. },
  112. }
  113. </script>