login.vue 2.8 KB

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