sign.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. console.log('points', points)
  60. currentPoints = points.map((p, ndx) => ({
  61. name: p.name,
  62. position: { ...p.position },
  63. modelId: p.modelId.toString(),
  64. hide: p.hide || false,
  65. }));
  66. emit("updatePoints", currentPoints);
  67. });
  68. path.bus.on("changeLineHeight", (val) => {
  69. emit("updateLineHeight", val);
  70. clearTimeout(changLineTimeout);
  71. });
  72. watchEffect(() => {
  73. path.changeName(props.path.name);
  74. });
  75. watch(
  76. () => props.path.points.map((i) => ({ modelId: i.modelId, position: i.position })),
  77. (p) => {
  78. console.log(p, 'watchEffect0', props.path.points);
  79. changPointsTimeout = setTimeout(() => {
  80. if (inRevise(props.path.points, currentPoints)) {
  81. path.changePathPoints(p);
  82. currentPoints = props.path.points;
  83. }
  84. }, 16);
  85. },
  86. { deep: true, flush: "post" }
  87. );
  88. watchEffect(() => {
  89. props.path.points.forEach((point, index) => {
  90. // 监听 name 属性
  91. watch(() => point.name, (newName) => {
  92. path.changePointName(index, newName);
  93. currentPoints[index].name = newName;
  94. });
  95. // 监听 hide 属性
  96. watch(() => point.hide, (newHide) => {
  97. if (path.changePointDisplay) {
  98. path.changePointDisplay(index, !newHide);
  99. }
  100. });
  101. });
  102. },{ deep: true, flush: "post" });
  103. watchEffect(() => {
  104. path.changeDirection(props.path.showDirection, props.path.reverseDirection);
  105. });
  106. let currentLine = getLineProps();
  107. let changLineTimeout: any;
  108. watch(
  109. getLineProps,
  110. (val) => {
  111. changLineTimeout = setTimeout(() => {
  112. if (inRevise(val, currentLine)) {
  113. path.changeLine(val);
  114. currentLine = val;
  115. }
  116. }, 16);
  117. },
  118. { deep: true }
  119. );
  120. path.bus.on("linePositionChange", (position) => {
  121. const p = {
  122. position: { ...position.pos },
  123. modelId: position.modelId.toString(),
  124. };
  125. currentLine = { ...getLineProps(), ...p };
  126. emit("updateLinePosition", p);
  127. });
  128. onUnmounted(() => {
  129. path.destroy();
  130. });
  131. defineExpose(path);
  132. </script>
  133. <style lang="scss" scoped></style>