feat: remember last edited scene path in editor via localStorage

This commit is contained in:
2026-06-14 21:31:46 +08:00
parent 34e11a4f52
commit 7c80fc431c
2 changed files with 18 additions and 2 deletions

View File

@@ -79,7 +79,23 @@ async function loadDemo() {
}
}
onMounted(() => loadDemo())
async function restoreOrLoad() {
const lastSource = localStorage.getItem('editor_last_source')
if (lastSource) {
try {
loading.value = true
const resp = await fetch(lastSource)
if (resp.ok) {
store.loadJSON(await resp.json())
store.setSourcePath(lastSource)
return
}
} catch {}
}
await loadDemo()
}
onMounted(() => restoreOrLoad())
</script>
<template>

View File

@@ -130,7 +130,7 @@ export const useEditorStore = defineStore('editor', () => {
dirty.value = true
}
function setSourcePath(p: string) { sourcePath.value = p }
function setSourcePath(p: string) { sourcePath.value = p; localStorage.setItem('editor_last_source', p) }
async function autoSave() {
try {