UpdatePrivilege.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <base-dialog :width="900" @cancel="cancelDialog">
  3. <div slot="header">{{$t('db.text_203')}}</div>
  4. <a-form :form="form.fc" class="mt-3" slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.dbinstanceaccounts')" :action="params.title" :count="params.data.length" />
  6. <dialog-table :columns="params.columns.slice(0, 3)" :data="params.data" />
  7. <a-form-item v-bind="formItemLayout" :label="$t('db.text_344')">
  8. <template #extra>
  9. <div>
  10. <p class="mb-0">{{$t('db.text_345')}}</p>
  11. <!-- <p class="mb-0">{{$t('db.text_346')}}</p> -->
  12. </div>
  13. </template>
  14. <a-input v-decorator="decorators.host" disabled />
  15. <!-- <a-textarea :auto-size="{ minRows: 3, maxRows: 5 }" v-decorator="decorators.host" disabled /> -->
  16. </a-form-item>
  17. <a-form-item v-bind="formItemLayout" :label="$t('db.text_28')">
  18. <account-privileges
  19. :privileges="params.data[0].dbinstanceprivileges || []"
  20. :rdsItem="params.rdsItem" />
  21. </a-form-item>
  22. </a-form>
  23. <div slot="footer">
  24. <a-button :loading="loading" @click="handleConfirm" type="primary">{{ $t('dialog.ok') }}</a-button>
  25. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  26. </div>
  27. </base-dialog>
  28. </template>
  29. <script>
  30. import { CreateServerForm } from '@Compute/constants'
  31. import DialogMixin from '@/mixins/dialog'
  32. import WindowsMixin from '@/mixins/windows'
  33. import validateForm, { passwordValidator } from '@/utils/validate'
  34. import AccountPrivileges from '../components/AccountPrivileges'
  35. export default {
  36. name: 'RDSAccountUpdatePrivilegeDialog',
  37. components: {
  38. AccountPrivileges,
  39. },
  40. mixins: [DialogMixin, WindowsMixin],
  41. data () {
  42. return {
  43. loading: false,
  44. form: {
  45. fc: this.$form.createForm(this),
  46. },
  47. formItemLayout: {
  48. wrapperCol: { span: CreateServerForm.wrapperCol },
  49. labelCol: { span: CreateServerForm.labelCol },
  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('serverName') },
  70. ],
  71. },
  72. ],
  73. host: [
  74. 'host',
  75. {
  76. initialValue: initialValues.host,
  77. rules: [
  78. { required: true, message: this.$t('db.text_347') },
  79. ],
  80. },
  81. ],
  82. account_privilege: [
  83. 'account_privilege',
  84. {
  85. initialValue: 'read',
  86. rules: [{ required: true, message: this.$t('db.text_136') }],
  87. },
  88. ],
  89. password: [
  90. 'password',
  91. {
  92. validateFirst: true,
  93. rules: [
  94. { required: true, message: this.$t('db.text_207') },
  95. { validator: passwordValidator },
  96. ],
  97. },
  98. ],
  99. checkPassword: [
  100. 'checkPassword',
  101. {
  102. initialValue: initialValues.ip_list,
  103. rules: [
  104. { required: true, message: this.$t('db.text_208') },
  105. { validator: this.rulesCheckPassword },
  106. ],
  107. },
  108. ],
  109. }
  110. return decorators
  111. },
  112. },
  113. methods: {
  114. rulesCheckPassword (rule, value, callback) {
  115. const form = this.form.fc
  116. if (value && value !== form.getFieldValue('password')) {
  117. callback(new Error(this.$t('db.text_209')))
  118. } else {
  119. callback()
  120. }
  121. },
  122. validateForm () {
  123. return new Promise((resolve, reject) => {
  124. this.form.fc.validateFields((err, values) => {
  125. if (!err) {
  126. resolve(values)
  127. } else {
  128. reject(err)
  129. }
  130. })
  131. })
  132. },
  133. async handleConfirm () {
  134. this.loading = true
  135. try {
  136. const values = await this.validateForm()
  137. await this.params.list.onManager('performAction', {
  138. id: this.params.data[0].id,
  139. steadyStatus: ['available'],
  140. managerArgs: {
  141. action: 'set-privileges',
  142. data: values,
  143. },
  144. })
  145. this.loading = false
  146. this.cancelDialog()
  147. } catch (error) {
  148. this.loading = false
  149. }
  150. },
  151. },
  152. }
  153. </script>