editPassword.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="u-page content">
  3. <u-icon class="back-btn" name="arrow-left" color="black" size="20" @click="navBack"></u-icon>
  4. <view class="wrapper">
  5. <h2 class="Semibold">重置密码</h2>
  6. <u--form labelPosition="left" :model="registerData" ref="registerForm" labelWidth="80">
  7. <u-form-item label="手机号" prop="phone" borderBottom>
  8. <u--input v-model="registerData.phone" border="none" maxlength="11" placeholder="请输入手机号码">
  9. </u--input>
  10. </u-form-item>
  11. <u-form-item label="验证码" prop="code" borderBottom>
  12. <u--input v-model="registerData.verifyCode" border="none" placeholder="请填写验证码"></u--input>
  13. <button :disabled="disabled1" class="code-style code-small" @tap="getCode">{{tips}}</button>
  14. </u-form-item>
  15. <u-form-item label="新密码" prop="password" borderBottom>
  16. <u--input v-model="registerData.password" border="none" placeholder="请输入新密码,6-16位字符"></u--input>
  17. </u-form-item>
  18. <u-code ref="uCode" @change="codeChange" seconds="60" @start="disabled1 = true"
  19. @end="disabled1 = false">
  20. </u-code>
  21. </u--form>
  22. <button class="code-style reset" @click="reset">重置密码</button>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. mapState
  29. } from 'vuex';
  30. var _this;
  31. import helper from '@/common/helper.js';
  32. export default {
  33. data() {
  34. return {
  35. disabled1: false,
  36. tips: '',
  37. registerData: {
  38. phone: '',
  39. password: '',
  40. verifyCode: '',
  41. },
  42. rules: {
  43. phone: {
  44. type: 'string',
  45. required: true,
  46. len: 11,
  47. message: '请填写11位手机号',
  48. trigger: ['blur']
  49. },
  50. verifyCode: {
  51. type: 'string',
  52. required: true,
  53. len: 6,
  54. message: '请填写6位验证码',
  55. trigger: ['blur']
  56. },
  57. }
  58. }
  59. },
  60. computed: {
  61. ...mapState(['hasLogin', 'userInfo']),
  62. // 手机号中间4位加*
  63. // starUserphone() {
  64. // let reg = /^(\d{3})\d{4}(\d{4})$/;
  65. // if (this.userphone) {
  66. // return this.userphone.replace(reg, "$1****$2");
  67. // }
  68. // }
  69. },
  70. onReady() {
  71. // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
  72. this.$refs.registerForm.setRules(this.rules)
  73. },
  74. onLoad() {
  75. _this = this
  76. this.registerData.phone = this.userInfo.phone
  77. },
  78. methods: {
  79. navBack() {
  80. uni.navigateBack();
  81. },
  82. codeChange(text) {
  83. this.tips = text;
  84. },
  85. // 获取验证码
  86. getCode() {
  87. if (/^0?1[3|4|5|6|7|8][0-9]\d{8}$/.test(this.registerData.phone)) {
  88. if (this.$refs.uCode.canGetCode) {
  89. // 模拟向后端请求验证码
  90. uni.showLoading({
  91. title: '正在获取验证码'
  92. })
  93. _this.$request.baseRequest('get', '/commonUser/sendVerifyCode', {
  94. phone: this.registerData.phone
  95. }).then(res => {
  96. uni.hideLoading();
  97. // 这里此提示会被this.start()方法中的提示覆盖
  98. uni.$u.toast('验证码已发送');
  99. // 通知验证码组件内部开始倒计时
  100. this.$refs.uCode.start();
  101. })
  102. .catch(res => {
  103. uni.$u.toast(res.message);
  104. });
  105. // setTimeout(() => {
  106. // }, 2000);
  107. } else {
  108. uni.$u.toast('倒计时结束后再发送');
  109. }
  110. } else {
  111. uni.$u.toast('请输入正确手机号');
  112. }
  113. },
  114. //修改密码
  115. reset() {
  116. uni.showLoading({
  117. title: '加载中'
  118. })
  119. this.$refs.registerForm.validate().then(res => {
  120. uni.$u.toast('校验通过')
  121. _this.isLoading = true
  122. _this.registerData.identification = 2
  123. _this.$request.baseRequest('post', '/commonUser/resetPassword', _this.registerData).then(
  124. res => {
  125. // 获得数据
  126. if (res.code == 200) {
  127. uni.clearStorageSync();
  128. this.$request.baseRequest('post', '/auth/api/logout').then(res => {
  129. })
  130. this.$store.commit('logout')
  131. // this.$api.logout()
  132. uni.showToast({
  133. title: '修改成功',
  134. icon: 'none',
  135. duration: 2000
  136. })
  137. uni.navigateTo({
  138. url: `/pages/public/login`
  139. })
  140. } else {
  141. uni.showToast({
  142. title: "系统异常或验证码已过期,请退出重试",
  143. icon: 'none',
  144. duration: 2000
  145. })
  146. }
  147. uni.hideLoading()
  148. })
  149. .catch(res => {
  150. uni.$u.toast(res.message)
  151. });
  152. }).catch(errors => {
  153. uni.$u.toast('校验失败')
  154. })
  155. },
  156. },
  157. }
  158. </script>
  159. <style lang="scss">
  160. .content {
  161. background: url(../../../static/images/mine/bg@2x.png);
  162. background-size: 100% 100%;
  163. height: 100vh;
  164. padding-top: 85px;
  165. position: relative;
  166. }
  167. .back-btn {
  168. position: absolute;
  169. left: 40upx;
  170. z-index: 9999;
  171. padding-top: var(--status-bar-height);
  172. top: 40upx;
  173. font-size: 40upx;
  174. color: red;
  175. }
  176. .wrapper {
  177. position: relative;
  178. z-index: 90;
  179. padding-bottom: 40upx;
  180. height: 100%;
  181. padding: 0 30px;
  182. }
  183. .code-style {
  184. background: #2772FB;
  185. color: white;
  186. }
  187. .reset {
  188. margin-top: 50rpx;
  189. }
  190. .Semibold {
  191. margin-bottom: 50rpx;
  192. }
  193. .code-small {
  194. width: 200rpx;
  195. height: 60rpx;
  196. font-size: 24rpx;
  197. }
  198. </style>