UpdateAuthMode.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{params.title}}</div>
  4. <div slot="body">
  5. <div class="mb-3">
  6. <a-alert :showIcon="false" :message="alertMsg" banner />
  7. </div>
  8. <dialog-selected-tips :name="$t('dictionary.elasticcaches')" :count="params.data.length" :action="params.title" />
  9. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  10. <a-form :form="form.fc" class="mt-3">
  11. <a-form-item
  12. :label="$t('db.text_286')"
  13. v-bind="formItemLayout"
  14. v-if="params.data[0].provider === 'Qcloud' && params.data[0].auth_mode === 'off'"
  15. :extra="$t('db.text_359')">
  16. <server-password :loginTypes="['random', 'password']" :decorator="decorators.loginConfig" />
  17. </a-form-item>
  18. </a-form>
  19. </div>
  20. <div slot="footer">
  21. <a-button :loading="loading" @click="handleConfirm" type="primary">{{ $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 { BUY_DURATIONS_OPTIONS } from '../constants/index.js'
  28. import { CreateServerForm } from '@Compute/constants'
  29. import ServerPassword from '@Compute/sections/ServerPassword'
  30. import DialogMixin from '@/mixins/dialog'
  31. import WindowsMixin from '@/mixins/windows'
  32. export default {
  33. name: 'RedisUpdateAuthModeDialog',
  34. components: {
  35. ServerPassword,
  36. },
  37. mixins: [DialogMixin, WindowsMixin],
  38. provide () {
  39. return {
  40. form: this.form,
  41. }
  42. },
  43. data () {
  44. return {
  45. BUY_DURATIONS_OPTIONS,
  46. loading: false,
  47. form: {
  48. fc: this.$form.createForm(this),
  49. },
  50. formItemLayout: {
  51. wrapperCol: { span: CreateServerForm.wrapperCol },
  52. labelCol: { span: CreateServerForm.labelCol },
  53. },
  54. decorators: {
  55. loginConfig: {
  56. loginType: [
  57. 'loginType',
  58. {
  59. initialValue: 'random',
  60. },
  61. ],
  62. },
  63. },
  64. }
  65. },
  66. computed: {
  67. alertMsg () {
  68. const data = this.params.data[0]
  69. if (data.auth_mode !== 'on') {
  70. return this.$t('db.text_292')
  71. } else {
  72. return this.$t('db.text_293')
  73. }
  74. },
  75. },
  76. methods: {
  77. async handleConfirm () {
  78. this.loading = true
  79. try {
  80. if (this.params.data[0].provider === 'Qcloud' && this.params.data[0].auth_mode === 'off') {
  81. const values = await this.form.fc.validateFields()
  82. if (values.loginType === 'random') {
  83. values.reset_password = true
  84. }
  85. await this.params.onManager('performAction', {
  86. id: this.params.data[0].id,
  87. steadyStatus: 'running',
  88. managerArgs: {
  89. action: 'reset-password',
  90. data: {
  91. ...values,
  92. },
  93. },
  94. })
  95. } else {
  96. await this.params.onManager('performAction', {
  97. steadyStatus: 'running',
  98. id: this.params.data[0].id,
  99. managerArgs: {
  100. action: 'update-auth-mode',
  101. data: {
  102. auth_mode: this.params.data[0].auth_mode === 'on' ? 'off' : 'on',
  103. },
  104. },
  105. })
  106. }
  107. this.loading = false
  108. this.cancelDialog()
  109. } catch (error) {
  110. this.loading = false
  111. }
  112. },
  113. },
  114. }
  115. </script>