sign.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. (e: "updateLineHeight", val: Path["lineAltitudeAboveGround"]): void;
  25. }>();
  26. const getLineProps = () => ({
  27. width: props.path.lineWidth,
  28. color: props.path.lineColor,
  29. altitudeAboveGround: props.path.lineAltitudeAboveGround,
  30. position: props.path.linePosition?.position,
  31. modelId: props.path.linePosition?.modelId,
  32. });
  33. const path = sdk.createPath({
  34. name: props.path.name,
  35. showName: props.path.showName,
  36. fontSize: props.path.fontSize,
  37. opacity: props.path.opacity,
  38. showDirection: props.path.showDirection,
  39. reverseDirection: props.path.reverseDirection,
  40. line: getLineProps(),
  41. points: props.path.points,
  42. });
  43. console.log(getLineProps());
  44. // path.changeCanEdit(false);
  45. watchEffect(() => path.visibilityName(props.path.showName));
  46. watchEffect(() => path.changeFontSize(props.path.fontSize));
  47. watchEffect(() => path.changeOpacity(props.path.opacity));
  48. watchEffect(() => {
  49. path.changeDirection(props.path.showDirection, props.path.reverseDirection);
  50. });
  51. watchEffect(() => {
  52. const range = props.path.globalVisibility ? -1 : props.path.visibilityRange;
  53. path.changeVisibilityRange(range);
  54. });
  55. let currentPoints = props.path.points;
  56. let changPointsTimeout: any;
  57. path.bus.on("changePoints", (points) => {
  58. clearTimeout(changPointsTimeout);
  59. currentPoints = points.map((p, ndx) => ({
  60. name: p.name,
  61. position: { ...p.position },
  62. modelId: p.modelId.toString(),
  63. }));
  64. emit("updatePoints", currentPoints);
  65. });
  66. path.bus.on("changeLineHeight", (val) => {
  67. emit("updateLineHeight", val);
  68. clearTimeout(changLineTimeout);
  69. });
  70. watchEffect(() => {
  71. path.changeName(props.path.name);
  72. });
  73. watch(
  74. () => props.path.points.map((i) => ({ modelId: i.modelId, position: i.position })),
  75. (p) => {
  76. changPointsTimeout = setTimeout(() => {
  77. if (inRevise(props.path.points, currentPoints)) {
  78. path.changePathPoints(p);
  79. currentPoints = props.path.points;
  80. }
  81. }, 16);
  82. },
  83. { deep: true, flush: "post" }
  84. );
  85. watchEffect(() => {
  86. for (const point of props.path.points) {
  87. watchEffect(() => {
  88. const ndx = props.path.points.indexOf(point);
  89. if (~ndx) {
  90. path.changePointName(ndx, point.name);
  91. currentPoints[ndx].name = point.name;
  92. }
  93. });
  94. }
  95. });
  96. let currentLine = getLineProps();
  97. let changLineTimeout: any;
  98. watch(
  99. getLineProps,
  100. (val) => {
  101. changLineTimeout = setTimeout(() => {
  102. if (inRevise(val, currentLine)) {
  103. path.changeLine(val);
  104. currentLine = val;
  105. }
  106. }, 16);
  107. },
  108. { deep: true }
  109. );
  110. path.bus.on("linePositionChange", (position) => {
  111. const p = {
  112. position: { ...position.pos },
  113. modelId: position.modelId.toString(),
  114. };
  115. currentLine = { ...getLineProps(), ...p };
  116. emit("updateLinePosition", p);
  117. });
  118. onUnmounted(() => {
  119. path.destroy();
  120. });
  121. defineExpose(path);
  122. </script>
  123. <style lang="scss" scoped></style>