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 @@
|
||||||
/**
|
/**
|
||||||
* 临时存储待上传的文件和需求
|
* Temporary storage for files and simulation requirement.
|
||||||
* 用于首页点击启动引擎后立即跳转,在Process页面再进行API调用
|
* - simulationRequirement: persisted to sessionStorage (survives refresh within the tab)
|
||||||
|
* - files: in-memory only (File objects are not JSON-serializable)
|
||||||
*/
|
*/
|
||||||
import { reactive } from 'vue'
|
import { reactive } from 'vue'
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
files: [],
|
files: [],
|
||||||
simulationRequirement: '',
|
simulationRequirement: sessionStorage.getItem('pendingRequirement') || '',
|
||||||
isPending: false,
|
isPending: sessionStorage.getItem('pendingIsPending') === 'true',
|
||||||
importOntologyMode: false,
|
importOntologyMode: false,
|
||||||
ontologyFile: null
|
ontologyFile: null,
|
||||||
})
|
})
|
||||||
|
|
||||||
export function setPendingUpload(files, requirement, importOntologyMode = false, 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.isPending = true
|
||||||
state.importOntologyMode = importOntologyMode
|
state.importOntologyMode = importOntologyMode
|
||||||
state.ontologyFile = ontologyFile
|
state.ontologyFile = ontologyFile
|
||||||
|
sessionStorage.setItem('pendingRequirement', requirement)
|
||||||
|
sessionStorage.setItem('pendingIsPending', 'true')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPendingUpload() {
|
export function getPendingUpload() {
|
||||||
|
|
@ -26,7 +29,7 @@ export function getPendingUpload() {
|
||||||
simulationRequirement: state.simulationRequirement,
|
simulationRequirement: state.simulationRequirement,
|
||||||
isPending: state.isPending,
|
isPending: state.isPending,
|
||||||
importOntologyMode: state.importOntologyMode,
|
importOntologyMode: state.importOntologyMode,
|
||||||
ontologyFile: state.ontologyFile
|
ontologyFile: state.ontologyFile,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,6 +39,8 @@ export function clearPendingUpload() {
|
||||||
state.isPending = false
|
state.isPending = false
|
||||||
state.importOntologyMode = false
|
state.importOntologyMode = false
|
||||||
state.ontologyFile = null
|
state.ontologyFile = null
|
||||||
|
sessionStorage.removeItem('pendingRequirement')
|
||||||
|
sessionStorage.removeItem('pendingIsPending')
|
||||||
}
|
}
|
||||||
|
|
||||||
export default state
|
export default state
|
||||||
|
|
|
||||||
|
|
@ -197,9 +197,16 @@ const initProject = async () => {
|
||||||
|
|
||||||
const handleNewProject = async () => {
|
const handleNewProject = async () => {
|
||||||
const pending = getPendingUpload()
|
const pending = getPendingUpload()
|
||||||
if (!pending.isPending || pending.files.length === 0) {
|
|
||||||
error.value = 'No pending files found.'
|
if (!pending.isPending) {
|
||||||
addLog('Error: No pending files found for new project.')
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -706,5 +706,8 @@
|
||||||
"submit": "Entrar",
|
"submit": "Entrar",
|
||||||
"loading": "Autenticant...",
|
"loading": "Autenticant...",
|
||||||
"invalidCredentials": "Usuari o contrasenya incorrectes"
|
"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",
|
"submit": "Enter",
|
||||||
"loading": "Authenticating...",
|
"loading": "Authenticating...",
|
||||||
"invalidCredentials": "Invalid username or password"
|
"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",
|
"submit": "Entrar",
|
||||||
"loading": "Autenticando...",
|
"loading": "Autenticando...",
|
||||||
"invalidCredentials": "Usuario o contraseña incorrectos"
|
"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": "登录",
|
"submit": "登录",
|
||||||
"loading": "验证中...",
|
"loading": "验证中...",
|
||||||
"invalidCredentials": "用户名或密码错误"
|
"invalidCredentials": "用户名或密码错误"
|
||||||
|
},
|
||||||
|
"error": {
|
||||||
|
"filesLostAfterRefresh": "刷新页面后文件丢失,正在跳转到首页重新选择文件…"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue