login.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view class="container">
  3. <view class="wjmm" style="text-align: right;padding-right: 30rpx;font-size: 36rpx;" @click="zc()">
  4. 注冊
  5. </view>
  6. <view class="tit" style="padding-top:120rpx;">
  7. 郵箱
  8. </view>
  9. <input type="text" class="shuru" placeholder="請翰入郵箱" v-model="email">
  10. <view class="tit">
  11. 密碼
  12. </view>
  13. <input type="password" class="shuru" placeholder="請翰入密碼" v-model="lpwd" >
  14. <view class="" style="padding:20rpx 48rpx;">
  15. <view class="wjmm" @click="wjmm()">
  16. 忘記密碼?
  17. </view>
  18. </view>
  19. <view class="flex" style="justify-content: flex-end;padding: 0 48rpx;">
  20. <view class="gologin" @click="gologin">
  21. 登錄
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import { mapMutations,mapState } from 'vuex';
  28. import {
  29. loginWx,
  30. gologin,
  31. getUser
  32. } from '@/api/login.js';
  33. export default {
  34. data() {
  35. return {
  36. email: '',
  37. lpwd: ''
  38. };
  39. },
  40. onLoad() {
  41. },
  42. methods: {
  43. ...mapMutations('user',['login','setUserInfo']),
  44. zc() {
  45. uni.navigateTo({
  46. url: '/pages/public/register',
  47. })
  48. },
  49. wjmm() {
  50. uni.navigateTo({
  51. url: '/pages/public/forget',
  52. })
  53. },
  54. gologin() {
  55. let obj = this
  56. if(obj.loadingType == 'loading') {
  57. return
  58. }
  59. if(!obj.isEmailAvailable(obj.email)) {
  60. return obj.$api.msg('請輸入正確的郵箱!')
  61. }
  62. obj.loadingType = 'loading'
  63. gologin({
  64. email: obj.email,
  65. lpwd: obj.lpwd
  66. }).then(res => {
  67. console.log(res)
  68. obj.loadingType = 'no'
  69. uni.showToast({
  70. title: '登錄成功',
  71. duration: 2000,
  72. position: 'top'
  73. });
  74. getUser().then(re => {
  75. obj.login()
  76. obj.setUserInfo(re.data)
  77. setTimeout(()=> {
  78. uni.switchTab({
  79. url:'/pages/index/index'
  80. })
  81. },1500)
  82. })
  83. }).catch(err => {
  84. console.log(err)
  85. obj.loadingType = 'no'
  86. })
  87. },
  88. isEmailAvailable(obj) {
  89. let email = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  90. if (!email.test(obj)) {
  91. return false;
  92. }
  93. return true;
  94. },
  95. }
  96. };
  97. </script>
  98. <style lang="scss">
  99. page {
  100. height: 100%;
  101. background-color: #fff;
  102. font-size: 32rpx;
  103. }
  104. .container {
  105. width: 100%;
  106. height: 100%;
  107. background-size: 100%;
  108. }
  109. .shuru {
  110. display: block;
  111. background-color: #f5f5f5;
  112. width: 673rpx;
  113. height: 95rpx;
  114. margin: auto;
  115. padding-left: 30rpx;
  116. text-align: 95rpx;
  117. }
  118. .tit {
  119. padding:60rpx 48rpx 20rpx;
  120. }
  121. .gologin {
  122. width: 204rpx;
  123. height: 98rpx;
  124. line-height: 98rpx;
  125. background-color: #fcd535;
  126. text-align: center;
  127. border-radius: 20rpx;
  128. }
  129. .wjmm {
  130. color: #fcd535;
  131. }
  132. </style>