forget.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="container">
  3. <view class="" style="text-align: left;padding-left: 30rpx;font-size: 52rpx;padding-top: 50rpx;">{{ $t('login.czmm') }}</view>
  4. <view class="tit">{{ $t('login.yx') }}</view>
  5. <input type="text" class="shuru" :placeholder="$t('login.yx')" v-model="email" />
  6. <view class="tit">{{ $t('login.xmm') }}</view>
  7. <input type="text" class="shuru" :placeholder="$t('login.xmm')" v-model="lpwd" />
  8. <view class="tit">{{ $t('login.yxyzm') }}</view>
  9. <view class="flex" style="width: 673rpx;justify-content: space-between;margin: auto;">
  10. <input type="text" class=" yzm" :placeholder="$t('login.yzm')" v-model="ecode" />
  11. <view class="code yzmbtn" @click="verification">{{ countDown == 0 ? $t('login.yzm') : countDown }}</view>
  12. </view>
  13. <view class="flex" style="justify-content: space-between;padding: 50rpx 30rpx;align-items: flex-start;">
  14. <view class=""></view>
  15. <image src="../../static/icon/goto.png" mode="" style="width: 97rpx;height: 97rpx;" @click="resetpwd()"></image>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import { mapMutations } from 'vuex';
  21. import { verify, loginMobile, getUserInfo, getForget, resetpwd } from '@/api/login.js';
  22. export default {
  23. data() {
  24. return {
  25. ecode: '',
  26. email: '',
  27. lpwd: '',
  28. phone: '', //用户
  29. code: '', //验证码
  30. time: '', //保存倒计时对象
  31. countDown: 0 //倒计时
  32. };
  33. },
  34. onLoad() {
  35. uni.setNavigationBarTitle({ title: this.$t('login.czmm') });
  36. },
  37. watch: {
  38. // 监听倒计时
  39. countDown(i) {
  40. if (i == 0) {
  41. clearInterval(this.time);
  42. }
  43. }
  44. },
  45. methods: {
  46. ...mapMutations('user', ['setUserInfo', 'login']),
  47. resetpwd() {
  48. let obj = this;
  49. if (obj.email == '') {
  50. return obj.$api.msg(this.$t('login.qsryx'));
  51. }
  52. if (!obj.isEmailAvailable(obj.email)) {
  53. return obj.$api.msg(this.$t('login.qsrzqdyx'));
  54. }
  55. if (obj.ecode == '') {
  56. return obj.$api.msg(this.$t('login.qsryzm'));
  57. }
  58. if (obj.lpwd == '') {
  59. return obj.$api.msg(this.$t('login.qsrxmm'));
  60. }
  61. resetpwd({
  62. email: obj.email,
  63. ecode: obj.ecode,
  64. lpwd: obj.lpwd
  65. })
  66. .then(res => {
  67. console.log(res);
  68. uni.setStorageSync('gwpsw',obj.lpwd)
  69. obj.login();
  70. })
  71. .catch(err => {});
  72. },
  73. // 手机登录
  74. register() {
  75. let obj = this;
  76. if (obj.phone == '') {
  77. obj.$api.msg('请输入电话号码');
  78. return;
  79. }
  80. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.phone)) {
  81. obj.$api.msg('请输入正确的手机号');
  82. return;
  83. }
  84. if (obj.code == '') {
  85. obj.$api.msg('请输入验证码');
  86. return;
  87. }
  88. loginMobile({
  89. phone: obj.phone, //账号
  90. captcha: obj.code
  91. })
  92. .then(function(e) {
  93. uni.setStorageSync('token', e.data.token);
  94. getUserInfo({}).then(e => {
  95. obj.login();
  96. // 保存返回用户数据
  97. obj.setUserInfo(e.data);
  98. //成功跳转首页
  99. uni.switchTab({
  100. url: '/pages/index/index'
  101. });
  102. });
  103. })
  104. .catch(e => {
  105. console.log(e);
  106. });
  107. },
  108. isEmailAvailable(obj) {
  109. let email = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  110. if (!email.test(obj)) {
  111. return false;
  112. }
  113. return true;
  114. },
  115. //发送验证码
  116. verification() {
  117. let obj = this;
  118. if (obj.email == '') {
  119. return obj.$api.msg(this.$t('login.qsryx'));
  120. }
  121. if (!obj.isEmailAvailable(obj.email)) {
  122. return obj.$api.msg(this.$t('login.qsrzqdyx'));
  123. }
  124. // 判断是否在倒计时
  125. if (obj.countDown > 0) {
  126. return false;
  127. } else {
  128. obj.countDown = 60;
  129. obj.time = setInterval(() => {
  130. obj.countDown--;
  131. }, 1000);
  132. //调用验证码接口
  133. getForget({
  134. email: obj.email
  135. // type: 'login'
  136. })
  137. .then(({ data }) => {})
  138. .catch(err => {
  139. console.log(err);
  140. });
  141. }
  142. },
  143. login() {
  144. //返回登录
  145. uni.navigateTo({
  146. url: '/pages/public/login'
  147. });
  148. }
  149. }
  150. };
  151. </script>
  152. <style lang="scss">
  153. page {
  154. height: 100%;
  155. background-color: #fff;
  156. font-size: 32rpx;
  157. }
  158. .container {
  159. width: 100%;
  160. height: 100%;
  161. background-size: 100%;
  162. }
  163. .shuru {
  164. display: block;
  165. background-color: #f5f5f5;
  166. width: 673rpx;
  167. height: 95rpx;
  168. margin: auto;
  169. padding-left: 30rpx;
  170. text-align: 95rpx;
  171. }
  172. .tit {
  173. padding: 40rpx 48rpx 20rpx;
  174. }
  175. .gologin {
  176. width: 204rpx;
  177. height: 98rpx;
  178. line-height: 98rpx;
  179. background-color: #fcd535;
  180. text-align: center;
  181. border-radius: 20rpx;
  182. }
  183. .wjmm {
  184. color: #fcd535;
  185. }
  186. .yzm {
  187. width: 400rpx;
  188. height: 95rpx;
  189. padding-left: 30rpx;
  190. background-color: #f5f5f5;
  191. }
  192. .yzmbtn {
  193. width: 234rpx;
  194. height: 95rpx;
  195. background-color: #f5f5f5;
  196. text-align: center;
  197. line-height: 95rpx;
  198. color: #fcd535;
  199. }
  200. </style>