2026-06-03 15:03:31 +08:00
|
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
|
|
import { ref } from 'vue';
|
2026-06-26 18:00:09 +08:00
|
|
|
|
import dayjs from 'dayjs';
|
2026-06-03 15:03:31 +08:00
|
|
|
|
|
|
|
|
|
|
export const useMapViewStore = defineStore('map-view', () => {
|
|
|
|
|
|
const checkedLayerKeys = ref<string[]>([]);
|
|
|
|
|
|
const legendCheckedState = ref<Record<string, number>>({});
|
2026-06-26 18:00:09 +08:00
|
|
|
|
const searchTimeRange = ref<[any, any]>([dayjs().subtract(1, 'M'), dayjs()]);
|
2026-06-03 15:03:31 +08:00
|
|
|
|
const selectedBaseId = ref('');
|
|
|
|
|
|
const currentZoomLevel = ref(4.5);
|
|
|
|
|
|
|
|
|
|
|
|
// 备注:统一写入当前选中的图层 key,始终保持去重后的结果。
|
|
|
|
|
|
const setCheckedLayerKeys = (keys: string[] = []) => {
|
|
|
|
|
|
checkedLayerKeys.value = Array.from(new Set(keys.filter(Boolean)));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 备注:获取当前选中的图层 key,供图层树、动态图层和筛选联动复用。
|
|
|
|
|
|
const getCheckedLayerKeys = (): string[] => {
|
|
|
|
|
|
return checkedLayerKeys.value;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 备注:覆盖写入完整图例运行态勾选状态,适合图例初始化和整批替换。
|
|
|
|
|
|
const setLegendCheckedState = (state: Record<string, number> = {}) => {
|
|
|
|
|
|
legendCheckedState.value = { ...state };
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 备注:写入单个图例运行态勾选状态,供点击图例项时复用。
|
|
|
|
|
|
const setLegendChecked = (nameEn: string, checked: number) => {
|
|
|
|
|
|
if (!nameEn) return;
|
|
|
|
|
|
legendCheckedState.value = {
|
|
|
|
|
|
...legendCheckedState.value,
|
|
|
|
|
|
[nameEn]: checked
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 备注:批量写入多个图例运行态勾选状态,供分组图例和筛选联动复用。
|
|
|
|
|
|
const setLegendCheckedBatch = (
|
|
|
|
|
|
stateMap: Record<string, number> = {}
|
|
|
|
|
|
) => {
|
|
|
|
|
|
legendCheckedState.value = {
|
|
|
|
|
|
...legendCheckedState.value,
|
|
|
|
|
|
...stateMap
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 备注:获取单个图例当前运行态勾选状态,未命中时默认返回 0。
|
|
|
|
|
|
const getLegendChecked = (nameEn: string): number => {
|
|
|
|
|
|
return legendCheckedState.value[nameEn] ?? 0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 备注:统一更新当前时间筛选范围,供筛选组件和地图数据重载复用。
|
|
|
|
|
|
const setSearchTimeRange = (range: [any, any]) => {
|
|
|
|
|
|
searchTimeRange.value = range;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 备注:统一更新当前基地 ID,供地图筛选和基地联动复用。
|
|
|
|
|
|
const setSelectedBaseId = (baseId: string) => {
|
|
|
|
|
|
selectedBaseId.value = baseId || '';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 备注:统一更新当前地图缩放级别,供动态图层联动复用。
|
|
|
|
|
|
const setCurrentZoomLevel = (zoom: number) => {
|
|
|
|
|
|
currentZoomLevel.value = zoom;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 备注:在菜单切换或地图销毁时重置运行态到默认值。
|
|
|
|
|
|
const resetViewState = () => {
|
|
|
|
|
|
checkedLayerKeys.value = [];
|
|
|
|
|
|
legendCheckedState.value = {};
|
2026-06-26 18:00:09 +08:00
|
|
|
|
searchTimeRange.value = [dayjs().subtract(1, 'M'), dayjs()];
|
2026-06-03 15:03:31 +08:00
|
|
|
|
selectedBaseId.value = '';
|
|
|
|
|
|
currentZoomLevel.value = 4.5;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
checkedLayerKeys,
|
|
|
|
|
|
legendCheckedState,
|
|
|
|
|
|
searchTimeRange,
|
|
|
|
|
|
selectedBaseId,
|
|
|
|
|
|
currentZoomLevel,
|
|
|
|
|
|
setCheckedLayerKeys,
|
|
|
|
|
|
getCheckedLayerKeys,
|
|
|
|
|
|
setLegendCheckedState,
|
|
|
|
|
|
setLegendChecked,
|
|
|
|
|
|
setLegendCheckedBatch,
|
|
|
|
|
|
getLegendChecked,
|
|
|
|
|
|
setSearchTimeRange,
|
|
|
|
|
|
setSelectedBaseId,
|
|
|
|
|
|
setCurrentZoomLevel,
|
|
|
|
|
|
resetViewState
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|