useSceneInfos.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { computed, ref } from 'vue';
  2. import { getShopSpaceList, getCamerasByWorkShopId } from '@/api/scene/scene';
  3. import { CompanyInfoItem } from '@/types/scene/type.ts';
  4. import { calculateTreeData, ElTreeItem, TreeProps } from '@/utils';
  5. export function useSceneInfos() {
  6. const scenesInfos = ref<CompanyInfoItem[]>([]);
  7. const scenesTree = ref<ElTreeItem[]>([]);
  8. const flattenedWorkshops = computed(() => {
  9. return scenesInfos.value.reduce((total, next) => [...total, ...next.children], []);
  10. });
  11. const flattendWorkspaces = computed(() => {
  12. return scenesInfos.value.reduce((total, next) => {
  13. let newArr: any[] = [];
  14. if (next.children && next.children.length) {
  15. newArr = next.children.reduce((subTotal, subNext) => [...subTotal, ...subNext.children], []);
  16. }
  17. return [...total, ...newArr];
  18. }, []);
  19. });
  20. const getScenesTree = (treeProps: TreeProps) => {
  21. getShopSpaceList().then((res) => {
  22. scenesInfos.value = res;
  23. scenesTree.value = calculateTreeData(res, treeProps, 1);
  24. });
  25. };
  26. return {
  27. scenesInfos,
  28. scenesTree,
  29. flattenedWorkshops,
  30. flattendWorkspaces,
  31. getScenesTree,
  32. calculateTreeData,
  33. };
  34. }
  35. export default useSceneInfos;