import { computed, ref, toRefs } from 'vue'; import useSceneInfos from '@/hooks/useSceneInfos'; import { CameraItem, getWorkshopMiniMapLayoutApi } from '@/api/scene/scene'; import { defineStore } from 'pinia'; import safeParse from '@/utils/safeParse'; type ShopMapCamera = CameraItem & { /** 相机是否已经设置 0-false 1-true */ isSet: number; /** 工位名称 */ workSpaceName: string; }; export const useMiniMap = defineStore('mini-map', () => { const sceneInfos = useSceneInfos(); const { scenesTree, workSpaces } = toRefs(sceneInfos); const { getScenesTree, getCameraList } = sceneInfos; const selectedShopId = ref(); const selectedShop = computed(() => workSpaces.value.find((space) => space.id === selectedShopId.value), ); const bgImgUrl = ref(''); const shopCameraList = ref([]); const getShowCameras = () => { shopCameraList.value = []; getCameraList(selectedShopId.value!).then((res) => { res.forEach((space) => { if (space.cameraList && space.cameraList.length > 0) { space.cameraList.forEach((camera) => { shopCameraList.value.push({ ...camera, isSet: 0, workSpaceName: space.name }); }); } }); }); }; const getMapLayout = () => { return getWorkshopMiniMapLayoutApi(selectedShopId.value + '').then((res) => { const layoutJSON = res?.layout ? safeParse(res.layout) : null; return layoutJSON; }); }; return { selectedShop, bgImgUrl, scenesTree, shopCameraList, getScenesTree, getShowCameras, getMapLayout, selectedShopId, }; }); export default useMiniMap;