path.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { diffArrayChange, mount, shallowWatchArray } from "@/utils";
  2. import TaggingComponent from "@/components/path/list.vue";
  3. import { Path as PathData, paths } from "@/store/path";
  4. import { Path, SDK } from "../sdk";
  5. import { reactive, watch } from "vue";
  6. import { groupProxy } from "@/store/group";
  7. import { isScenePlayRun, pauseScene, playScene } from "@/utils/full";
  8. // -----------------导览线关联--------------------
  9. export type PathNode = Path;
  10. export type PathsNode = { node: PathNode; id: PathData["id"] }[];
  11. const pathNodes = reactive(new Map<PathData, PathNode>());
  12. export const getPathNode = (
  13. path: PathData | PathData["id"]
  14. ): undefined | PathNode => {
  15. if (typeof path !== "object") {
  16. path = paths.value.find((item) => item.id === path)!;
  17. if (!path) return void 0;
  18. }
  19. return pathNodes.get(path);
  20. };
  21. export const taggingsGroup = groupProxy(() => {
  22. const nodes = [] as PathNode[];
  23. for (const path of paths.value) {
  24. const node = getPathNode(path);
  25. if (node) {
  26. nodes.push(node);
  27. }
  28. }
  29. return nodes;
  30. });
  31. export const playScenePath = (
  32. path: PathData,
  33. forceFull = false
  34. ) => {
  35. const node = getPathNode(path)
  36. if (!node) return null;
  37. playScene({
  38. play: () => {
  39. return new Promise(resolve => {
  40. node.play(resolve)
  41. })
  42. },
  43. pause: () => {
  44. node.pause();
  45. }
  46. }, forceFull)
  47. }
  48. export const pauseScenePath = pauseScene
  49. export const isScenePathPlayIng = isScenePlayRun
  50. export const associationPaths = (sdk: SDK, el: HTMLDivElement) => {
  51. mount<PathsNode>(el, TaggingComponent, { paths }, (pathsNode) => {
  52. watch(
  53. () => {
  54. pathsNode.forEach(i => !!i?.id)
  55. return pathsNode
  56. },
  57. (nodes, oldNodes = []) => {
  58. const { added, deleted } = diffArrayChange<PathsNode>(
  59. nodes,
  60. oldNodes as PathsNode
  61. );
  62. for (const add of added) {
  63. if (add) {
  64. const path = paths.value.find((item) => item.id === add.id)!;
  65. pathNodes.set(path, add.node);
  66. }
  67. }
  68. for (const del of deleted) {
  69. if (del) {
  70. const path = paths.value.find((item) => item.id === del.id)!;
  71. pathNodes.delete(path);
  72. }
  73. }
  74. },
  75. {immediate: true}
  76. );
  77. });
  78. };