refactor: 重构卫星选择器为独立组件,优化代码结构和性能
Some checks failed
/ playwright (push) Blocked by required conditions
/ depcheck (push) Successful in 2m10s
/ build-and-deploy-to-vercel (push) Has been cancelled
/ surge (push) Has been cancelled
/ lint-build-and-check (push) Has been cancelled

This commit is contained in:
严浩
2025-03-12 14:29:38 +08:00
parent ff46fdd637
commit 92d795ba88
4 changed files with 209 additions and 172 deletions

View File

@ -1,4 +1,4 @@
import { computed, reactive } from 'vue';
import { computed, reactive, watch } from 'vue';
const layoutConfig = reactive({
darkTheme: false,
@ -8,17 +8,31 @@ const layoutConfig = reactive({
surface: null,
});
// 从 localStorage 读取初始状态,如果没有则使用默认值 false
const getStoredMenuState = (): boolean => {
const stored = localStorage.getItem('staticMenuDesktopInactive');
return stored ? JSON.parse(stored) : false;
};
const layoutState = reactive({
activeMenuItem: null,
configSidebarVisible: false,
menuHoverActive: false,
overlayMenuActive: false,
profileSidebarVisible: false,
staticMenuDesktopInactive: false,
staticMenuDesktopInactive: getStoredMenuState(),
staticMenuMobileActive: false,
});
export function useLayout() {
// 监听 staticMenuDesktopInactive 的变化并保存到 localStorage
watch(
() => layoutState.staticMenuDesktopInactive,
(newValue) => {
localStorage.setItem('staticMenuDesktopInactive', JSON.stringify(newValue));
},
);
const setActiveMenuItem = (item: Record<string, never>) => {
layoutState.activeMenuItem = item.value || item;
};