SEC_Warehouse/store/scene.js

43 lines
936 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 当前场景全局状态:内存 + 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)
}