AppMain.vue
3.11 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<template>
<!-- <el-scrollbar class="page-scrollbar"> -->
<div class="app-main">
<div class="page-wrap">
<transition name="fade-transform" mode="out-in" v-if="!isActiveMicroApp">
<router-view class="page container" id="page-container" :key="key" />
<!-- <keep-alive :include="cachedViews">
</keep-alive> -->
</transition>
<div v-loading="loading" class="micro-app-wrap height100" v-show="isActiveMicroApp">
<div id="micro-app" class="height100"></div>
</div>
</div>
</div>
<!-- </el-scrollbar> -->
</template>
<script>
import { registerMicroApps, start, initGlobalState } from 'qiankun'
export default {
name: 'AppMain',
data() {
return {
loading: false,
}
},
computed: {
cachedViews() {
return this.$store.state.tagsView.cachedViews
},
key() {
return this.$route.path
},
isActiveMicroApp() {
let microApp = window.lwConfig.MICRO_APPS
return (
microApp && Object.values(microApp).some((item) => this.$route.path.startsWith(item.activeRule.match('/.*')[0]))
)
},
},
mounted() {
if (window.lwConfig.MICRO_APPS && window.lwConfig.MICRO_APPS.store) {
window.Vue2 = window.Vue
delete window.Vue
window.lwConfig.MICRO_APPS.store.loader = (loading) => (this.loading = loading)
registerMicroApps([window.lwConfig.MICRO_APPS.store])
start({
sandbox: { experimentalStyleIsolation: true },
})
// 挂在window供下面微服务使用
window.lwConfig.$store = this.$store
// 初始化 state
// const actions = initGlobalState({ token: getToken() })
// actions.onGlobalStateChange((state, prev) => {
// // state: 变更后的状态; prev 变更前的状态
// });
// actions.setGlobalState(state)
}
// if (window.lwConfig.MICRO_APPS) {
// import('qiankun').then(({ registerMicroApps, start }) => {
// registerMicroApps(window.lwConfig.MICRO_APPS)
// start({
// sandbox: { experimentalStyleIsolation: true },
// })
// })
// }
},
}
</script>
<style lang="scss" scoped>
// ::v-deep .el-scrollbar__wrap {
// margin: 20px 0;
// padding: 0 20px;
// }
.app-main {
position: relative;
flex: auto;
// overflow: hidden;
overflow-y: auto;
overflow-x: hidden;
margin-top: 20px;
}
.page-wrap {
position: initial !important; // 用以解决加载遮罩层随内容滚动问题
height: 100%;
overflow-y: auto;
overflow-x: hidden;
scroll-behavior: smooth;
padding: 0 15px 0 20px;
}
.page {
position: initial !important; // 用以解决加载遮罩层随内容滚动问题
}
.micro-app-wrap {
position: relative;
}
// .fixed-header + .app-main {
// padding-top: 50px;
// }
// .hasTagsView {
// .app-main {
// /* 84 = navbar + tags-view = 50 + 34 */
// height: calc(100vh - 84px);
// }
// .fixed-header + .app-main {
// padding-top: 84px;
// }
// }
</style>
<style lang="scss">
// fix css style bug in open el-dialog
.el-popup-parent--hidden {
.fixed-header {
padding-right: 15px;
}
}
#micro-app > div {
height: 100%;
}
</style>