index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view>
  3. <!-- #ifdef H5 -->
  4. <view style="color: #fff;">
  5. <tn-nav-bar :bottomShadow="false" backgroundColor="#26B3A0">{{from=='set'?'修改密码':'找回密码'}}</tn-nav-bar>
  6. <view :style="{height: tobheight+'px'}"></view>
  7. </view>
  8. <!-- #endif -->
  9. <view class="container">
  10. <view class="textl_ogin">{{from=='set'?'修改密码':'找回密码'}}</view>
  11. <!-- 账号密码登录 -->
  12. <view class="login">
  13. <view class="input u-flex align-center">
  14. <u-icon name="phone-fill" color="#26B3A0" size="24"></u-icon>
  15. <input class="vs-flex-item" v-model="accountLogin.mobile" :maxlength="11" placeholder="请输入手机号" />
  16. </view>
  17. <view class="input u-flex align-center">
  18. <i class="iconfont icon-yanzhengma" style="color:#26B3A0;font-size: 22px;"></i>
  19. <input class="vs-flex-item" v-model="accountLogin.code" :maxlength="11" placeholder="请输入验证码" />
  20. <view class="" style="width: 250rpx;">
  21. <u-button style="width: 250rpx;" color='#26B3A0' class="custom-style"
  22. @tap="getCode">{{tips}}</u-button>
  23. </view>
  24. </view>
  25. <view class="input u-flex align-center">
  26. <u-icon name="lock-fill" color="#26B3A0" size="24"></u-icon>
  27. <input class="vs-flex-item" type="text" :password="password" v-model="accountLogin.password"
  28. placeholder="请输入新密码" placeholder-class="input-placeholder" />
  29. <u-icon @click="password = !password" :name="password ? 'eye-off' : 'eye-fill'" color="#26B3A0"
  30. size="18"></u-icon>
  31. </view>
  32. </view>
  33. <view @click="changePwd()" hover-class="hoversubmit" class="signinnow">{{from=='set'?'修改':'找回'}}
  34. </view>
  35. </view>
  36. <view class="wrap">
  37. <u-toast ref="uToast"></u-toast>
  38. <u-code :seconds="seconds" @end="" @start="" ref="uCode" @change="codeChange"></u-code>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import {
  44. mapMutations,
  45. mapActions,
  46. mapState,
  47. mapGetters
  48. } from 'vuex';
  49. import {
  50. sendCode,
  51. forgetPwd
  52. } from '@/api/my/index.js'
  53. export default {
  54. data() {
  55. return {
  56. tips: '',
  57. // refCode: null,
  58. seconds: 60,
  59. password: true,
  60. accountLogin: {
  61. mobile: '',
  62. password: '',
  63. code: ''
  64. },
  65. tobheight: 45,
  66. platform: this.$platform.get(),
  67. userList: [{
  68. title: '更换手机号',
  69. icon: 'account-fill',
  70. path: 'collect-list',
  71. url: '/pages/user/public/agreement?type=aboutus',
  72. },
  73. {
  74. title: '修改密码',
  75. icon: 'question-circle-fill',
  76. path: 'collect-list',
  77. url: '/pages/user/public/agreement?type=use'
  78. }
  79. ],
  80. from: 'set'
  81. }
  82. },
  83. computed: {
  84. // ...mapGetters(['appInfo'])
  85. },
  86. onLoad(o) {
  87. this.from = o.from
  88. if (this.from == 'login') {
  89. uni.setNavigationBarTitle({
  90. title: '找回密码'
  91. })
  92. }
  93. },
  94. methods: {
  95. codeChange(text) {
  96. this.tips = text;
  97. },
  98. async changePwd() {
  99. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  100. if (!this.accountLogin.mobile) {
  101. uni.showToast({
  102. title: '请输入手机号',
  103. icon: 'none'
  104. })
  105. return;
  106. }
  107. if (!phoneReg.test(this.accountLogin.mobile)) {
  108. uni.showToast({
  109. title: '手机号不合法',
  110. icon: 'none'
  111. })
  112. return
  113. }
  114. if (!this.showlogon && !this.accountLogin.code) {
  115. uni.showToast({
  116. title: '请输入验证码',
  117. icon: 'none'
  118. })
  119. return
  120. }
  121. if (!this.accountLogin.password) {
  122. uni.showToast({
  123. title: '请输入新密码',
  124. icon: 'none'
  125. })
  126. return;
  127. }
  128. if (!uni.$u.test.rangeLength(this.accountLogin.password, [6, 12])) {
  129. uni.showToast({
  130. title: '密码长度为6至12位',
  131. icon: 'none'
  132. })
  133. return;
  134. }
  135. if (/.*[\u4e00-\u9fa5]+.*$/.test(this.accountLogin.password)) {
  136. uni.showToast({
  137. title: '密码不能含有汉字',
  138. icon: 'none'
  139. })
  140. return;
  141. }
  142. if (!uni.$u.test.enOrNum(this.accountLogin.password)) {
  143. uni.showToast({
  144. title: '密码只能是字母和数字',
  145. icon: 'none'
  146. })
  147. return;
  148. }
  149. // if (this.from == 'set') {
  150. console.log('修改密码参数', {
  151. mobile: this.accountLogin.mobile,
  152. password: this.accountLogin.password,
  153. code: this.accountLogin.code
  154. });
  155. let res = await forgetPwd({
  156. mobile: this.accountLogin.mobile,
  157. password: this.accountLogin.password,
  158. code: this.accountLogin.code
  159. })
  160. console.log('修改密码返回值', res);
  161. if (res.code == 0) {
  162. uni.showToast({
  163. title: '修改密码成功',
  164. icon: 'none'
  165. })
  166. setTimeout(function() {
  167. uni.navigateBack()
  168. }, 1000);
  169. }
  170. // } else {
  171. // }
  172. },
  173. async getCode() {
  174. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  175. if (!this.accountLogin.mobile) {
  176. uni.showToast({
  177. title: '请输入手机号',
  178. icon: 'none'
  179. })
  180. return;
  181. }
  182. if (!phoneReg.test(this.accountLogin.mobile)) {
  183. uni.showToast({
  184. title: '手机号不合法',
  185. icon: 'none'
  186. })
  187. return
  188. }
  189. let res = await sendCode({
  190. mobile: this.accountLogin.mobile
  191. })
  192. console.log('验证码返回值', res);
  193. if (res.code == 0) {
  194. if (this.$refs.uCode.canGetCode) {
  195. // 模拟向后端请求验证码
  196. uni.showLoading({
  197. title: '正在获取验证码'
  198. })
  199. setTimeout(() => {
  200. uni.hideLoading();
  201. // 这里此提示会被this.start()方法中的提示覆盖
  202. uni.$u.toast('验证码已发送');
  203. // 通知验证码组件内部开始倒计时
  204. this.$refs.uCode.start();
  205. }, 2000);
  206. } else {
  207. uni.$u.toast('倒计时结束后再发送');
  208. }
  209. } else {
  210. uni.hideLoading();
  211. uni.$u.toast(res.msg);
  212. }
  213. },
  214. }
  215. }
  216. </script>
  217. <style lang="scss">
  218. @import './index.scss';
  219. </style>