changePassword.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <!-- 修改密码 -->
  3. <div class="changePassword flex-col">
  4. <s-header :name="$t('changePassword.changePassword')" :noback="false"></s-header>
  5. <div class="changePasswordFormBox">
  6. <van-form @submit="changePasswordSubmit">
  7. <van-field v-model="password" name="password" type="password" :label="$t('changePassword.passwordLabel')"
  8. :placeholder="$t('changePassword.passwordPlaceholder')"
  9. :rules="[
  10. { required: true, message: $t('changePassword.passwordRequired') },
  11. { pattern: /^(?=.*[a-zA-Z])(?=.*\d).{10,}$/, message: $t('register.passwordPattern') }
  12. ]" />
  13. <br>
  14. <van-field v-model="passwordCheck" name="passwordCheck" type="password"
  15. :label="$t('changePassword.passwordCheckLabel')" :placeholder="$t('changePassword.passwordCheckPlaceholder')"
  16. :rules="[{ required: true, message: $t('changePassword.passwordCheckRequired') }]" />
  17. <van-button round type="primary" class="register" native-type="submit">{{ $t('changePassword.registerButton') }}
  18. </van-button>
  19. </van-form>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import md5 from 'js-md5';
  25. import { ref } from 'vue';
  26. import { showToast, showFailToast } from 'vant';
  27. import sHeader from "@/components/SimpleHeader";
  28. import { useRouter, useRoute } from "vue-router";
  29. import { updatePassword } from '@/service/changePassword';
  30. import { useI18n } from 'vue-i18n';
  31. import { styleUrl } from '../common/js/utils';
  32. import { getLoginUser } from "@/common/js/utils";
  33. export default {
  34. setup() {
  35. // 引入语言
  36. const { t } = useI18n();
  37. const router = useRouter();
  38. const route = useRoute();
  39. const user = getLoginUser();
  40. const password = ref('');
  41. const passwordCheck = ref('');
  42. // 加载样式
  43. styleUrl('changePassword');
  44. // 验证-表单
  45. const changePasswordSubmit = async () => {
  46. if (password.value !== passwordCheck.value) {
  47. showFailToast(t('changePassword.inconsistentPasswords'));
  48. return false;
  49. }
  50. const { data } = await updatePassword({
  51. username: route.query.name || user.username,
  52. // username: user.username,
  53. password: md5(password.value)
  54. });
  55. if (data.code === '00000') {
  56. showToast(t('changePassword.pwdEditSucess'));
  57. router.push({ path: '/login' });
  58. } else {
  59. showFailToast(data.message);
  60. }
  61. };
  62. return {
  63. password,
  64. passwordCheck,
  65. changePasswordSubmit
  66. };
  67. },
  68. components: { sHeader },
  69. };
  70. </script>
  71. <style lang="less" scoped>
  72. @import "../common/style/mixin";
  73. </style>