editPassword.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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,flag:2
  96. }).then(res => {
  97. if(res.code==200){
  98. uni.hideLoading();
  99. // 这里此提示会被this.start()方法中的提示覆盖
  100. uni.$u.toast('验证码已发送');
  101. // 通知验证码组件内部开始倒计时
  102. this.$refs.uCode.start();
  103. }else{
  104. uni.showToast({
  105. title: res.message,
  106. icon: 'none',
  107. duration: 2000
  108. })
  109. }
  110. })
  111. .catch(res => {
  112. uni.$u.toast(res.message);
  113. });
  114. // setTimeout(() => {
  115. // }, 2000);
  116. } else {
  117. uni.$u.toast('倒计时结束后再发送');
  118. }
  119. } else {
  120. uni.$u.toast('请输入正确手机号');
  121. }
  122. },
  123. //修改密码
  124. reset() {
  125. if (this.registerData.password.length < 6) {
  126. uni.showToast({
  127. title: '密码请输入6-16字符格式',
  128. icon: 'none',
  129. duration: 2000
  130. })
  131. return
  132. }
  133. uni.showLoading({
  134. title: '加载中'
  135. })
  136. this.$refs.registerForm.validate().then(res => {
  137. uni.$u.toast('校验通过')
  138. _this.isLoading = true
  139. _this.registerData.identification = 2
  140. _this.$request.baseRequest('post', '/commonUser/resetPassword', _this.registerData).then(
  141. res => {
  142. // 获得数据
  143. if (res.code == 200) {
  144. uni.clearStorageSync();
  145. this.$request.baseRequest('post', '/auth/api/logout').then(res => {
  146. })
  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. }
  184. .back-btn {
  185. position: absolute;
  186. left: 40upx;
  187. z-index: 9999;
  188. padding-top: var(--status-bar-height);
  189. top: 40upx;
  190. font-size: 40upx;
  191. color: red;
  192. }
  193. .wrapper {
  194. position: relative;
  195. z-index: 90;
  196. padding-bottom: 40upx;
  197. height: 100%;
  198. padding: 0 30px;
  199. }
  200. .code-style {
  201. background: #2772FB;
  202. color: white;
  203. }
  204. .reset {
  205. margin-top: 50rpx;
  206. }
  207. .Semibold {
  208. margin-bottom: 50rpx;
  209. }
  210. .code-small {
  211. width: 200rpx;
  212. height: 60rpx;
  213. font-size: 24rpx;
  214. }
  215. </style>