task 1: 自动保存(30s) — 新增autoSaveTimer每30秒静默保存草稿
This commit is contained in:
@@ -708,6 +708,7 @@ async function deleteNode(dimKey: string, oi: number) {
|
|||||||
|
|
||||||
// ── 保存 ──
|
// ── 保存 ──
|
||||||
let saveTimer: ReturnType<typeof setTimeout> | null = null
|
let saveTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
let autoSaveTimer: ReturnType<typeof setInterval> | null = null
|
||||||
let isSaving = false
|
let isSaving = false
|
||||||
|
|
||||||
function debouncedSaveCanvas() {
|
function debouncedSaveCanvas() {
|
||||||
@@ -716,7 +717,7 @@ function debouncedSaveCanvas() {
|
|||||||
saveTimer = setTimeout(() => { saveCanvas() }, 500)
|
saveTimer = setTimeout(() => { saveCanvas() }, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveCanvas() {
|
async function saveCanvas(silent?: boolean) {
|
||||||
if (!selectedMap.value) return
|
if (!selectedMap.value) return
|
||||||
if (isSaving) return
|
if (isSaving) return
|
||||||
isSaving = true
|
isSaving = true
|
||||||
@@ -730,7 +731,7 @@ async function saveCanvas() {
|
|||||||
canvas_data: { connections: connections.value },
|
canvas_data: { connections: connections.value },
|
||||||
version_num: currentMap.value?.version_num,
|
version_num: currentMap.value?.version_num,
|
||||||
})
|
})
|
||||||
ElMessage.success("已保存")
|
if (!silent) ElMessage.success("已保存")
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e?.response?.status === 409) {
|
if (e?.response?.status === 409) {
|
||||||
ElMessage.warning("地图已被修改,刷新后重试")
|
ElMessage.warning("地图已被修改,刷新后重试")
|
||||||
@@ -927,12 +928,17 @@ onMounted(async () => {
|
|||||||
for (const kpi of allKpis.value) {
|
for (const kpi of allKpis.value) {
|
||||||
if (kpi.kpi_code) kpiNameMap[kpi.kpi_code] = kpi.kpi_name || kpi.kpi_code
|
if (kpi.kpi_code) kpiNameMap[kpi.kpi_code] = kpi.kpi_name || kpi.kpi_code
|
||||||
}
|
}
|
||||||
|
// 自动保存:每30秒自动保存草稿
|
||||||
|
autoSaveTimer = setInterval(() => {
|
||||||
|
if (currentMap?.status === 'draft') saveCanvas(true)
|
||||||
|
}, 30000)
|
||||||
window.addEventListener('resize', triggerRecalc)
|
window.addEventListener('resize', triggerRecalc)
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
window.removeEventListener('resize', triggerRecalc)
|
window.removeEventListener('resize', triggerRecalc)
|
||||||
if (saveTimer) clearTimeout(saveTimer)
|
if (saveTimer) clearTimeout(saveTimer)
|
||||||
|
if (autoSaveTimer) clearInterval(autoSaveTimer)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user