Create.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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">
  5. <a-form-item v-bind="formItemLayout" :label="$t('db.text_60')">
  6. <a-input :placeholder="$t('validator.dbName')" v-decorator="decorators.name" />
  7. </a-form-item>
  8. <a-form-item v-bind="formItemLayout" :label="$t('db.text_344')" v-if="params.rdsItem.provider === 'Qcloud'">
  9. <template #extra>
  10. <div>
  11. <p class="mb-0">{{$t('db.text_345')}}</p>
  12. <!-- <p class="mb-0">{{$t('db.text_346')}}</p> -->
  13. </div>
  14. </template>
  15. <a-input v-decorator="decorators.host" />
  16. <!-- <a-textarea :auto-size="{ minRows: 3, maxRows: 5 }" v-decorator="decorators.host" /> -->
  17. </a-form-item>
  18. <a-form-item v-bind="formItemLayout" :label="$t('db.text_28')" v-if="this.params.rdsItem.brand !== 'Google'">
  19. <account-privileges :rdsItem="params.rdsItem" />
  20. </a-form-item>
  21. <a-form-item :label="$t('db.text_195')" v-bind="formItemLayout">
  22. <server-password :loginTypes="loginTypes" :decorator="decorators.loginConfig" :form="form" />
  23. </a-form-item>
  24. </a-form>
  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 AccountPrivileges from '../components/AccountPrivileges'
  33. import { CreateServerForm } from '@Compute/constants'
  34. import { RDS_ACCOUNT_PRIVILEGES } from '@DB/constants'
  35. import ServerPassword from '@Compute/sections/ServerPassword'
  36. import DialogMixin from '@/mixins/dialog'
  37. import WindowsMixin from '@/mixins/windows'
  38. import validateForm, { passwordValidator } from '@/utils/validate'
  39. export default {
  40. name: 'RDSAccountCreateDialog',
  41. components: {
  42. AccountPrivileges,
  43. ServerPassword,
  44. },
  45. mixins: [DialogMixin, WindowsMixin],
  46. data () {
  47. return {
  48. loginTypes: ['random', 'password'],
  49. loading: false,
  50. privileges: RDS_ACCOUNT_PRIVILEGES,
  51. form: {
  52. fc: this.$form.createForm(this),
  53. },
  54. formItemLayout: {
  55. wrapperCol: { span: CreateServerForm.wrapperCol },
  56. labelCol: { span: CreateServerForm.labelCol },
  57. },
  58. }
  59. },
  60. provide () {
  61. return {
  62. form: this.form,
  63. }
  64. },
  65. computed: {
  66. decorators () {
  67. const { initialValues = {} } = this.params
  68. const decorators = {
  69. name: [
  70. 'name',
  71. {
  72. initialValue: initialValues.name,
  73. validateFirst: true,
  74. rules: [
  75. { required: true, message: this.$t('db.text_136') },
  76. { validator: validateForm('dbName') },
  77. ],
  78. },
  79. ],
  80. host: [
  81. 'host',
  82. {
  83. initialValue: initialValues.host,
  84. rules: [
  85. { required: true, message: this.$t('db.text_347') },
  86. ],
  87. },
  88. ],
  89. account_privilege: [
  90. 'account_privilege',
  91. {
  92. initialValue: 'read',
  93. rules: [{ required: true, message: this.$t('db.text_136') }],
  94. },
  95. ],
  96. password: [
  97. 'password',
  98. {
  99. validateFirst: true,
  100. rules: [
  101. { required: true, message: this.$t('db.text_207') },
  102. { validator: passwordValidator },
  103. ],
  104. },
  105. ],
  106. checkPassword: [
  107. 'checkPassword',
  108. {
  109. initialValue: initialValues.ip_list,
  110. rules: [
  111. { required: true, message: this.$t('db.text_208') },
  112. { validator: this.rulesCheckPassword },
  113. ],
  114. },
  115. ],
  116. loginConfig: {
  117. loginType: [
  118. 'loginType',
  119. {
  120. initialValue: 'random',
  121. },
  122. ],
  123. },
  124. }
  125. return decorators
  126. },
  127. },
  128. created () {
  129. },
  130. methods: {
  131. rulesCheckPassword (rule, value, callback) {
  132. const form = this.form.fc
  133. if (value && value !== form.getFieldValue('password')) {
  134. callback(new Error(this.$t('db.text_209')))
  135. } else {
  136. callback()
  137. }
  138. },
  139. validateForm () {
  140. return new Promise((resolve, reject) => {
  141. this.form.fc.validateFields((err, values) => {
  142. if (!err) {
  143. resolve(values)
  144. } else {
  145. reject(err)
  146. }
  147. })
  148. })
  149. },
  150. async handleConfirm () {
  151. this.loading = true
  152. try {
  153. const values = await this.validateForm()
  154. const params = {
  155. ...values,
  156. dbinstance: this.params.rdsItem.id,
  157. }
  158. delete params.checkPassword
  159. await this.params.list.onManager('create', {
  160. managerArgs: {
  161. data: params,
  162. },
  163. })
  164. this.loading = false
  165. this.cancelDialog()
  166. } catch (error) {
  167. this.loading = false
  168. }
  169. },
  170. },
  171. }
  172. </script>