forgetPassword.vue 3.7 KB

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