Create.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <base-dialog @cancel="cancelDialog" :width="900">
  3. <div slot="header">{{params.title}}</div>
  4. <a-form slot="body" :form="form.fc" class="mt-3" v-bind="formItemLayout">
  5. <a-form-item :label="$t('db.text_232')">
  6. <a-input :placeholder="$t('validator.dbName')" v-decorator="decorators.name" />
  7. </a-form-item>
  8. <a-form-item :label="$t('db.text_233')">
  9. <a-select allowClear showSearch :placeholder="$t('db.text_234')" v-decorator="decorators.character_set">
  10. <a-select-option
  11. v-for="item in CHARACTER_SET"
  12. :key="item"
  13. :value="item">{{ item }}</a-select-option>
  14. </a-select>
  15. </a-form-item>
  16. <a-form-item :label="$t('db.text_188')" v-if="this.params.rdsItem.brand !== 'Google'">
  17. <database-privileges :rdsItem="params.rdsItem" />
  18. </a-form-item>
  19. </a-form>
  20. <div slot="footer">
  21. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  22. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  23. </div>
  24. </base-dialog>
  25. </template>
  26. <script>
  27. import DatabasePrivileges from '../components/DatabasePrivileges'
  28. import { RDS_ACCOUNT_PRIVILEGES } from '@DB/constants'
  29. import DialogMixin from '@/mixins/dialog'
  30. import WindowsMixin from '@/mixins/windows'
  31. import validateForm from '@/utils/validate'
  32. const CHARACTER_SET = ['utf8', 'gbk', 'latin1', 'utf8mb4', 'euckr', 'armscii8', 'ascii', 'big5', 'binary', 'cp1250', 'cp1251', 'cp1256', 'cp1257', 'cp850', 'cp852', 'cp866', 'cp932', 'dec8', 'eucjpms', 'gb2312', 'geostd8', 'greek', 'hebrew', 'hp8', 'keybcs2', 'koi8r', 'koi8u', 'latin2', 'latin5', 'latin7', 'macce', 'macroman', 'sjis', 'swe7', 'tis620', 'ucs2', 'ujis', 'utf16', 'utf16le', 'utf32']
  33. export default {
  34. name: 'RDSDatabaseCreateDialog',
  35. components: {
  36. DatabasePrivileges,
  37. },
  38. mixins: [DialogMixin, WindowsMixin],
  39. data () {
  40. return {
  41. loading: false,
  42. CHARACTER_SET,
  43. privileges: RDS_ACCOUNT_PRIVILEGES,
  44. form: {
  45. fc: this.$form.createForm(this),
  46. },
  47. formItemLayout: {
  48. wrapperCol: { span: 20 },
  49. labelCol: { span: 4 },
  50. },
  51. }
  52. },
  53. provide () {
  54. return {
  55. form: this.form,
  56. }
  57. },
  58. computed: {
  59. decorators () {
  60. const { initialValues = {} } = this.params
  61. const decorators = {
  62. name: [
  63. 'name',
  64. {
  65. initialValue: initialValues.name,
  66. validateFirst: true,
  67. rules: [
  68. { required: true, message: this.$t('db.text_136') },
  69. { validator: validateForm('dbName') },
  70. ],
  71. },
  72. ],
  73. character_set: [
  74. 'character_set',
  75. {
  76. initialValue: 'utf8',
  77. rules: [{ required: true, message: this.$t('db.text_234') }],
  78. },
  79. ],
  80. }
  81. return decorators
  82. },
  83. },
  84. methods: {
  85. validateForm () {
  86. return new Promise((resolve, reject) => {
  87. this.form.fc.validateFields((err, values) => {
  88. if (!err) {
  89. resolve(values)
  90. } else {
  91. reject(err)
  92. }
  93. })
  94. })
  95. },
  96. async handleConfirm () {
  97. this.loading = true
  98. try {
  99. const values = await this.validateForm()
  100. const params = {
  101. ...values,
  102. dbinstance: this.params.rdsItem.id,
  103. }
  104. await this.params.onManager('create', {
  105. managerArgs: {
  106. data: params,
  107. },
  108. })
  109. this.loading = false
  110. this.cancelDialog()
  111. } catch (error) {
  112. this.loading = false
  113. throw error
  114. }
  115. },
  116. },
  117. }
  118. </script>