sign.vue 3.5 KB

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