优化
This commit is contained in:
+11
-1
@@ -8,12 +8,15 @@ import router from '@/app/router'
|
||||
import { sanitizeInternalPath } from '@/core/routing/accessDecision'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useUnsavedWorkStore } from '@/core/unsaved-work/unsavedWork'
|
||||
import { useWorkspaceTabsStore } from '@/core/workspace-tabs/workspaceTabs'
|
||||
import { useAuthStore } from '@/core/auth/auth'
|
||||
import { registerAuthSessionExpiredHandler } from '@/shared/api/http'
|
||||
import './styles/index.css'
|
||||
|
||||
const pinia = createPinia()
|
||||
const auth = useAuthStore(pinia)
|
||||
const unsaved = useUnsavedWorkStore(pinia)
|
||||
const workspace = useWorkspaceTabsStore(pinia)
|
||||
|
||||
await auth.restoreSession()
|
||||
|
||||
@@ -22,7 +25,8 @@ registerAuthSessionExpiredHandler(async () => {
|
||||
if (currentRoute.name === 'login') return
|
||||
|
||||
useAccessPreviewStore(pinia).reset()
|
||||
useUnsavedWorkStore(pinia).clear()
|
||||
unsaved.clear()
|
||||
workspace.reset(true)
|
||||
const redirect = sanitizeInternalPath(currentRoute.fullPath)
|
||||
ElMessage.warning('登录状态已过期,请重新登录')
|
||||
await router.replace({
|
||||
@@ -31,4 +35,10 @@ registerAuthSessionExpiredHandler(async () => {
|
||||
})
|
||||
})
|
||||
|
||||
window.addEventListener('beforeunload', (event) => {
|
||||
if (!unsaved.entries.some((entry) => entry.dirty)) return
|
||||
event.preventDefault()
|
||||
event.returnValue = ''
|
||||
})
|
||||
|
||||
createApp(App).use(pinia).use(router).mount('#app')
|
||||
|
||||
Reference in New Issue
Block a user