2026-07-30 17:59:43 +08:00
|
|
|
import { createApp } from 'vue'
|
|
|
|
|
import { createPinia } from 'pinia'
|
2026-07-31 13:43:16 +08:00
|
|
|
import { ElMessage } from 'element-plus'
|
2026-07-30 17:59:43 +08:00
|
|
|
import 'element-plus/es/components/message/style/css'
|
|
|
|
|
import 'element-plus/es/components/message-box/style/css'
|
|
|
|
|
import App from './App.vue'
|
2026-08-03 18:49:18 +08:00
|
|
|
import router from '@/app/router'
|
|
|
|
|
import { sanitizeInternalPath } from '@/core/routing/accessDecision'
|
|
|
|
|
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
|
|
|
|
import { useUnsavedWorkStore } from '@/core/unsaved-work/unsavedWork'
|
2026-08-05 15:54:59 +08:00
|
|
|
import { useWorkspaceTabsStore } from '@/core/workspace-tabs/workspaceTabs'
|
2026-08-03 18:49:18 +08:00
|
|
|
import { useAuthStore } from '@/core/auth/auth'
|
|
|
|
|
import { registerAuthSessionExpiredHandler } from '@/shared/api/http'
|
2026-07-30 17:59:43 +08:00
|
|
|
import './styles/index.css'
|
|
|
|
|
|
2026-07-31 13:43:16 +08:00
|
|
|
const pinia = createPinia()
|
|
|
|
|
const auth = useAuthStore(pinia)
|
2026-08-05 15:54:59 +08:00
|
|
|
const unsaved = useUnsavedWorkStore(pinia)
|
|
|
|
|
const workspace = useWorkspaceTabsStore(pinia)
|
2026-07-30 22:38:28 +08:00
|
|
|
|
2026-07-31 13:43:16 +08:00
|
|
|
await auth.restoreSession()
|
|
|
|
|
|
|
|
|
|
registerAuthSessionExpiredHandler(async () => {
|
|
|
|
|
const currentRoute = router.currentRoute.value
|
|
|
|
|
if (currentRoute.name === 'login') return
|
|
|
|
|
|
|
|
|
|
useAccessPreviewStore(pinia).reset()
|
2026-08-05 15:54:59 +08:00
|
|
|
unsaved.clear()
|
|
|
|
|
workspace.reset(true)
|
2026-07-31 13:43:16 +08:00
|
|
|
const redirect = sanitizeInternalPath(currentRoute.fullPath)
|
|
|
|
|
ElMessage.warning('登录状态已过期,请重新登录')
|
|
|
|
|
await router.replace({
|
|
|
|
|
name: 'login',
|
|
|
|
|
query: redirect === '/' ? undefined : { redirect },
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-05 15:54:59 +08:00
|
|
|
window.addEventListener('beforeunload', (event) => {
|
|
|
|
|
if (!unsaved.entries.some((entry) => entry.dirty)) return
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
event.returnValue = ''
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-31 13:43:16 +08:00
|
|
|
createApp(App).use(pinia).use(router).mount('#app')
|