refactor: vite.config.ts 类型修复与 Vite 8 迁移适配

- 修复 vite.config.ts 中 command 隐式 any 类型错误
- 修复 proxy 中 path 参数隐式 any 类型错误
- 将无效的 oxc.drop 配置迁移为 Vite 8 原生方式(build.rolldownOptions.output.minify.compress)
- 引入 defineConfig + ConfigEnv 提供完整类型推导
- JS 文件迁移为 TypeScript(user.ts, routerGuard.ts 等)
- 更新 API 层类型定义
This commit is contained in:
2026-08-12 14:13:45 +08:00
parent 35e98b9ab1
commit fd753291fe
20 changed files with 596 additions and 660 deletions

60
src/router/routerGuard.ts Normal file
View File

@@ -0,0 +1,60 @@
import router from './index'
import { getToken } from '@/utils/auth'
import { useUserStore } from '@/store/modules/user'
const whiteList = ['/login'] // no redirect whitelist
// const setPageTitle = function (meta) {
// let title = '海灵标'
// if (meta && meta.title) {
// title = `${meta.title}`
// }
// document.title = title
// }
// 路由守卫
router.beforeEach(async (to, from, next) => {
$loadingBar.start()
// setPageTitle(to.meta)
const hasToken = getToken()
const userStore = useUserStore()
if (hasToken) {
if (to.path === '/login') {
next({ path: '/' })
$loadingBar.finish()
} else {
const hasGetUserInfo = userStore.name
if (hasGetUserInfo !== '') {
next()
} else {
try {
// get user info
const infoVO = await userStore.getInfo()
next({ ...to, replace: true })
} catch (error) {
await userStore.resetToken()
next(`/login?redirect=${to.path}`)
// remove token and go to login page to re-login
console.error(error)
$loadingBar.error()
}
}
}
} else {
/* has no token */
if (whiteList.indexOf(to.path) !== -1) {
// in the free login whitelist, go directly
next()
} else {
next(`/login?redirect=${to.path}`)
$loadingBar.finish()
}
}
})
router.afterEach((to) => {
if (to.matched.length === 0) {
router.push('/404')
// fixme 不能自动跳转404, 需要引导
}
$loadingBar.finish()
})