42 lines
1.6 KiB
JavaScript
42 lines
1.6 KiB
JavaScript
import router, {projectOpTreeRoutes, setProjectOperationRoutes} from './router'
|
|
import {generateRoutes} from "@/api/game_api.js";
|
|
import LocalCache, {cachedProject, cachedProjectResource} from '@/stores/project.js'
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.path === '/login') {
|
|
// 推首页
|
|
next({path: '/'})
|
|
} else {
|
|
if (to.path.startsWith('/project')) {
|
|
const pathSegments = to.path.split("/").filter(segment => segment !== "");
|
|
if (pathSegments.length === 3) {
|
|
|
|
// const projectId = pathSegments[pathSegments.length - 2]
|
|
// const resource = pathSegments[pathSegments.length - 1]
|
|
|
|
// 进行资源操作点击
|
|
const oldResource = LocalCache.getCache("resource")
|
|
if (oldResource.path !== to.path) {
|
|
LocalCache.setCache("resource", to)
|
|
}
|
|
}
|
|
}
|
|
|
|
if (projectOpTreeRoutes.value.length === 0) {
|
|
generateRoutes().then((res) => {
|
|
const projectList = ref([])
|
|
projectList.value = res.data.projects
|
|
setProjectOperationRoutes(projectList.value)
|
|
// console.log("all routes:", router.getRoutes())
|
|
next({...to, replace: true}); // 在已有页面里查找
|
|
}, (err) => {
|
|
console.log("跳转路径:", to.path, " 报错:", err)
|
|
})
|
|
} else {
|
|
console.log("op tree routes length valid:", projectOpTreeRoutes.value.length)
|
|
next()
|
|
}
|
|
}
|
|
})
|
|
|