forgetPassword.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view style="padding-top: 40rpx;">
  3. <veiw class="log">
  4. <view class="form-items">
  5. <u-icon name="account" color="#666" size="24" ></u-icon>
  6. <input
  7. type="number"
  8. v-model="phone"
  9. style="flex: 1;margin-left: 16rpx;"
  10. placeholder="手机号"
  11. maxlength="11"/>
  12. </view>
  13. <view class="form-items">
  14. <u-icon name="lock" color="#666" size="24" ></u-icon>
  15. <input
  16. type="password"
  17. v-model="password"
  18. style="flex: 1;margin-left: 16rpx;"
  19. placeholder="密码(6-15个字符)"
  20. maxlength="15"/>
  21. </view>
  22. <view class="form-items codeitem">
  23. <view style="display: flex;justify-content: flex-start; align-items: center;">
  24. <u-icon name="lock" color="#666" size="24"></u-icon>
  25. <input
  26. type="number"
  27. v-model="code"
  28. style="flex: 1;margin-left: 16rpx;"
  29. placeholder="验证码"
  30. maxlength="11"/>
  31. </view>
  32. <view
  33. class="captcha-btn"
  34. :disabled="countdown > 0 || !isPhoneValid"
  35. @click="sendSMcode"
  36. >
  37. {{ countdown > 0 ? `${countdown}s后重试` : '获取验证码' }}
  38. </view>
  39. </view>
  40. <view class="submitlog" @click="submitlogs">设置新密码</view>
  41. </veiw>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. data() {
  47. return {
  48. phone:'',
  49. password:'',
  50. code: '', // 验证码
  51. countdown: 0, // 倒计时
  52. timer: null // 定时器
  53. }
  54. },
  55. computed: {
  56. // 手机号格式验证
  57. isPhoneValid() {
  58. return /^1[3-9]\d{9}$/.test(this.phone)
  59. }
  60. },
  61. methods: {
  62. // 校验密码
  63. validatePassword() {
  64. return /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/.test(this.password);
  65. },
  66. sendSMcode(){
  67. if (!this.isPhoneValid) {
  68. return uni.showToast({ title: '手机号格式错误', icon: 'none' })
  69. }
  70. // 显示加载状态
  71. uni.showLoading({ title: '发送中...', mask: true })
  72. this.startCountdown()
  73. },
  74. // 开始倒计时
  75. startCountdown() {
  76. this.countdown = 60
  77. this.timer = setInterval(() => {
  78. if (this.countdown <= 0) {
  79. clearInterval(this.timer)
  80. return
  81. }
  82. this.countdown--
  83. uni.hideLoading();
  84. }, 1000)
  85. },
  86. // 组件销毁时清除定时器
  87. beforeDestroy() {
  88. if (this.timer) clearInterval(this.timer)
  89. },
  90. submitlogs(){
  91. if(!this.phone){
  92. return uni.showToast({ title: '请输入手机号', icon: 'none' })
  93. }
  94. if (!this.isPhoneValid) {
  95. return uni.showToast({ title: '手机号格式错误', icon: 'none' })
  96. }
  97. if(!this.password){
  98. return uni.showToast({ title: '请输入密码', icon: 'none' })
  99. }
  100. if (!this.validatePassword()) {
  101. return uni.showToast({ title: '密码格式不正确', icon: 'none' })
  102. }
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped lang="scss">
  108. .log{
  109. background: #fff ;
  110. width: calc(100% - 20rpx);
  111. margin: 10rpx ;
  112. padding: 20rpx 0;
  113. border-radius: 20rpx;
  114. display: flex;
  115. flex-direction: column;
  116. .form-items{
  117. background: #fff ;
  118. display: flex;
  119. align-items: center;
  120. padding: 28rpx 0;
  121. margin: 0 20rpx;
  122. border-bottom: #eee solid 2rpx;
  123. }
  124. }
  125. .submitlog{
  126. background: linear-gradient(135deg, #38e663 0%, #018C39 100%);
  127. border-radius: 80rpx;
  128. color: #fff;
  129. margin: 0 auto;
  130. width: 80%;
  131. padding: 20rpx 0;
  132. text-align: center;
  133. margin-top: 40rpx;
  134. }
  135. .captcha-btn {
  136. width: 160rpx;
  137. height: 60rpx;
  138. line-height: 60rpx;
  139. border-radius: 8rpx;
  140. background: linear-gradient(135deg, #38e663 0%, #018C39 100%);
  141. color: #fff;
  142. text-align: center;
  143. font-size: 28rpx;
  144. &[disabled] {
  145. background-color: #a2d7ff ;
  146. color: #fff;
  147. }
  148. }
  149. .codeitem{
  150. display: flex;
  151. justify-content: space-between;
  152. align-items: center;
  153. flex: 1;
  154. }
  155. </style>