feat: 在场景编辑器中新增视图状态保存与恢复功能,优化用户体验

This commit is contained in:
xudan 2025-07-01 19:24:29 +08:00
parent 3b6f429442
commit fbb266f97d

View File

@ -1,6 +1,7 @@
<script setup lang="ts">
import { getSceneById, pushSceneById, saveSceneById } from '@api/scene';
import { EditorService } from '@core/editor.service';
import { useViewState } from '@core/useViewState';
import { decodeTextFile, downloadFile, selectFile, textToBlob } from '@core/utils';
import { message, Modal } from 'ant-design-vue';
import { computed, watch } from 'vue';
@ -52,7 +53,11 @@ const pushScene = async () => {
const title = ref<string>('');
watch(
() => props.id,
() => readScene(),
async () => {
await readScene();
//
await handleRestoreViewState();
},
{ immediate: true, flush: 'post' },
);
@ -124,6 +129,32 @@ const selectRobot = (id: string) => {
current.value = { type: 'robot', id };
editor.value?.inactive();
};
//
const { saveViewState, restoreViewState, isSaving } = useViewState();
//
const handleSaveViewState = async () => {
if (!editor.value) return;
try {
await saveViewState(editor.value, props.id);
message.success('视图状态保存成功');
} catch {
message.error('视图状态保存失败');
}
};
//
const handleRestoreViewState = async () => {
if (!editor.value) return;
const restored = await restoreViewState(editor.value, props.id);
if (!restored) {
// 使centerView
editor.value.centerView();
}
};
</script>
<template>
@ -132,6 +163,7 @@ const selectRobot = (id: string) => {
<a-flex justify="space-between" align="center">
<a-typography-text class="title">{{ title }} --场景编辑</a-typography-text>
<a-space align="center">
<a-button type="primary" :loading="isSaving" @click="handleSaveViewState"> 保存比例 </a-button>
<a-button v-if="editable" class="warning" @click="editable = false">
<i class="icon exit size-18 mr-8" />
<span>{{ $t('退出编辑器') }}</span>