forget-password.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <s-layout title="忘记密码" :bgStyle="{color:'#fff'}">
  3. <view class="content-block">
  4. <uni-forms ref="resetPasswordRef" v-model="state.model" :rules="state.rules" validateTrigger="bind" labelWidth="140"
  5. labelAlign="left" labelPosition="top">
  6. <uni-forms-item name="mobile" label="手机号">
  7. <view class="input-line">
  8. <uni-easyinput placeholder="请输入手机号" v-model="state.model.mobile" type="number" :inputBorder="false">
  9. </uni-easyinput>
  10. </view>
  11. </uni-forms-item>
  12. <uni-forms-item name="password" label="密码">
  13. <view class="input-line">
  14. <uni-easyinput type="password" placeholder="请输入密码" v-model="state.model.password" :inputBorder="false">
  15. </uni-easyinput>
  16. </view>
  17. </uni-forms-item>
  18. <uni-forms-item name="code" label="验证码">
  19. <view class="ss-flex ss-row-between">
  20. <view class="input-line w-370">
  21. <uni-easyinput placeholder="请输入验证码" v-model="state.model.code" :inputBorder="false" type="number"
  22. maxlength="6">
  23. </uni-easyinput>
  24. </view>
  25. <button class="ss-reset-button code-btn code-btn-start" :disabled="getSmsTimer('resetPassword') != '获取验证码'"
  26. :class="{ 'code-btn-end': getSmsTimer('resetPassword') != '获取验证码' }"
  27. @tap="getSmsCode('resetPassword', state.model.mobile)">
  28. {{ getSmsTimer('resetPassword') }}
  29. </button>
  30. </view>
  31. </uni-forms-item>
  32. </uni-forms>
  33. <button class="ss-reset-button toLoginBtn" @tap="resetPasswordSubmit">
  34. 确认
  35. </button>
  36. </view>
  37. </s-layout>
  38. </template>
  39. <script setup>
  40. import {
  41. computed,
  42. watch,
  43. ref,
  44. reactive,
  45. unref
  46. } from 'vue';
  47. import sheep from '@/sheep';
  48. import {
  49. code,
  50. mobile,
  51. password
  52. } from '@/sheep/validate/form';
  53. import {
  54. getSmsCode,
  55. getSmsTimer
  56. } from '@/sheep/hooks/useModal';
  57. import {Base64} from 'js-base64'
  58. const resetPasswordRef = ref(null);
  59. const isLogin = computed(() => sheep.$store('user').isLogin);
  60. // 数据
  61. const state = reactive({
  62. isMobileEnd: false, // 手机号输入完毕
  63. model: {
  64. mobile: '', //手机号
  65. code: '', //验证码
  66. password: '', //密码
  67. },
  68. rules: {
  69. code,
  70. mobile,
  71. password,
  72. },
  73. });
  74. // 4.重置密码
  75. const resetPasswordSubmit = async () => {
  76. const validate = await unref(resetPasswordRef)
  77. .validate()
  78. .catch((error) => {
  79. console.log('error: ', error);
  80. });
  81. if (!validate) return;
  82. state.model.uuid = sheep.$store('user').getUUID('resetPassword')
  83. console.log(state.model,'model')
  84. const data = Base64.encode(JSON.stringify(state.model))
  85. sheep.$api.user.forgotPassword(data)
  86. .then((res) => {
  87. if (res.code == 200) {
  88. sheep.$helper.toast('修改成功!')
  89. setTimeout(()=>{
  90. uni.navigateBack()
  91. },1500)
  92. // sheep.$store('user').getInfo();
  93. }
  94. })
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. @import '@/sheep/components/s-auth-modal/index.scss';
  99. .content-block {
  100. padding: 0 30rpx;
  101. }
  102. .input-line {
  103. background-color: #F5F7FB;
  104. border-radius: 16rpx;
  105. padding-left: 30rpx;
  106. height: 88rpx;
  107. box-sizing: border-box;
  108. }
  109. .toLoginBtn {
  110. height: 88rpx;
  111. background: #F39801;
  112. border-radius: 16rpx;
  113. color: #fff;
  114. margin-bottom: 32rpx;
  115. margin-top: 30rpx;
  116. }
  117. .w-370 {
  118. width: 370rpx;
  119. }
  120. </style>