getInfo.vue 7.88 KB
<template>
  <div class="login">
    <div class="wscn-http404-container">
      <div class="wscn-http404">
        <div class="pic-404">
          <!--<img class="pic-404__parent" src="@/assets/404_images/404.png" alt="404">-->
          <img class="pic-404__parent" src="#" alt="">

        </div>
        <div class="bullshit">
          <div class="bullshit__oops" v-if="token!='' && token!=null && token!='undefined'">
            正在登录中.....
          </div>
          <div class="bullshit__oops" v-else style="font-size: 22px">
            登录状态已过期或token无效<br/>请重新登录.....
          </div>
          <!--<div class="bullshit__headline">-->
          <!--{{ message }}-->
          <!--</div>-->
          <!--<div class="bullshit__info">-->
          <!--对不起,您正在寻找的页面不存在。尝试检查URL的错误,然后按浏览器上的刷新按钮或尝试在我们的应用程序中找到其他内容。-->
          <!--</div>-->
          <!--<router-link to="/" class="bullshit__return-home">-->
          <!--返回首页-->
          <!--</router-link>-->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import userService from "./service/UserService";
export default {
  name: 'getInfo',
  computed: {
    message() {
      return '找不到网页!'
    },
  },
  data() {
    return {
      token: false,
    };
  },
  created() {
    this.pointLogin();
  },
  methods: {
    pointLogin() {
      this.token = this.$route.query.token;
      console.log('Token value:', this.token);
      console.log('Token type:', typeof this.token);

      if (this.token != null && this.token != 'undefined' && this.token !== '') {
        // 直接使用token,不进行编码,避免可能的编码问题
        let loginParam = {
          token: this.token
        };

        console.log('Sending parameters:', loginParam);

        // 使用POST方式发送token,避免URL参数可能出现的问题
        this.$axios({
          method: 'post',
          url: "/api/user/getInfo",
          data: loginParam
        }).then(res => {
          console.log('Success response:', res);
          if (res.data != null) {
            this.toLogin(res.data.data)
          }
        }).catch(error => {
          console.error('Request failed:', error);
          console.error('Error status:', error.response ? error.response.status : 'No response');
          console.error('Error data:', error.response ? error.response.data : 'No response data');

          // 即使是400错误,如果返回了有效数据,则继续处理
          if (error.response && error.response.status === 400 && error.response.data) {
            // 检查返回的数据是否有效
            if (error.response.data.data || error.response.data.user) {
              // 尝试使用返回的数据进行登录
              this.toLogin(error.response.data.data || error.response.data.user);
              return;
            }
          }

          this.$message.error("登录失败,请重试");
          // 失败时跳转到登录页面
          // setTimeout(() => {
          //   this.$router.push('/login');
          // }, 2000);
        })
      } else {
        console.log('Token is empty or invalid');
        this.$message.warning("登录参数无效");
        // 参数无效时跳转到登录页面
        // setTimeout(() => {
        //   this.$router.push('/login');
        // }, 2000);
      }
    },
    cancelEnterkeyDefaultAction() {
      document.onkeydown = function (e) {
        var key = window.event.keyCode;
        if (key == 13) {
          return false;
        }
      }
    },
    toLogin(user) {
      console.log("开始登录")
      //需要想后端发送的登录参数
      let loginParam = {
        username: user.username,
        password: user.password
      }
      var that = this;
      this.$axios({
        method: 'get',
        url: "/api/user/login",
        params: loginParam
      }).then(function (res) {
        console.log(res);
        console.log("登录成功");
        if (res.data.code === 0) {
          userService.setUser(res.data.data)
          //登录成功后
          that.cancelEnterkeyDefaultAction();
          that.$router.push('/');
        } else {
          that.$message({
            showClose: true,
            message: '登录失败,用户名或密码错误',
            type: 'error'
          });
        }
      }).catch(function (error) {
        console.log(error)
      });
    },

  }
}
</script>

