Home.vue 2.57 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() {
      let params = this.analysisParams();
      let worksCode = params["worksCode"];
      if (worksCode) {
        store.saveWorksRedirectUrl(worksCode);
        let link = location.origin + location.pathname;
        location.href = link;
        return;
      }

      // SimonFungC 检测是否跳转中奖表单页
      let from = params["f"];
      if (from == "award") {
        let data = {
          route: "/award",
          params: {}
        };
        localStorage.setItem(
          "_jiajia_childrenhost_redirect",
          JSON.stringify(data)
        );
        let link = location.origin + location.pathname;
        location.href = link;
        return;
      }

      if (store.getSession()) {
        this.toNextPath();
      } else {
        if (params["openId"]) {
          this.loginParam.openid = params["openId"];
					this.loginParam.accessToken = params["access_token"];
					console.log("this.loginParam:",this.loginParam)
          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);
          this.toNextPath();
        }
      });
    },
    toNextPath() {
      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>