Commit c132b74d by xinla

增加微服务主应用配置

1 parent 3bb007d0
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
"nprogress": "0.2.0", "nprogress": "0.2.0",
"path-to-regexp": "2.4.0", "path-to-regexp": "2.4.0",
"promise.prototype.finally": "^3.1.2", "promise.prototype.finally": "^3.1.2",
"qiankun": "^2.10.3",
"qrcodejs2": "0.0.2", "qrcodejs2": "0.0.2",
"quill-image-resize-module": "^3.0.0", "quill-image-resize-module": "^3.0.0",
"screenfull": "4.2.0", "screenfull": "4.2.0",
......
...@@ -27,6 +27,15 @@ const common = { ...@@ -27,6 +27,15 @@ const common = {
DEFAULT_H5_WORDE: env.DOMAIN + '/static/WORD.png', DEFAULT_H5_WORDE: env.DOMAIN + '/static/WORD.png',
DEFAULT_H5_PPT: env.DOMAIN + '/static/PPT.png', DEFAULT_H5_PPT: env.DOMAIN + '/static/PPT.png',
PRIVIEW_URL: env.VIEW_URL, PRIVIEW_URL: env.VIEW_URL,
MICRO_APPS: {
store: {
name: 'microStore',
entry: env.DOMAIN + '/microStore/',
container: '#micro-app',
activeRule: '#/microStore',
},
},
} }
// 以下仅用于系统信息展示,不作为项目变量使用,请勿在代码中使用 // 以下仅用于系统信息展示,不作为项目变量使用,请勿在代码中使用
......
<template> <template>
<!-- <el-scrollbar class="page-scrollbar"> --> <!-- <el-scrollbar class="page-scrollbar"> -->
<div class="app-main"> <div class="app-main">
<transition name="fade-transform" mode="out-in"> <transition name="fade-transform" mode="out-in" v-if="!isActiveMicroApp">
<router-view class="page" :key="key" /> <router-view class="page" :key="key" />
<!-- <keep-alive :include="cachedViews"> <!-- <keep-alive :include="cachedViews">
</keep-alive> --> </keep-alive> -->
</transition> </transition>
<div v-loading="loading">
<div id="micro-app" v-show="isActiveMicroApp">
<!-- <div id="app" class="mask" style="position: absolute">
<i class="el-icon-loading cc"></i>
</div> -->
</div>
</div>
</div> </div>
<!-- </el-scrollbar> --> <!-- </el-scrollbar> -->
</template> </template>
<script> <script>
import { registerMicroApps, start, initGlobalState } from 'qiankun'
export default { export default {
name: 'AppMain', name: 'AppMain',
computed: { computed: {
...@@ -20,6 +28,41 @@ export default { ...@@ -20,6 +28,41 @@ export default {
key() { key() {
return this.$route.path 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> </script>
...@@ -62,6 +105,11 @@ export default { ...@@ -62,6 +105,11 @@ export default {
padding-top: 84px; padding-top: 84px;
} }
} }
#micro-app {
height: calc(100vh - 130px);
position: relative;
}
</style> </style>
<style lang="scss"> <style lang="scss">
......
...@@ -40,8 +40,18 @@ export default { ...@@ -40,8 +40,18 @@ export default {
}, },
// 默认激活的一级菜单路径 eg:/drainageCode // 默认激活的一级菜单路径 eg:/drainageCode
activeMenu() { activeMenu() {
let activePath = this.$route.path.match(/\/[^\/]+/) const path = this.$route.path
let activePath = ''
// 兼容微服务多级路径匹配eg:/microStore/*
if (
window.lwConfig.MICRO_APPS &&
Object.values(window.lwConfig.MICRO_APPS).some((item) => path.startsWith(item.activeRule.match('/.*')[0]))
) {
activePath = path.match('/.+?/.+?/')[0].slice(0, -1)
} else {
activePath = path.match(/\/[^\/]+/)
activePath = activePath && activePath[0] activePath = activePath && activePath[0]
}
this.activeRoutes(activePath) this.activeRoutes(activePath)
return activePath return activePath
}, },
......
...@@ -9,6 +9,20 @@ import { getToken } from '@/utils/auth' ...@@ -9,6 +9,20 @@ import { getToken } from '@/utils/auth'
const whiteList = ['/authRedirect', '/bind', '/test'] // 不管有没有token都可直接进入的页面路径 const whiteList = ['/authRedirect', '/bind', '/test'] // 不管有没有token都可直接进入的页面路径
const noLoginList = ['/login', '/register'] // 没有token才能进入的页面 const noLoginList = ['/login', '/register'] // 没有token才能进入的页面
function nextTo(to, next, isRpelace) {
if (isRpelace) {
next({ ...to, replace: true })
} else if (
to.matched.length === 0 &&
!Object.values(window.lwConfig.MICRO_APPS).some((item) => to.path.startsWith(item.activeRule.match('/.*')[0]))
) {
// 未匹配到路由,且路径不是以微应用路由开头的,跳转至404
next('/404')
} else {
next()
}
}
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// NProgress.start() // NProgress.start()
// 无需检测token的, 不管有没有token都可直接进入 // 无需检测token的, 不管有没有token都可直接进入
...@@ -30,7 +44,7 @@ router.beforeEach((to, from, next) => { ...@@ -30,7 +44,7 @@ router.beforeEach((to, from, next) => {
// store.dispatch('permission/generateRoutes', { roles }).then(accessRoutes => { // store.dispatch('permission/generateRoutes', { roles }).then(accessRoutes => {
// 判断是否有设置企业微信id // 判断是否有设置企业微信id
if (res.corpInfo && res.corpInfo.corpId) { if (res.corpInfo && res.corpInfo.corpId) {
next({ ...to, replace: true }) nextTo(to, next, true)
} else { } else {
// 没有设置企业微信的 // 没有设置企业微信的
let isEnterpriseWechat = router.getRoutes().some((element) => { let isEnterpriseWechat = router.getRoutes().some((element) => {
...@@ -60,7 +74,7 @@ router.beforeEach((to, from, next) => { ...@@ -60,7 +74,7 @@ router.beforeEach((to, from, next) => {
// }) // })
// }) // })
} else { } else {
next() nextTo()
} }
} }
} else if (noLoginList.includes(to.path)) { } else if (noLoginList.includes(to.path)) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!