editPassword.vue 5.0 KB

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