Home.vue
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<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>