App.vue
2.35 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<template>
<div id="app">
<router-view v-if="isRouterAlive" />
</div>
</template>
<script>
import "@/assets/iconfont/iconfont.css";
import { initDictToLocalstorage } from "@/api/dict-data";
export default {
name: "App",
provide() {
return {
reload: this.reload
};
},
data() {
return {
isRouterAlive: false
};
},
watch: {
$route(to, form) {
if (to.path == "/login") {
this.queryDictName();
}
}
},
computed: {},
created() {
this.queryDictName();
this.loadTheme();
},
methods: {
queryDictName() {
// 初始化数据字典到浏览器本地缓存
initDictToLocalstorage(() => {
this.isRouterAlive = true;
});
},
loadTheme(){
const getParams = () => {
let map = {};
let query = window.location.search.substring(1);
if (query == '') {
query = document.location.href
let args = query.split('?');
let arr = [];
if (args && args.length > 1) {
arr = args[1].split('&')
}
for (let i = 0; i < arr.length; i++) {
let pair = arr[i].split("=");
map[pair[0]] = pair[1];
}
return map;
}
let vars = query.split("&");
for (let i = 0; i < vars.length; i++) {
let pair = vars[i].split("=");
map[pair[0]] = pair[1];
}
return map;
}
const getVal = (key) => {
if(key){
let val = getParams()[key];
if(!val){
val = localStorage.getItem(key);
}
if(val){
localStorage.setItem(key,val);
}
return val;
}
return '';
}
getVal('AuthKey');
getVal('AuthVal');
let theme = getVal('theme');
if (!theme) {
theme = 'simplicity';
}
if (!theme) {
theme = 'simplicity';
}
var link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("href", `/mj/public/css/sub-sys/aj-web-${theme}.css`);
document.body.insertBefore(link, document.body.firstChild);
},
reload() {
this.isRouterAlive = false;
this.$nextTick(function() {
this.isRouterAlive = true;
});
}
}
};
</script>