SettingsPassword.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div>
  3. <a-form ref="ref_form" :model="form" :style="{ width: '900px' }">
  4. <a-form-item field="password_current" :label="$t('settings.current_password')" required>
  5. <a-input-password
  6. v-model="form.password_current"
  7. :placeholder="$t('settings.placeholder_cur_password')"
  8. allow-clear
  9. >
  10. <template #prefix>
  11. <icon-lock />
  12. </template>
  13. </a-input-password>
  14. </a-form-item>
  15. <a-form-item field="password_new_1" :label="$t('settings.new_password')" required>
  16. <a-input-password
  17. v-model="form.password_new_1"
  18. :placeholder="$t('settings.placeholder_new1_password')"
  19. allow-clear
  20. >
  21. <template #prefix>
  22. <icon-lock />
  23. </template>
  24. </a-input-password>
  25. </a-form-item>
  26. <a-form-item field="password_new_2" :label="$t('settings.confirm_password')" required>
  27. <a-input-password
  28. v-model="form.password_new_2"
  29. :placeholder="$t('settings.placeholder_new2_password')"
  30. allow-clear
  31. >
  32. <template #prefix>
  33. <icon-lock />
  34. </template>
  35. </a-input-password>
  36. </a-form-item>
  37. <a-form-item>
  38. <div class="setting-password-btn-container">
  39. <a-space>
  40. <a-button class="submit-btn">{{ $t('settings.btn_cancel') }} </a-button>
  41. <a-button
  42. class="submit-btn"
  43. type="primary"
  44. html-type="submit"
  45. :loading="loading"
  46. @click="handleUpdatePassword"
  47. >{{ $t('settings.btn_submit') }}
  48. </a-button>
  49. </a-space>
  50. </div>
  51. </a-form-item>
  52. </a-form>
  53. </div>
  54. </template>
  55. <script setup>
  56. import { ref, reactive, getCurrentInstance, computed } from 'vue';
  57. import { useRouter } from 'vue-router';
  58. import { useI18n } from 'vue-i18n';
  59. import { Message } from '../3rd-libs/arco-vue-libs';
  60. import { changeUserPassword } from '../apis/login';
  61. import { encrypt } from '../utils/jsencrypt';
  62. const router = useRouter();
  63. const i18n = useI18n();
  64. const form = reactive({
  65. password_current: '',
  66. password_new_1: '',
  67. password_new_2: ''
  68. });
  69. const loading = ref(false);
  70. const handleUpdatePassword = () => {
  71. const pre = form.password_current;
  72. const new_1 = form.password_new_1;
  73. const new_2 = form.password_new_2;
  74. if (!pre || !new_1 || !new_2) {
  75. return;
  76. }
  77. if (new_1 !== new_2) {
  78. // console.log('新密码两次输入不一致,请确认后再修改');
  79. const msg = i18n.t('settings.warning_not_match');
  80. Message.error(msg);
  81. return;
  82. }
  83. const pre_pswd = encrypt(pre); // 加密后的旧密码
  84. const new_pswd = encrypt(new_1); // 加密后的新密码
  85. loading.value = true;
  86. changeUserPassword(pre_pswd, new_pswd)
  87. .then((res) => {
  88. // {"code":200,"msg":"user pwd change success","data":{}}
  89. const code = res.code / 1;
  90. if (code === 200) {
  91. // 成功: 清空原先的值
  92. form.password_current = '';
  93. form.password_new_1 = '';
  94. form.password_new_2 = '';
  95. const msg = i18n.t('settings.update_success');
  96. Message.success(msg);
  97. } else {
  98. // 失败
  99. const msg = i18n.t('settings.update_fail');
  100. Message.warning(msg);
  101. }
  102. loading.value = false;
  103. })
  104. .catch((err) => {
  105. console.log(err, 'flag-njsdfjsau345jkdsfljfjsklaj->>');
  106. Message.error(err.msg);
  107. loading.value = false;
  108. });
  109. };
  110. </script>
  111. <style scoped>
  112. .setting-password-btn-container {
  113. display: flex;
  114. justify-content: flex-end;
  115. flex-grow: 1;
  116. }
  117. </style>