/** * 当前场景全局状态:内存 + uni.storage 持久化。 * 项目未引入 Vuex/Pinia,采用轻量模块方案。 */ const STORAGE_KEY = 'current_scene' let currentScene = null // 模块加载时从本地存储恢复上次选中的场景。 function initFromStorage() { const cached = uni.getStorageSync(STORAGE_KEY) if (cached && cached.id !== undefined) { currentScene = cached } } initFromStorage() /** * 获取当前选中场景。 * @returns {{ id: *, name: string } | null} */ export function getCurrentScene() { return currentScene } /** * 设置当前场景并持久化。 * @param {{ id: *, name: string }} scene */ export function setCurrentScene(scene) { currentScene = scene uni.setStorageSync(STORAGE_KEY, scene) } /** * 清除当前场景(本地与持久化均清除)。 */ export function clearCurrentScene() { currentScene = null uni.removeStorageSync(STORAGE_KEY) }