editPassword.vue 6.3 KB

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