App.vue
2.2 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
84
85
86
87
88
89
90
91
<template>
<div id="app" :lang="lang">
<v-header class="header"></v-header>
<main ref="container" class="main-container" :class="{'main-container-min-height':!initCss}">
<router-view />
</main>
<v-footer></v-footer>
<vhis-modal></vhis-modal>
</div>
</template>
<script>
import Vue from "vue";
import { mapGetters, mapActions, mapState } from "vuex";
import { getCookie } from "@utils/utils.js";
import VHeader from "@components/home/header/header.vue";
import VFooter from "@components/home/footer/footer.vue";
import VhisModal from "@components/vhis-modal/vhis-modal.vue";
import api from "@/api/api";
import { httpGet, httpPost } from "@/api/fetch-api.js";
var UA = require("ua-device");
export default {
name: "app",
components: {
VHeader,
VFooter,
VhisModal
},
data() {
return {
lang: "zh",
initCss: false
};
},
computed: {
...mapState({
isMobile: state => state.isMobile
})
},
methods: {
...mapActions(["pcorphone"]),
// 设置UA
refreshUA() {
let output = new UA(navigator.userAgent);
let deviceType = output.device.type;
let isMobile = deviceType == "mobile";
this.$store.commit("IS_MOBILE", isMobile);
},
// 设置用户Profile
refreshProfile() {
let userInfoStr = decodeURIComponent(getCookie("_user_profile"));
if (userInfoStr) {
try {
let userInfo = JSON.parse(decodeURIComponent(userInfoStr));
this.$store.commit("SET_USER_INFO", userInfo);
if (userInfo && userInfo.sid) {
httpPost({ url: api.baseInfo, sidStr: userInfo.sid }).then(res => {
if (res) {
this.$store.commit("SET_USER_INFO", userInfo);
} else {
this.$store.commit("SET_USER_INFO", null);
}
});
}
} catch (e) {}
}
},
initData() {
this.lang = this.$i18n.locale == "en" ? "en" : "zh";
}
},
created() {
this.initData();
this.refreshUA();
this.refreshProfile();
this.$root.eventBus.$on("langChange", () => {
try {
this.initData();
} catch (e) {}
});
}
};
</script>
<style lang="scss" scoped>
</style>