You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

forget-pwd-step2.vue 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <!-- 注册第2步 -->
  2. <template>
  3. <view class="register-main">
  4. <view class="title">请输入验证码</view>
  5. <view class="hint">验证码已发送至:{{ phone }}</view>
  6. <view class="input-code">
  7. <verification-code-input v-model="code"></verification-code-input>
  8. </view>
  9. <view class="hint2">
  10. <view class="green">{{ codeDuration === 0 ? "" : codeDuration }}</view>
  11. <view class="grey" @click="sendRegisterCode">{{
  12. codeDuration === 0 ? "重新发送验证码" : "秒后可重新发送验证码"
  13. }}</view>
  14. </view>
  15. </view>
  16. <!-- <view class="btn">
  17. <submit-button title="下一步" @submit="nextStep"></submit-button>
  18. </view> -->
  19. <view class="register-main">
  20. <!-- <view class="title">重置密码</view>
  21. <view class="hint">重置之前的密码,设置新密码</view> -->
  22. <view class="hint1">请输入密码</view>
  23. <view class="form-input">
  24. <input class="input" v-model="state.password" placeholder="请输入密码" placeholder-class="form-placeholder"
  25. :password="state.isPwdType ? true : false" type="text" />
  26. <image :src="`${$imgUrl}login/${
  27. state.isPwdType ? 'icon_eye_close' : 'icon_eye_open'
  28. }.png`" class="eye" @click="state.isPwdType = !state.isPwdType" mode="aspectFill"></image>
  29. </view>
  30. <view class="hint2">请再次输入密码</view>
  31. <view class="form-input">
  32. <input class="input" v-model="state.affirmPassword" placeholder="请再次输入密码"
  33. placeholder-class="form-placeholder" :password="state.isAffirmPwdType ? true : false" type="text" />
  34. <image :src="`${$imgUrl}login/${
  35. state.isAffirmPwdType ? 'icon_eye_close' : 'icon_eye_open'
  36. }.png`" class="eye" @click="state.isAffirmPwdType = !state.isAffirmPwdType" mode="aspectFill"></image>
  37. </view>
  38. <view class="hint4">{{ state.pwdHint }}</view>
  39. </view>
  40. <view class="btn">
  41. <submit-button title="确认更改" @submit="doResetPwd"></submit-button>
  42. </view>
  43. </template>
  44. <script setup lang="ts">
  45. import { msg, navTo, confirm, checkStr } from "@/utils/utils";
  46. import { onLoad } from "@dcloudio/uni-app";
  47. import { reactive } from "vue";
  48. import { ref } from "vue";
  49. import { request,requestNew } from "@/utils/network/request";
  50. import { sendMessage, resetPwd } from "@/utils/network/api.js";
  51. //上个界面传递的电话号码
  52. const phone = ref("");
  53. const code = ref(null);
  54. //倒计时时常
  55. const codeDuration = ref(0);
  56. let interval = null;
  57. const state = reactive({
  58. isPwdType: true,
  59. isAffirmPwdType: true,
  60. password: "", //密码
  61. affirmPassword: "",//再次输入密码
  62. phone: "", //手机号
  63. code: "", //验证码
  64. pwdHint: "密码不少于10位,必须同时包含数字、大小写字母和特殊符号,不能使用3个连续字符",
  65. });
  66. onLoad((options) => {
  67. phone.value = options.phone;
  68. codeInterval();
  69. });
  70. /* 验证码倒计时 */
  71. const codeInterval = () => {
  72. codeDuration.value = 60;
  73. interval = setInterval(() => {
  74. codeDuration.value--;
  75. if (codeDuration.value === 0) {
  76. if (interval) {
  77. clearInterval(interval);
  78. interval = null;
  79. }
  80. }
  81. }, 1000);
  82. };
  83. /* 发送验证码 */
  84. const sendRegisterCode = () => {
  85. if (codeDuration.value !== 0) {
  86. return;
  87. }
  88. const options = {
  89. type: 2,
  90. data: { mobile: phone.value },
  91. method: "POST",
  92. showLoading: true,
  93. };
  94. requestNew(sendMessage, options).then((res) => {
  95. msg("验证码发送成功!");
  96. codeInterval();
  97. });
  98. };
  99. /* 下一步 */
  100. const nextStep = () => {
  101. if (!code.value) {
  102. msg("请先输入验证码!");
  103. return;
  104. }
  105. navTo(`/login/forget-pwd-step3?phone=${phone.value}&code=${code.value}`);
  106. };
  107. /* 忘记密码 */
  108. const doResetPwd = () => {
  109. if (!code.value) {
  110. msg("请先输入验证码!");
  111. return;
  112. }
  113. if (!state.password) {
  114. msg("请输入密码");
  115. return;
  116. }
  117. if (!state.affirmPassword) {
  118. msg("请再次输入密码");
  119. return;
  120. }
  121. if (state.password !== state.affirmPassword) {
  122. msg("两次密码输入不一致,请重新输入!");
  123. return;
  124. }
  125. const options = {
  126. type: 2,
  127. data: {
  128. password: state.password,
  129. affirmPassword: state.affirmPassword,
  130. mobile: phone.value,
  131. verificationCode: code.value,
  132. },
  133. method: "POST",
  134. showLoading: true,
  135. };
  136. requestNew(resetPwd, options).then((res) => {
  137. confirm(
  138. "密码重置成功,请登录!",
  139. () => {
  140. uni.$emit("login", { phone: phone.value });
  141. uni.navigateBack({ delta: 2 });
  142. },
  143. "提示",
  144. false
  145. );
  146. });
  147. };
  148. </script>
  149. <style lang="scss" scoped>
  150. .register-main {
  151. border-top: 1rpx solid #dcdcdc;
  152. padding: 78rpx 30rpx 50rpx;
  153. .title {
  154. font-size: 32rpx;
  155. color: #333333;
  156. font-weight: 600;
  157. }
  158. .hint {
  159. font-size: 24rpx;
  160. color: #999999;
  161. margin-top: 20rpx;
  162. }
  163. }
  164. .input-code {
  165. margin: 0 -10rpx 0px;
  166. }
  167. .hint2 {
  168. margin-top: 40rpx;
  169. display: flex;
  170. .green {
  171. font-size: 28rpx;
  172. color: #00b38b;
  173. }
  174. .grey {
  175. font-size: 24rpx;
  176. color: #999999;
  177. margin-left: 16rpx;
  178. }
  179. }
  180. .register-main {
  181. border-top: 1rpx solid #dcdcdc;
  182. padding: 78rpx 30rpx 50rpx;
  183. .title {
  184. font-size: 32rpx;
  185. color: #333333;
  186. font-weight: 600;
  187. }
  188. .hint {
  189. font-size: 24rpx;
  190. color: #999999;
  191. margin-top: 20rpx;
  192. }
  193. .hint1 {
  194. color: #333333;
  195. font-size: 28rpx;
  196. // margin-top: 100rpx;
  197. font-weight: 600;
  198. }
  199. .hint2 {
  200. color: #333333;
  201. font-size: 28rpx;
  202. margin-top: 50rpx;
  203. font-weight: 600;
  204. }
  205. .hint4 {
  206. margin-top: 30rpx;
  207. font-size: 26rpx;
  208. color: #00b38b;
  209. }
  210. }
  211. .form-input {
  212. display: flex;
  213. flex-direction: row;
  214. align-items: center;
  215. height: 90rpx;
  216. margin-top: 30rpx;
  217. border-bottom: 1rpx solid #dcdcdc;
  218. color: #333333;
  219. .input {
  220. flex: 1;
  221. padding-right: 48rpx;
  222. font-size: 26rpx;
  223. background: transparent;
  224. }
  225. .eye {
  226. width: 48rpx;
  227. height: 48rpx;
  228. }
  229. }
  230. .form-placeholder {
  231. color: #999999;
  232. }
  233. .btn {
  234. margin: 80rpx 40px;
  235. }
  236. </style>