闫增涛
2024-07-02 92845ee4a3898c4c65bc85bbbe777e4595897e3d
src/main.ts
@@ -8,8 +8,9 @@
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import toolClass from '@/assets/js/toolClass'
import request from '@/plugin/axios/index.ts'
import MG from '@/assets/js/middleGround/WebMiddleGroundApi.js'
import './child.ts'
import { loginCtx } from '@/assets/js/config.ts'
const handleGetToken = () => {
  return localStorage.getItem('token')
@@ -17,26 +18,35 @@
// 路由执行之前的一些操作
router.beforeEach((to, from, next) => {
  // 如果有token
  if (handleGetToken()) {
    // 是否是登录页面,直接到首页
    if (to.path === '/login') {
      next({ path: '/transmission' })
    } else {
      // 如果不是登录页面,跳转到目标的页面
      next()
    }
  console.log(to, from)
  const isInternalLink = from.fullPath.includes('/testBookReader')
  if (isInternalLink) {
    console.log('通过内部链接进入项目')
    sessionStorage.removeItem('loginCtx')
  } else {
    // 没有token
    if (!to.meta || !to.meta.auth) {
      // 在免登录白名单,直接进入
      next()
    } else {
      next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
    }
    console.log(loginCtx, '通过外部链接进入项目')
    sessionStorage.setItem('loginCtx', loginCtx)
  }
})
  next()
  // if (handleGetToken()) {
  //   // 是否是登录页面,直接到首页
  //   if (to.path === '/login') {
  //     next({ path: '/home', query: { bookId: localStorage.getItem('bookId') } })
  //   } else {
  //     // 如果不是登录页面,跳转到目标的页面
  //     next()
  //   }
  // } else {
  //   // 没有token
  //   if (!to.meta || !to.meta.auth) {
  //     // 在免登录白名单,直接进入
  //     next()
  //   } else {
  //     next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
  //   }
  // }
})
// qiankun主应用与微应用通讯
// import { initGlobalState, type MicroAppStateActions } from 'qiankun'
@@ -68,7 +78,7 @@
const app = createApp(App)
app.provide('toolClass', toolClass)
app.provide('request', request)
app.provide('MG', MG)
app.use(router)
app.use(ElementPlus)
app.use(pinia)
@@ -77,4 +87,3 @@
}
app.mount('#parentApp')