reset-password.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!-- 重置密码 - resetPassword-- -->
  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="resetPasswordRef"
  12. v-model="state.model"
  13. :rules="state.rules"
  14. validateTrigger="bind"
  15. labelWidth="140"
  16. labelAlign="center"
  17. >
  18. <uni-forms-item name="mobile" label="手机号">
  19. <uni-easyinput
  20. placeholder="请输入手机号"
  21. v-model="state.model.mobile"
  22. type="number"
  23. :inputBorder="false"
  24. >
  25. <template v-slot:right>
  26. <button
  27. class="ss-reset-button code-btn code-btn-start"
  28. :disabled="state.isMobileEnd"
  29. :class="{ 'code-btn-end': state.isMobileEnd }"
  30. @tap="getSmsCode('resetPassword', state.model.mobile)"
  31. >
  32. {{ getSmsTimer('resetPassword') }}
  33. </button>
  34. </template>
  35. </uni-easyinput>
  36. </uni-forms-item>
  37. <uni-forms-item name="code" label="验证码">
  38. <uni-easyinput
  39. placeholder="请输入验证码"
  40. v-model="state.model.code"
  41. type="number"
  42. maxlength="6"
  43. :inputBorder="false"
  44. ></uni-easyinput>
  45. </uni-forms-item>
  46. <uni-forms-item name="password" label="密码">
  47. <uni-easyinput
  48. type="password"
  49. placeholder="请输入密码"
  50. v-model="state.model.password"
  51. :inputBorder="false"
  52. >
  53. <template v-slot:right>
  54. <button class="ss-reset-button login-btn-start" @tap="resetPasswordSubmit">
  55. 确认
  56. </button>
  57. </template>
  58. </uni-easyinput>
  59. </uni-forms-item>
  60. </uni-forms>
  61. <button v-if="!isLogin" class="ss-reset-button type-btn" @tap="showAuthModal('accountLogin')">
  62. 返回登录
  63. </button>
  64. </view>
  65. </template>
  66. <script setup>
  67. import { computed, watch, ref, reactive, unref } from 'vue';
  68. import sheep from '@/sheep';
  69. import { code, mobile, password } from '@/sheep/validate/form';
  70. import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
  71. const resetPasswordRef = ref(null);
  72. const isLogin = computed(() => sheep.$store('user').isLogin);
  73. // 数据
  74. const state = reactive({
  75. isMobileEnd: false, // 手机号输入完毕
  76. model: {
  77. mobile: '', //手机号
  78. code: '', //验证码
  79. password: '', //密码
  80. },
  81. rules: {
  82. code,
  83. mobile,
  84. password,
  85. },
  86. });
  87. // 4.重置密码
  88. const resetPasswordSubmit = async () => {
  89. const validate = await unref(resetPasswordRef)
  90. .validate()
  91. .catch((error) => {
  92. console.log('error: ', error);
  93. });
  94. if (!validate) return;
  95. sheep.$api.user.resetPassword(state.model).then((res) => {
  96. if (res.error === 0) {
  97. sheep.$store('user').getInfo();
  98. closeAuthModal();
  99. }
  100. });
  101. };
  102. </script>
  103. <style lang="scss" scoped>
  104. @import '../index.scss';
  105. </style>