forgetPassword.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="page">
  3. <uni-nav-bar :fixed="true" background-color="#FFE05C" :border="false" :statusBar="true" left-icon="left" title="找回密码" @clickLeft="back" />
  4. <view :style="{'marginTop':'10rpx'}">
  5. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
  6. <u-form-item :labelWidth="80" label="手机号:" prop="username" ref="item1">
  7. <u--input v-model="form.username" placeholder="请输入手机号"></u--input>
  8. </u-form-item>
  9. <u-form-item :labelWidth="80" label="验证码:" prop="code" ref="item1">
  10. <view class="inputCode">
  11. <u--input v-model="form.code" placeholder="请输入验证码" ></u--input>
  12. </view>
  13. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="small" :disabled="disabled1"></u-button>
  14. </u-form-item>
  15. <u-form-item :labelWidth="80" label="新密码:" prop="newPassword" ref="item1">
  16. <u--input v-model="form.newPassword" placeholder="请输入新密码" type="password"></u--input>
  17. </u-form-item>
  18. <u-form-item :labelWidth="80" label="确认密码:" prop="againPassword" ref="item1">
  19. <u--input v-model="form.againPassword" placeholder="再次确认新密码" type="password"></u--input>
  20. </u-form-item>
  21. </u--form>
  22. <view :style="{'marginTop':'100rpx'}">
  23. <button class="customStyle" @click="retrievePassword">提交</button>
  24. </view>
  25. </view>
  26. <u-code ref="uCode" @change="codeChange" seconds="60" @start="disabled1 = true" @end="disabled1 = false"></u-code>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. disabled1:false,
  34. tips:'',
  35. form:{
  36. username:'',
  37. code:'',
  38. newPassword:'',
  39. againPassword:''
  40. },
  41. rules: {
  42. 'username': {
  43. type: 'string',
  44. required: true,
  45. min:11,
  46. max: 11,
  47. pattern:this.$phonePattern,
  48. message: '请输入正确的电话号码',
  49. trigger: ['blur', 'change']
  50. },
  51. 'code': {
  52. type: 'string',
  53. required: true,
  54. min:4,
  55. max: 6,
  56. message: '请输入验证码',
  57. trigger: ['blur', 'change']
  58. },
  59. 'newPassword': {
  60. type: 'string',
  61. min:6,
  62. max: 16,
  63. required: true,
  64. message: '请输入6-18位密码',
  65. trigger: ['blur', 'change']
  66. },
  67. 'againPassword': {
  68. type: 'string',
  69. min:6,
  70. max: 16,
  71. required: true,
  72. message: '请输入6-18位密码',
  73. trigger: ['blur', 'change']
  74. }
  75. },
  76. }
  77. },
  78. methods: {
  79. retrievePassword(){
  80. this.$refs.uForm.validate().then(res => {
  81. this.$api.login.retrievePassword(this.form).then(res=>{
  82. uni.showToast({
  83. icon: 'success',
  84. duration: 2000,
  85. title: '修改成功,即将跳转登录页'
  86. });
  87. setTimeout(()=>{
  88. this.logout()
  89. },2000)
  90. })
  91. })
  92. },
  93. logout(){
  94. this.$api.login.logout().then(res=>{
  95. uni.clearStorageSync();
  96. uni.navigateTo({
  97. url:'/pages/login/login'
  98. })
  99. })
  100. },
  101. back(){
  102. uni.navigateBack({
  103. delta: 1
  104. });
  105. },
  106. codeChange(text) {
  107. this.tips = text;
  108. },
  109. getCode() {
  110. let regExp=new RegExp(this.$phonePattern);
  111. let b= regExp.test(this.form.username)
  112. if (!b){
  113. uni.$u.toast('请输入正确的手机号')
  114. return
  115. }
  116. if (this.$refs.uCode.canGetCode) {
  117. // 模拟向后端请求验证码
  118. uni.showLoading({
  119. title: '正在获取验证码'
  120. })
  121. this.$api.service.getSmsCode({phonenumber: this.form.username}).then(res=>{
  122. uni.hideLoading();
  123. // 这里此提示会被this.start()方法中的提示覆盖
  124. uni.$u.toast('验证码已发送');
  125. // 通知验证码组件内部开始倒计时
  126. this.$refs.uCode.start();
  127. })
  128. } else {
  129. uni.$u.toast('倒计时结束后再发送');
  130. }
  131. },
  132. }
  133. }
  134. </script>
  135. <style lang="scss" scoped>
  136. @import './index.rpx.css';
  137. </style>