import './assets/main.css'
|
|
import { createApp } from 'vue'
|
import pinia from '@/store/index'
|
import ElementPlus from 'element-plus'
|
import 'element-plus/dist/index.css'
|
import App from './App.vue'
|
import router from './router'
|
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
import toolClass from '@/assets/js/toolClass'
|
import MG from "@/assets/js/middleGround/WebMiddleGroundApi.js"
|
import './child.ts'
|
|
const handleGetToken = () => {
|
return localStorage.getItem('token')
|
}
|
|
const getUrlParam =(paraName)=>{
|
var url = window.location.toString();
|
var arrObj = url.split("?");
|
if (arrObj.length > 1) {
|
var arrPara = arrObj[1].split("&");
|
var arr;
|
for (var i = 0; i < arrPara.length; i++) {
|
arr = arrPara[i].split("=");
|
if (arr != null && arr[0] == paraName) {
|
return arr[1];
|
}
|
}
|
return "";
|
} else {
|
return "";
|
}
|
}
|
|
// 路由执行之前的一些操作
|
router.beforeEach((to, from, next) => {
|
let token = getUrlParam('token');
|
let bookId = getUrlParam('bookId');
|
if(bookId){
|
localStorage.setItem('bookId', bookId)
|
}
|
|
if (token) {
|
localStorage.setItem('token', token)
|
|
if (to.path === '/login') {
|
next({ path: '/home' })
|
} else {
|
// 如果不是登录页面,跳转到目标的页面
|
next()
|
}
|
}else if (handleGetToken()) {
|
// 是否是登录页面,直接到首页
|
if (to.path === '/login') {
|
next({ path: '/home' })
|
} else {
|
// 如果不是登录页面,跳转到目标的页面
|
next()
|
}
|
} else {
|
// 没有token
|
if (!to.meta || !to.meta.auth) {
|
// 在免登录白名单,直接进入
|
next()
|
} else {
|
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
}
|
}
|
})
|
|
// qiankun主应用与微应用通讯
|
// import { initGlobalState, type MicroAppStateActions } from 'qiankun'
|
// import state from './qiankunState/state'
|
|
// state.bb = (data) => {
|
// console.log(data);
|
// }
|
|
// 初始化 state
|
// const actions: any = initGlobalState(state)
|
|
// 监听state变化
|
// actions.onGlobalStateChange((state: any, prev: any) => {
|
// // state: 变更后的状态; prev 变更前的状态
|
// console.log("父层change:",state, prev)
|
// })
|
// 设置state的值
|
// actions.setGlobalState(state)
|
|
// console.log(actions,"actions");
|
|
// app.provide('qiankunActions', actions)
|
// window.qiankunActions = actions
|
|
// 移除当前应用的状态监听,微应用 umount 时会默认调用
|
// actions.offGlobalStateChange()
|
|
const app = createApp(App)
|
|
app.provide('toolClass', toolClass)
|
app.provide('MG', MG)
|
app.use(router)
|
app.use(ElementPlus)
|
app.use(pinia)
|
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
app.component(key, component)
|
}
|
|
app.mount('#parentApp')
|