change-password.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!-- 修改密码 - changePassword -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <view class="head-box ss-m-b-60">
  6. <view class="head-title ss-m-b-20">修改密码</view>
  7. <view class="head-subtitle">如密码丢失或未设置,请点击忘记密码重新设置</view>
  8. </view>
  9. <!-- 表单项 -->
  10. <uni-forms
  11. ref="changePasswordRef"
  12. v-model="state.model"
  13. :rules="state.rules"
  14. validateTrigger="bind"
  15. labelWidth="140"
  16. labelAlign="center"
  17. >
  18. <uni-forms-item name="oldPassword" label="旧密码">
  19. <uni-easyinput
  20. placeholder="请输入旧密码"
  21. v-model="state.model.oldPassword"
  22. type="text"
  23. :inputBorder="false"
  24. />
  25. </uni-forms-item>
  26. <uni-forms-item name="newPassword" label="新密码">
  27. <uni-easyinput
  28. type="password"
  29. placeholder="请输入新密码"
  30. v-model="state.model.newPassword"
  31. :inputBorder="false"
  32. />
  33. </uni-forms-item>
  34. <uni-forms-item name="reNewPassword" label="确认密码">
  35. <uni-easyinput
  36. type="password"
  37. placeholder="请重新输入您的新密码"
  38. v-model="state.model.reNewPassword"
  39. :inputBorder="false"
  40. >
  41. <template v-slot:right>
  42. <button class="ss-reset-button login-btn-start" @tap="changePasswordSubmit">
  43. 确认
  44. </button>
  45. </template>
  46. </uni-easyinput>
  47. </uni-forms-item>
  48. </uni-forms>
  49. <view class="editPwd-btn-box ss-m-t-80">
  50. <button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
  51. 忘记密码
  52. </button>
  53. </view>
  54. </view>
  55. </template>
  56. <script setup>
  57. import { computed, watch, ref, reactive, unref } from 'vue';
  58. import sheep from '@/sheep';
  59. import { password } from '@/sheep/validate/form';
  60. import { showAuthModal, closeAuthModal } from '@/sheep/hooks/useModal';
  61. const changePasswordRef = ref(null);
  62. // 数据
  63. const state = reactive({
  64. isMobileEnd: false, // 手机号输入完毕
  65. model: {
  66. oldPassword: '', //旧密码
  67. newPassword: '', //新密码
  68. reNewPassword: '', //确认密码
  69. },
  70. rules: {
  71. oldPassword: password,
  72. newPassword: password,
  73. reNewPassword: {
  74. rules: [
  75. {
  76. required: true,
  77. errorMessage: '请确认密码',
  78. },
  79. {
  80. validateFunction: function (rule, value, data, callback) {
  81. if (value !== state.model.newPassword) {
  82. callback('两次输入的密码不一致');
  83. }
  84. if (value === state.model.oldPassword) {
  85. callback('新密码不能与旧密码相同');
  86. }
  87. return true;
  88. },
  89. },
  90. ],
  91. },
  92. },
  93. });
  94. // 6.更改密码
  95. async function changePasswordSubmit() {
  96. const validate = await unref(changePasswordRef)
  97. .validate()
  98. .catch((error) => {
  99. console.log('error: ', error);
  100. });
  101. if (!validate) return;
  102. sheep.$api.user.changePassword(state.model).then((res) => {
  103. if (res.error === 0) {
  104. sheep.$store('user').getInfo();
  105. closeAuthModal();
  106. }
  107. });
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. @import '../index.scss';
  112. </style>