<style scoped>
.wscn-http404-container {
  transform: translate(-50%, -50%);
  position: absolute;
  top: 40%;
  left: 50%;
}

.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../assets/login-bg.jpg");
  background-size: cover;
}

.wscn-http404 {
  position: relative;
  width: 1200px;
  padding: 0 50px;
  overflow: hidden;
}

.wscn-http404 .pic-404 {
  position: relative;
  float: left;
  width: 600px;
  overflow: hidden;
}

.wscn-http404 .pic-404__parent {
  width: 100%;
}

.wscn-http404 .pic-404__child {
  position: absolute;
}

.wscn-http404 .pic-404__child.left {
  width: 80px;
  top: 17px;
  left: 220px;
  opacity: 0;
  animation-name: cloudLeft;
  animation-duration: 2s;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  animation-delay: 1s;
}

.wscn-http404 .pic-404__child.mid {
  width: 46px;
  top: 10px;
  left: 420px;
  opacity: 0;
  animation-name: cloudMid;
  animation-duration: 2s;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  animation-delay: 1.2s;
}

.wscn-http404 .pic-404__child.right {
  width: 62px;
  top: 100px;
  left: 500px;
  opacity: 0;
  animation-name: cloudRight;
  animation-duration: 2s;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  animation-delay: 1s;
}

@keyframes cloudLeft {
  0% {
    top: 17px;
    left: 220px;
    opacity: 0;
  }
  20% {
    top: 33px;
    left: 188px;
    opacity: 1;
  }
  80% {
    top: 81px;
    left: 92px;
    opacity: 1;
  }
  100% {
    top: 97px;
    left: 60px;
    opacity: 0;
  }
}

@keyframes cloudMid {
  0% {
    top: 10px;
    left: 420px;
    opacity: 0;
  }
  20% {
    top: 40px;
    left: 360px;
    opacity: 1;
  }
  70% {
    top: 130px;
    left: 180px;
    opacity: 1;
  }
  100% {
    top: 160px;
    left: 120px;
    opacity: 0;
  }
}

@keyframes cloudRight {
  0% {
    top: 100px;
    left: 500px;
    opacity: 0;
  }
  20% {
    top: 120px;
    left: 460px;
    opacity: 1;
  }
  80% {
    top: 180px;
    left: 340px;
    opacity: 1;
  }
  100% {
    top: 200px;
    left: 300px;
    opacity: 0;
  }
}

.wscn-http404 .bullshit {
  position: relative;
  float: left;
  width: 300px;
  padding: 30px 0;
  overflow: hidden;
}

.bullshit__oops {
  font-size: 32px;
  font-weight: bold;
  line-height: 40px;
  color: #1482f0;
  opacity: 0;
  margin-bottom: 20px;
  animation-name: slideUp;
  animation-duration: 0.5s;
  animation-fill-mode: forwards;
}

.bullshit__headline {
  font-size: 20px;
  line-height: 24px;
  color: #222;
  font-weight: bold;
  opacity: 0;
  margin-bottom: 10px;
  animation-name: slideUp;
  animation-duration: 0.5s;
  animation-delay: 0.1s;
  animation-fill-mode: forwards;
}

.bullshit__info {
  font-size: 13px;
  line-height: 21px;
  color: grey;
  opacity: 0;
  margin-bottom: 30px;
  animation-name: slideUp;
  animation-duration: 0.5s;
  animation-delay: 0.2s;
  animation-fill-mode: forwards;
}

.bullshit__return-home {
  display: block;
  float: left;
  width: 110px;
  height: 36px;
  background: #1482f0;
  border-radius: 100px;
  text-align: center;
  color: #ffffff;
  opacity: 0;
  font-size: 14px;
  line-height: 36px;
  cursor: pointer;
  animation-name: slideUp;
  animation-duration: 0.5s;
  animation-delay: 0.3s;
  animation-fill-mode: forwards;
}

@keyframes slideUp {
  0% {
    transform: translateY(60px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}
</style>