use-mini-map.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { computed, ref, toRefs } from 'vue';
  2. import useSceneInfos from '@/hooks/useSceneInfos';
  3. import { getCamerasByWorkShopId, getWorkshopMiniMapLayoutPCApi } from '@/api/scene/scene';
  4. import { CameraItem } from '@/types/scene/type.ts';
  5. import { defineStore } from 'pinia';
  6. import safeParse from '@/utils/safeParse';
  7. import { ElMessage } from 'element-plus';
  8. type ShopMapCamera = CameraItem & {
  9. /** 相机是否已经设置 0-false 1-true */
  10. isSet: number;
  11. /** 工位名称 */
  12. workSpaceName: string;
  13. integrationState?: number;
  14. };
  15. export const useMiniMap = defineStore('mini-map', () => {
  16. const sceneInfos = useSceneInfos();
  17. const { scenesTree, flattenedWorkshops } = toRefs(sceneInfos);
  18. const { getScenesTree } = sceneInfos;
  19. // const selectedShopCode = ref<string>();
  20. // const selectedShopDetail = computed(() =>
  21. // flattenedWorkshops.value.find((space) => space.code === selectedShopCode.value),
  22. // );
  23. // const getShopDetailByCode = (code: string) => {
  24. // return flattenedWorkshops.value.find((space) => space.code === code);
  25. // };
  26. const bgImgUrl = ref('');
  27. /**
  28. * 切换租户管理的时候需要判断是否在布局编辑器里面
  29. */
  30. const isInConfigEditor = (routerName: string) => {
  31. if (routerName.includes('LayoutSceneConfig') || routerName.includes('LayoutCameraConfig')) {
  32. return true;
  33. }
  34. return false;
  35. };
  36. // const shopCameraList = ref<ShopMapCamera[]>([]);
  37. // const getShowCameras = (code: string) => {
  38. // shopCameraList.value = [];
  39. // const id = getShopDetailByCode(code)?.id;
  40. // if (!id) {
  41. // ElMessage.error('摄像头code未找到对应信息');
  42. // return Promise.resolve();
  43. // }
  44. // return getCamerasByWorkShopId({ workshopId: id }).then((res) => {
  45. // res.children?.forEach((space) => {
  46. // if (space.children && space.children.length > 0) {
  47. // space.children.forEach((camera) => {
  48. // shopCameraList.value.push({ ...camera, isSet: 0, workSpaceName: space.name });
  49. // });
  50. // }
  51. // });
  52. // });
  53. // };
  54. // const getMapLayout = (code: string) => {
  55. // const shopId = getShopDetailByCode(code)?.id || '';
  56. // if (!shopId) {
  57. // ElMessage.error('摄像头code未找到对应信息');
  58. // return Promise.reject();
  59. // }
  60. // return getWorkshopMiniMapLayoutPCApi(shopId).then((res) => {
  61. // const layoutJSON = res?.layout ? safeParse(res.layout) : null;
  62. // return layoutJSON;
  63. // });
  64. // };
  65. return {
  66. // selectedShopDetail,
  67. bgImgUrl,
  68. scenesTree,
  69. // shopCameraList,
  70. getScenesTree,
  71. isInConfigEditor,
  72. // getShowCameras,
  73. // getMapLayout,
  74. // selectedShopCode,
  75. };
  76. });
  77. export default useMiniMap;