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
108
109
110
111
112
113
114
115
116
117
<template>
<section class="app-main-container">
<!-- <vab-keel v-if="show && skeleton" style="margin: 15px">
<vab-keel-heading :img="true" />
<vab-keel-text :lines="7" />
<vab-keel-heading :img="true" />
<vab-keel-text :lines="6" />
<vab-keel-heading :img="true" />
<vab-keel-text :lines="8" />
</vab-keel> -->
<transition mode="out-in" name="fade-transform">
<keep-alive v-if="routerView" :include="cachedRoutes" :max="10">
<router-view :key="key" style="min-height: 84vh" />
</keep-alive>
</transition>
</section>
</template>
<script>
import { VabKeel, VabKeelHeading, VabKeelText } from "@/plugins/vabKeel"
import { mapGetters } from "vuex"
import { copyright } from "@/config/settings"
export default {
name: "AppMain",
components: {
VabKeel,
VabKeelHeading,
VabKeelText,
},
data() {
return {
show: true,
fullYear: new Date().getFullYear(),
copyright,
routerView: true,
skeleton: this._skeleton,
}
},
computed: {
...mapGetters({
visitedRoutes: "tagsBar/visitedRoutes",
device: "settings/device",
_skeleton: "settings/skeleton",
}),
cachedRoutes() {
const cachedRoutesArr = []
this.visitedRoutes.forEach((item) => {
if (!item.meta.noKeepAlive) {
cachedRoutesArr.push(item.name)
}
})
this.handleSkeleton(cachedRoutesArr)
return cachedRoutesArr
},
key() {
return this.$route.path
},
},
watch: {
$route: {
handler(route) {
if ("mobile" === this.device) {
this.$store.dispatch("settings/foldSideBar")
}
},
immediate: true,
},
},
created() {
//重载所有路由
this.$baseEventBus.$on("reloadRouterView", () => {
this.routerView = false
this.skeleton = false
this.$nextTick(() => {
this.routerView = true
this.skeleton = true
})
})
},
mounted() {
setTimeout(() => {
this.show = false
}, 200)
},
methods: {
// TODO 骨架屏处理还有bug我找到更好的解决方案待修复
handleSkeleton(cachedRoutesArr) {
if (this.skeleton) {
cachedRoutesArr.push(this.$route.name)
this.show = true
setTimeout(() => {
this.show = false
}, 200)
} else {
this.show = false
}
},
},
}
</script>
<style lang="scss" scoped>
.app-main-container {
position: relative;
width: 100%;
overflow: hidden;
.footer-copyright {
min-height: 55px;
line-height: 55px;
color: rgba(0, 0, 0, 0.45);
text-align: center;
border-top: 1px dashed $base-border-color;
}
}
</style>