|
|
@@ -3,6 +3,7 @@ import useSceneInfos from '@/hooks/useSceneInfos';
|
|
|
import { CameraItem, getWorkshopMiniMapLayoutApi } from '@/api/scene/scene';
|
|
|
import { defineStore } from 'pinia';
|
|
|
import safeParse from '@/utils/safeParse';
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
|
|
|
type ShopMapCamera = CameraItem & {
|
|
|
/** 相机是否已经设置 0-false 1-true */
|
|
|
@@ -13,20 +14,30 @@ type ShopMapCamera = CameraItem & {
|
|
|
|
|
|
export const useMiniMap = defineStore('mini-map', () => {
|
|
|
const sceneInfos = useSceneInfos();
|
|
|
- const { scenesTree, workSpaces } = toRefs(sceneInfos);
|
|
|
+ const { scenesTree, flattenedWorkshops } = toRefs(sceneInfos);
|
|
|
const { getScenesTree, getCameraList } = sceneInfos;
|
|
|
|
|
|
- const selectedShopId = ref<number>();
|
|
|
- const selectedShop = computed(() =>
|
|
|
- workSpaces.value.find((space) => space.id === selectedShopId.value),
|
|
|
+ const selectedShopCode = ref<string>();
|
|
|
+ const selectedShopDetail = computed(() =>
|
|
|
+ flattenedWorkshops.value.find((space) => space.code === selectedShopCode.value),
|
|
|
);
|
|
|
+
|
|
|
+ const getShopDetailByCode = (code: string) => {
|
|
|
+ return flattenedWorkshops.value.find((space) => space.code === code);
|
|
|
+ };
|
|
|
const bgImgUrl = ref('');
|
|
|
|
|
|
const shopCameraList = ref<ShopMapCamera[]>([]);
|
|
|
|
|
|
- const getShowCameras = () => {
|
|
|
+ const getShowCameras = (code: string) => {
|
|
|
shopCameraList.value = [];
|
|
|
- getCameraList(selectedShopId.value!).then((res) => {
|
|
|
+ const id = getShopDetailByCode(code)?.id;
|
|
|
+
|
|
|
+ if (!id) {
|
|
|
+ ElMessage.error('摄像头code未找到对应信息');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ getCameraList(id).then((res) => {
|
|
|
res.forEach((space) => {
|
|
|
if (space.cameraList && space.cameraList.length > 0) {
|
|
|
space.cameraList.forEach((camera) => {
|
|
|
@@ -37,22 +48,27 @@ export const useMiniMap = defineStore('mini-map', () => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- const getMapLayout = () => {
|
|
|
- return getWorkshopMiniMapLayoutApi(selectedShopId.value + '').then((res) => {
|
|
|
+ const getMapLayout = (code: string) => {
|
|
|
+ const shopId = getShopDetailByCode(code)?.id || '';
|
|
|
+ if (!shopId) {
|
|
|
+ ElMessage.error('摄像头code未找到对应信息');
|
|
|
+ return Promise.reject();
|
|
|
+ }
|
|
|
+ return getWorkshopMiniMapLayoutApi(String(shopId)).then((res) => {
|
|
|
const layoutJSON = res?.layout ? safeParse(res.layout) : null;
|
|
|
return layoutJSON;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
return {
|
|
|
- selectedShop,
|
|
|
+ selectedShopDetail,
|
|
|
bgImgUrl,
|
|
|
scenesTree,
|
|
|
shopCameraList,
|
|
|
getScenesTree,
|
|
|
getShowCameras,
|
|
|
getMapLayout,
|
|
|
- selectedShopId,
|
|
|
+ selectedShopCode,
|
|
|
};
|
|
|
});
|
|
|
|