editPassword.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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="$u.throttle(reset, 5000)">重置密码</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. identification: 2,
  96. flag: 2
  97. }).then(res => {
  98. if (res.code == 200) {
  99. uni.hideLoading();
  100. // 这里此提示会被this.start()方法中的提示覆盖
  101. uni.$u.toast('验证码已发送');
  102. // 通知验证码组件内部开始倒计时
  103. this.$refs.uCode.start();
  104. } else {
  105. uni.showToast({
  106. title: res.message,
  107. icon: 'none',
  108. duration: 2000
  109. })
  110. }
  111. })
  112. .catch(res => {
  113. uni.$u.toast(res.message);
  114. });
  115. // setTimeout(() => {
  116. // }, 2000);
  117. } else {
  118. uni.$u.toast('倒计时结束后再发送');
  119. }
  120. } else {
  121. uni.$u.toast('请输入正确手机号');
  122. }
  123. },
  124. //修改密码
  125. reset() {
  126. if (this.registerData.password.length < 6) {
  127. uni.showToast({
  128. title: '密码请输入6-16字符格式',
  129. icon: 'none',
  130. duration: 2000
  131. })
  132. return
  133. }
  134. uni.showLoading({
  135. title: '加载中'
  136. })
  137. this.$refs.registerForm.validate().then(res => {
  138. uni.$u.toast('校验通过')
  139. _this.isLoading = true
  140. _this.registerData.identification = 2
  141. _this.$request.baseRequest('post', '/commonUser/resetPassword', _this.registerData).then(
  142. res => {
  143. // 获得数据
  144. if (res.code == 200) {
  145. uni.clearStorageSync();
  146. this.$request.baseRequest('post', '/auth/api/logout').then(res => {})
  147. this.$store.commit('logout')
  148. // this.$api.logout()
  149. uni.showToast({
  150. title: '修改成功',
  151. icon: 'none',
  152. duration: 2000
  153. })
  154. uni.navigateTo({
  155. url: `/pages/public/login`
  156. })
  157. } else {
  158. uni.showToast({
  159. title: "系统异常或验证码已过期,请退出重试",
  160. icon: 'none',
  161. duration: 2000
  162. })
  163. }
  164. uni.hideLoading()
  165. })
  166. .catch(res => {
  167. uni.$u.toast(res.message)
  168. });
  169. }).catch(errors => {
  170. uni.$u.toast('校验失败')
  171. })
  172. },
  173. },
  174. }
  175. </script>
  176. <style lang="scss">
  177. .content {
  178. background: url(../../../static/images/mine/bg@2x.png);
  179. background-size: 100% 100%;
  180. height: 100vh;
  181. padding-top: 85px;
  182. position: relative;
  183. box-sizing: border-box;
  184. }
  185. .back-btn {
  186. position: absolute;
  187. left: 40upx;
  188. z-index: 9999;
  189. padding-top: var(--status-bar-height);
  190. top: 40upx;
  191. font-size: 40upx;
  192. color: red;
  193. }
  194. .wrapper {
  195. position: relative;
  196. z-index: 90;
  197. padding-bottom: 40upx;
  198. height: 100%;
  199. padding: 0 30px;
  200. }
  201. .code-style {
  202. background: #2772FB;
  203. color: white;
  204. }
  205. .reset {
  206. margin-top: 50rpx;
  207. }
  208. .Semibold {
  209. margin-bottom: 50rpx;
  210. }
  211. .code-small {
  212. width: 200rpx;
  213. height: 60rpx;
  214. font-size: 24rpx;
  215. }
  216. </style>