AccountLisResetPwd.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('db.text_201')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="params.name ? params.name : $t('dictionary.elasticcaches')" :count="params.data.length" :action="$t('db.text_201')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form slot="body" :form="form.fc" class="mt-3">
  8. <a-form-item v-bind="formItemLayout" :label="$t('db.text_285')">
  9. {{this.params.data[0].name}}
  10. </a-form-item>
  11. <a-form-item :label="$t('db.text_286')" v-bind="formItemLayout">
  12. <server-password :loginTypes="['random', 'password']" :decorator="decorators.loginConfig" />
  13. </a-form-item>
  14. </a-form>
  15. </div>
  16. <div slot="footer">
  17. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  18. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  19. </div>
  20. </base-dialog>
  21. </template>
  22. <script>
  23. import { ACCOUNT_PRIVILEGES } from '../constants'
  24. import { CreateServerForm } from '@Compute/constants'
  25. import ServerPassword from '@Compute/sections/ServerPassword'
  26. import DialogMixin from '@/mixins/dialog'
  27. import WindowsMixin from '@/mixins/windows'
  28. import { passwordValidator } from '@/utils/validate'
  29. // import validateForm from '@/utils/validate'
  30. export default {
  31. name: 'RedisAccountLisResetPwdDialog',
  32. components: {
  33. ServerPassword,
  34. },
  35. mixins: [DialogMixin, WindowsMixin],
  36. data () {
  37. return {
  38. loading: false,
  39. privileges: ACCOUNT_PRIVILEGES,
  40. form: {
  41. fc: this.$form.createForm(this),
  42. },
  43. formItemLayout: {
  44. wrapperCol: { span: CreateServerForm.wrapperCol },
  45. labelCol: { span: CreateServerForm.labelCol },
  46. },
  47. }
  48. },
  49. computed: {
  50. decorators () {
  51. const decorators = {
  52. password: [
  53. 'password',
  54. {
  55. validateFirst: true,
  56. rules: [
  57. { required: true, message: this.$t('db.text_207') },
  58. { validator: passwordValidator },
  59. ],
  60. },
  61. ],
  62. checkPassword: [
  63. 'checkPassword',
  64. {
  65. initialValue: undefined,
  66. rules: [
  67. { required: true, message: this.$t('db.text_208') },
  68. { validator: this.rulesCheckPassword },
  69. ],
  70. },
  71. ],
  72. loginConfig: {
  73. loginType: [
  74. 'loginType',
  75. {
  76. initialValue: 'random',
  77. },
  78. ],
  79. },
  80. }
  81. return decorators
  82. },
  83. },
  84. methods: {
  85. rulesCheckPassword (rule, value, callback) {
  86. const form = this.form.fc
  87. if (value && value !== form.getFieldValue('password')) {
  88. callback(new Error(this.$t('db.text_209')))
  89. } else {
  90. callback()
  91. }
  92. },
  93. validateForm () {
  94. return new Promise((resolve, reject) => {
  95. this.form.fc.validateFields((err, values) => {
  96. if (!err) {
  97. resolve(values)
  98. } else {
  99. reject(err)
  100. }
  101. })
  102. })
  103. },
  104. async handleConfirm () {
  105. this.loading = true
  106. try {
  107. const values = await this.validateForm()
  108. if (values.loginType === 'random') {
  109. values.reset_password = true
  110. }
  111. const params = {
  112. ...values,
  113. }
  114. if (this.params.redisItem) {
  115. params.elasticcache = this.params.redisItem.id
  116. }
  117. delete params.checkPassword
  118. await this.params.list.onManager('performAction', {
  119. id: this.params.data[0].id,
  120. steadyStatus: this.params.steadyStatus,
  121. managerArgs: {
  122. action: 'reset-password',
  123. data: params,
  124. },
  125. })
  126. this.loading = false
  127. this.cancelDialog()
  128. } catch (error) {
  129. this.loading = false
  130. }
  131. },
  132. },
  133. }
  134. </script>