sign.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <!-- <template v-if="show">
  3. <div :style="linePixel">
  4. {{ path.name }}
  5. </div>
  6. <template v-for="(p, i) in pointPixels">
  7. <span :style="p" v-if="p && path.points[i].name">
  8. {{ path.points[i].name }}
  9. </span>
  10. </template>
  11. </template> -->
  12. </template>
  13. <script lang="ts" setup>
  14. import { computed, onUnmounted, ref, watch, watchEffect } from "vue";
  15. import { sdk } from "@/sdk";
  16. import type { Path } from "@/store";
  17. import { inRevise } from "bill/utils";
  18. export type SignProps = { path: Path };
  19. const props = defineProps<SignProps>();
  20. const emit = defineEmits<{
  21. (e: "delete"): void;
  22. (e: "updateLinePosition", val: Path["linePosition"]): void;
  23. (e: "updatePoints", val: Path["points"]): void;
  24. }>();
  25. const getLineProps = () => ({
  26. width: props.path.lineWidth,
  27. color: props.path.lineColor,
  28. altitudeAboveGround: props.path.lineAltitudeAboveGround,
  29. position: props.path.linePosition?.position,
  30. modelId: props.path.linePosition?.modelId,
  31. });
  32. const path = sdk.createPath({
  33. name: props.path.name,
  34. showName: props.path.showName,
  35. fontSize: props.path.fontSize,
  36. showDirection: props.path.showDirection,
  37. reverseDirection: props.path.reverseDirection,
  38. line: getLineProps(),
  39. points: props.path.points,
  40. });
  41. console.log(getLineProps());
  42. // path.changeCanEdit(false);
  43. watchEffect(() => path.visibilityName(props.path.showName));
  44. watchEffect(() => path.changeFontSize(props.path.fontSize));
  45. watchEffect(() => {
  46. path.changeDirection(props.path.showDirection, props.path.reverseDirection);
  47. });
  48. watchEffect(() => {
  49. const range = props.path.globalVisibility ? -1 : props.path.visibilityRange;
  50. path.changeVisibilityRange(range);
  51. });
  52. let currentPoints = props.path.points;
  53. let changPointsTimeout: any;
  54. path.bus.on("changePoints", (points) => {
  55. clearTimeout(changPointsTimeout);
  56. currentPoints = points.map((p, ndx) => ({
  57. name: p.name,
  58. position: { ...p.position },
  59. modelId: p.modelId.toString(),
  60. }));
  61. emit("updatePoints", currentPoints);
  62. });
  63. watchEffect(() => {
  64. path.changeName(props.path.name);
  65. });
  66. watch(
  67. () => props.path.points.map((i) => ({ modelId: i.modelId, position: i.position })),
  68. (p) => {
  69. changPointsTimeout = setTimeout(() => {
  70. if (inRevise(props.path.points, currentPoints)) {
  71. path.changePathPoints(p);
  72. currentPoints = props.path.points;
  73. }
  74. }, 16);
  75. },
  76. { deep: true, flush: "post" }
  77. );
  78. watchEffect(() => {
  79. for (const point of props.path.points) {
  80. watchEffect(() => {
  81. const ndx = props.path.points.indexOf(point);
  82. if (~ndx) {
  83. path.changePointName(ndx, point.name);
  84. currentPoints[ndx].name = point.name;
  85. }
  86. });
  87. }
  88. });
  89. let currentLine = getLineProps();
  90. let changLineTimeout: any;
  91. watch(
  92. getLineProps,
  93. (val) => {
  94. changLineTimeout = setTimeout(() => {
  95. if (inRevise(val, currentLine)) {
  96. path.changeLine(val);
  97. currentLine = val;
  98. }
  99. }, 16);
  100. },
  101. { deep: true }
  102. );
  103. path.bus.on("linePositionChange", (position) => {
  104. const p = {
  105. position: { ...position.pos },
  106. modelId: position.modelId.toString(),
  107. };
  108. currentLine = { ...getLineProps(), ...p };
  109. emit("updateLinePosition", p);
  110. });
  111. onUnmounted(() => {
  112. path.destroy();
  113. });
  114. defineExpose(path);
  115. </script>
  116. <style lang="scss" scoped></style>