forget.vue 4.5 KB

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