forgetPassword.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. tips:'',
  33. form:{
  34. username:'',
  35. code:'',
  36. newPassword:'',
  37. againPassword:''
  38. },
  39. rules: {
  40. 'username': {
  41. type: 'string',
  42. required: true,
  43. min:11,
  44. max: 11,
  45. pattern:this.$phonePattern,
  46. message: '请输入正确的电话号码',
  47. trigger: ['blur', 'change']
  48. },
  49. 'code': {
  50. type: 'string',
  51. required: true,
  52. min:4,
  53. max: 6,
  54. message: '请输入验证码',
  55. trigger: ['blur', 'change']
  56. },
  57. 'newPassword': {
  58. type: 'string',
  59. min:6,
  60. max: 16,
  61. required: true,
  62. message: '请输入6-18位密码',
  63. trigger: ['blur', 'change']
  64. },
  65. 'againPassword': {
  66. type: 'string',
  67. min:6,
  68. max: 16,
  69. required: true,
  70. message: '请输入6-18位密码',
  71. trigger: ['blur', 'change']
  72. }
  73. },
  74. }
  75. },
  76. methods: {
  77. retrievePassword(){
  78. this.$refs.uForm.validate().then(res => {
  79. this.$api.login.retrievePassword(this.form).then(res=>{
  80. uni.showToast({
  81. icon: 'success',
  82. duration: 2000,
  83. title: '修改成功,即将跳转登录页'
  84. });
  85. setTimeout(()=>{
  86. this.logout()
  87. },2000)
  88. })
  89. })
  90. },
  91. logout(){
  92. this.$api.login.logout().then(res=>{
  93. uni.clearStorageSync();
  94. uni.navigateTo({
  95. url:'/pages/login/login'
  96. })
  97. })
  98. },
  99. back(){
  100. uni.navigateBack({
  101. delta: 1
  102. });
  103. },
  104. codeChange(text) {
  105. this.tips = text;
  106. },
  107. getCode() {
  108. if (this.$refs.uCode.canGetCode) {
  109. // 模拟向后端请求验证码
  110. uni.showLoading({
  111. title: '正在获取验证码'
  112. })
  113. this.$api.service.getSmsCode({phonenumber: this.form.username}).then(res=>{
  114. uni.hideLoading();
  115. // 这里此提示会被this.start()方法中的提示覆盖
  116. uni.$u.toast('验证码已发送');
  117. // 通知验证码组件内部开始倒计时
  118. this.$refs.uCode.start();
  119. })
  120. } else {
  121. uni.$u.toast('倒计时结束后再发送');
  122. }
  123. },
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. @import './index.rpx.css';
  129. </style>