更新返回按钮逻辑,添加从场景页面跳转的状态管理

This commit is contained in:
2026-04-15 19:34:19 +08:00
parent 913dea7afa
commit 5079f17df0

View File

@@ -29,7 +29,7 @@
<span>保存</span> <span>保存</span>
</a-button> </a-button>
<a-button v-if="currentScenarioId" class="ks-model-builder-save" size="small" @click="handleGoback"> <a-button v-if="fromScenarioPage" class="ks-model-builder-save" size="small" @click="handleGoback">
<BackwardFilled /> <BackwardFilled />
<span>返回</span> <span>返回</span>
</a-button> </a-button>
@@ -125,6 +125,7 @@ export default defineComponent({
const nodeCommands = ref<NodeCommand[]>([]) const nodeCommands = ref<NodeCommand[]>([])
const currentScenarioId = ref<number | undefined>(); const currentScenarioId = ref<number | undefined>();
const currentPlatformId = ref<number | null>(null); const currentPlatformId = ref<number | null>(null);
const fromScenarioPage = ref<boolean>(false);
const { const {
handleGraphEvent, handleGraphEvent,
@@ -269,8 +270,7 @@ export default defineComponent({
const handleSelectTree = (tree: BehaviorTree) => { const handleSelectTree = (tree: BehaviorTree) => {
destroyGraph(); destroyGraph();
currentPlatformId.value = null; currentPlatformId.value = null;
// currentScenarioId.value = undefined;
console.info('handleSelectTree', tree); console.info('handleSelectTree', tree);
findOneTreeById(tree.id).then(r => { findOneTreeById(tree.id).then(r => {
@@ -334,14 +334,27 @@ export default defineComponent({
}); });
}; };
const STORAGE_KEY_SCENARIO = 'designer_from_scenario_id';
const resolveQuery = ()=> { const resolveQuery = ()=> {
console.log(currentRoute); console.log(currentRoute);
let scenarioId = Number(currentRoute.query.scenario); let scenarioId = Number(currentRoute.query.scenario);
if (!isNaN(scenarioId)) { if (!isNaN(scenarioId) && scenarioId > 0) {
currentScenarioId.value = scenarioId; currentScenarioId.value = scenarioId;
fromScenarioPage.value = true;
sessionStorage.setItem(STORAGE_KEY_SCENARIO, String(scenarioId));
} else { } else {
currentScenarioId.value = undefined; // 尝试从 sessionStorage 恢复(页面刷新或 SPA 内部跳转后 query 参数丢失的情况)
const stored = sessionStorage.getItem(STORAGE_KEY_SCENARIO);
const storedId = Number(stored);
if (stored && !isNaN(storedId) && storedId > 0) {
currentScenarioId.value = storedId;
fromScenarioPage.value = true;
} else {
currentScenarioId.value = undefined;
fromScenarioPage.value = false;
}
} }
let platformId = Number(currentRoute.query.platform); let platformId = Number(currentRoute.query.platform);
if (!isNaN(platformId)) { if (!isNaN(platformId)) {
@@ -444,7 +457,7 @@ export default defineComponent({
initGraph(); initGraph();
window.addEventListener('resize', handleResize); window.addEventListener('resize', handleResize);
console.log('节点挂载完成'); console.log('节点挂载完成');
resolveQuery(); resolveQuery();
if (currentPlatformId.value) { if (currentPlatformId.value) {
@@ -476,6 +489,7 @@ export default defineComponent({
}; };
const handleGoback = ()=> { const handleGoback = ()=> {
sessionStorage.removeItem(STORAGE_KEY_SCENARIO);
window.location.href = `/app/decision/communication?scenario=${currentScenarioId.value}` window.location.href = `/app/decision/communication?scenario=${currentScenarioId.value}`
} }
@@ -555,6 +569,7 @@ export default defineComponent({
handleUpdateElement, handleUpdateElement,
handleSelectTree, handleSelectTree,
handleGoback, handleGoback,
fromScenarioPage,
}; };
}, },
}); });