fix(frontend): persist upload requirement to sessionStorage; friendly error when files lost on refresh
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
75533e9319
commit
182a9525e7
|
|
@ -1,15 +1,16 @@
|
|||
/**
|
||||
* 临时存储待上传的文件和需求
|
||||
* 用于首页点击启动引擎后立即跳转,在Process页面再进行API调用
|
||||
* Temporary storage for files and simulation requirement.
|
||||
* - simulationRequirement: persisted to sessionStorage (survives refresh within the tab)
|
||||
* - files: in-memory only (File objects are not JSON-serializable)
|
||||
*/
|
||||
import { reactive } from 'vue'
|
||||
|
||||
const state = reactive({
|
||||
files: [],
|
||||
simulationRequirement: '',
|
||||
isPending: false,
|
||||
simulationRequirement: sessionStorage.getItem('pendingRequirement') || '',
|
||||
isPending: sessionStorage.getItem('pendingIsPending') === 'true',
|
||||
importOntologyMode: false,
|
||||
ontologyFile: null
|
||||
ontologyFile: null,
|
||||
})
|
||||
|
||||
export function setPendingUpload(files, requirement, importOntologyMode = false, ontologyFile = null) {
|
||||
|
|
@ -18,6 +19,8 @@ export function setPendingUpload(files, requirement, importOntologyMode = false,
|
|||
state.isPending = true
|
||||
state.importOntologyMode = importOntologyMode
|
||||
state.ontologyFile = ontologyFile
|
||||
sessionStorage.setItem('pendingRequirement', requirement)
|
||||
sessionStorage.setItem('pendingIsPending', 'true')
|
||||
}
|
||||
|
||||
export function getPendingUpload() {
|
||||
|
|
@ -26,7 +29,7 @@ export function getPendingUpload() {
|
|||
simulationRequirement: state.simulationRequirement,
|
||||
isPending: state.isPending,
|
||||
importOntologyMode: state.importOntologyMode,
|
||||
ontologyFile: state.ontologyFile
|
||||
ontologyFile: state.ontologyFile,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -36,6 +39,8 @@ export function clearPendingUpload() {
|
|||
state.isPending = false
|
||||
state.importOntologyMode = false
|
||||
state.ontologyFile = null
|
||||
sessionStorage.removeItem('pendingRequirement')
|
||||
sessionStorage.removeItem('pendingIsPending')
|
||||
}
|
||||
|
||||
export default state
|
||||
|
|
|
|||
|
|
@ -197,9 +197,16 @@ const initProject = async () => {
|
|||
|
||||
const handleNewProject = async () => {
|
||||
const pending = getPendingUpload()
|
||||
if (!pending.isPending || pending.files.length === 0) {
|
||||
error.value = 'No pending files found.'
|
||||
addLog('Error: No pending files found for new project.')
|
||||
|
||||
if (!pending.isPending) {
|
||||
return // not a new-project session
|
||||
}
|
||||
|
||||
if (pending.files.length === 0) {
|
||||
error.value = t('error.filesLostAfterRefresh')
|
||||
addLog(t('error.filesLostAfterRefresh'))
|
||||
clearPendingUpload()
|
||||
setTimeout(() => router.push('/'), 3000)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -706,5 +706,8 @@
|
|||
"submit": "Entrar",
|
||||
"loading": "Autenticant...",
|
||||
"invalidCredentials": "Usuari o contrasenya incorrectes"
|
||||
},
|
||||
"error": {
|
||||
"filesLostAfterRefresh": "Els fitxers s'han perdut en refrescar la pàgina. Redirigint a l'inici per tornar a seleccionar-los…"
|
||||
}
|
||||
}
|
||||
|
|
@ -707,5 +707,8 @@
|
|||
"submit": "Enter",
|
||||
"loading": "Authenticating...",
|
||||
"invalidCredentials": "Invalid username or password"
|
||||
},
|
||||
"error": {
|
||||
"filesLostAfterRefresh": "Files were lost after page refresh. Redirecting to home to re-select files…"
|
||||
}
|
||||
}
|
||||
|
|
@ -706,5 +706,8 @@
|
|||
"submit": "Entrar",
|
||||
"loading": "Autenticando...",
|
||||
"invalidCredentials": "Usuario o contraseña incorrectos"
|
||||
},
|
||||
"error": {
|
||||
"filesLostAfterRefresh": "Los archivos se perdieron al refrescar la página. Redirigiendo al inicio para volver a seleccionarlos…"
|
||||
}
|
||||
}
|
||||
|
|
@ -707,5 +707,8 @@
|
|||
"submit": "登录",
|
||||
"loading": "验证中...",
|
||||
"invalidCredentials": "用户名或密码错误"
|
||||
},
|
||||
"error": {
|
||||
"filesLostAfterRefresh": "刷新页面后文件丢失,正在跳转到首页重新选择文件…"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue