20251128API:selectAllWithTableName/selectAll/selectTaskHasCreated提前缓存
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
import { store } from '@/components/vuex/store'
|
||||
const Home = () => import('@/components/Home')
|
||||
const ViewTask = () => import('@/components/Supervision/ViewTask')
|
||||
const statPage = () => import('@/components/Statistic/statPage')
|
||||
@@ -148,21 +149,73 @@ const routes = [
|
||||
const router = new VueRouter({
|
||||
routes
|
||||
})
|
||||
router.beforeEach((to, from, next) => {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (to.path.startsWith('/login')) {
|
||||
window.sessionStorage.removeItem('access-user')
|
||||
window.sessionStorage.removeItem('access-id')
|
||||
// 清除初始化状态
|
||||
store.commit('setTaskDataInitialized', false)
|
||||
store.commit('clearInitError')
|
||||
next()
|
||||
} else if (to.path.startsWith('/register') || to.path.startsWith('/modifypassword') || to.path.startsWith('/forgetpassword') || to.path.startsWith('/addinfo')) {
|
||||
window.sessionStorage.removeItem('access-user')
|
||||
window.sessionStorage.removeItem('access-id')
|
||||
// 清除初始化状态
|
||||
store.commit('setTaskDataInitialized', false)
|
||||
store.commit('clearInitError')
|
||||
next()
|
||||
} else {
|
||||
let user = window.sessionStorage.getItem('access-user') === '' ? false : window.sessionStorage.getItem('access-user')
|
||||
if (!user) {
|
||||
next({ path: '/login' })
|
||||
} else {
|
||||
next()
|
||||
// 检查数据是否已初始化
|
||||
const isInitialized = store.state.taskDataInitialized
|
||||
const isInitializing = store.state.taskDataInitializing
|
||||
|
||||
// 如果数据未初始化且不在初始化中,则进行初始化
|
||||
if (!isInitialized && !isInitializing) {
|
||||
try {
|
||||
const result = await store.dispatch('initTaskData')
|
||||
if (result.success) {
|
||||
// 初始化成功,继续路由
|
||||
next()
|
||||
} else {
|
||||
// 初始化失败,显示错误提示并阻止路由
|
||||
store.commit('setInitError', result.error)
|
||||
// 阻止路由跳转,显示错误对话框
|
||||
next(false)
|
||||
}
|
||||
} catch (error) {
|
||||
// 初始化异常
|
||||
store.commit('setInitError', error.message || '初始化失败,请重试')
|
||||
next(false)
|
||||
}
|
||||
} else if (isInitializing) {
|
||||
// 正在初始化中,等待完成(最多等待5秒)
|
||||
let waited = 0
|
||||
const maxWait = 5000
|
||||
const checkInterval = setInterval(() => {
|
||||
waited += 100
|
||||
if (!store.state.taskDataInitializing || waited >= maxWait) {
|
||||
clearInterval(checkInterval)
|
||||
if (store.state.taskDataInitialized) {
|
||||
next()
|
||||
} else {
|
||||
if (waited >= maxWait) {
|
||||
store.commit('setTaskDataInitializing', false)
|
||||
store.commit('setInitError', '初始化超时,请重试')
|
||||
} else {
|
||||
store.commit('setInitError', '初始化失败,请重试')
|
||||
}
|
||||
next(false)
|
||||
}
|
||||
}
|
||||
}, 100)
|
||||
} else {
|
||||
// 已初始化,继续路由
|
||||
next()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user