Home.vue 1.87 KB
<template>
  <div class="home">
    <!-- <div class="title"></div>
    <div class="sys-btn btn-margin">我要报名</div>
    <div class="rule"></div>
    <div class="prize"></div>
    <div class="leap-01"></div>
    <div class="leap-02"></div>
    <div class="leap-03"></div>
    <div class="remain"></div>
    <bottom-tool v-model="activityIndex"></bottom-tool>-->
  </div>
</template>

<script>
let urls = {
  login: "/jiajiaCHApi/app/login"
};
import { store, httpPost } from "@/api/fetch-api.js";

export default {
  name: "home",
  data() {
    return {
      activityIndex: 1,
      loginParam: {
        openid: "",
        accessToken: ""
      }
    };
  },
  methods: {
    init() {
      if (store.getSession()) {
        this.$router.push("/index");
      } else {
        let params = this.analysisParams();
        if (params["openId"]) {
          this.loginParam.openid = params["openId"];
          this.loginParam.accessToken = params["access_token"];
          this.login();
        } else {
          store.toWxLogin();
        }
      }
    },
    analysisParams() {
      let params = {};
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        params[pair[0]] = pair[1];
      }
      return params;
    },
    login() {
      httpPost({ url: urls.login, data: this.loginParam }).then(res => {
        if (!res.sessionId) {
          store.toWxLogin();
        } else {
          store.putSession(res.sessionId);
          let path = store.getRedirectUrl();
          path = !path ? "/index" : path;
          store.delRedirectUrl();
          this.$router.push(path);
        }
      });
    }
  },
  created() {
    this.init();
  }
};
</script>

<style lang="scss" scoped>
.home {
  position: relative;
  text-align: center;
  background-color: #74cb35;
}
</style>