闫增涛
2024-11-22 4165ebe94e92af85b093abe264eb404c6a5181e7
src/main.ts
@@ -10,6 +10,13 @@
import toolClass from '@/assets/js/toolClass'
import MG from '@/assets/js/middleGround/WebMiddleGroundApi.js'
import './child.ts'
import { loginCtx } from '@/assets/js/config.ts'
// 公式输入
import { MathfieldElement } from "mathlive"
// 公式解析
import VueLatex from 'vatex'
const handleGetToken = () => {
  return localStorage.getItem('token')
@@ -17,23 +24,31 @@
// 路由执行之前的一些操作
router.beforeEach((to, from, next) => {
  if (handleGetToken()) {
    // 是否是登录页面,直接到首页
    if (to.path === '/login') {
      next({ path: '/home', query: { bookId: localStorage.getItem('bookId') } })
    } else {
      // 如果不是登录页面,跳转到目标的页面
      next()
    }
  const isInternalLink = from.fullPath.includes('/testBookReader')
  if (isInternalLink) {
    sessionStorage.removeItem('loginCtx')
  } else {
    // 没有token
    if (!to.meta || !to.meta.auth) {
      // 在免登录白名单,直接进入
      next()
    } else {
      next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
    }
    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主应用与微应用通讯
@@ -65,8 +80,10 @@
const app = createApp(App)
app.provide('toolClass', toolClass)
app.provide('MG', MG)
app.use(VueLatex)
app.use(router)
app.use(ElementPlus)
app.use(pinia)