frame.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <template v-for="(l, i) in lines">
  3. <v-line :config="l" :ref="(s: any) => frameShapes[i] = s" />
  4. </template>
  5. </template>
  6. <script lang="ts" setup>
  7. import { computed, ref } from "vue";
  8. import {
  9. flatPositions,
  10. useGlobalVar,
  11. useViewerInvertTransformConfig,
  12. } from "../drawing/hook";
  13. import { Transform } from "konva/lib/Util";
  14. import { Line } from "konva/lib/shapes/Line";
  15. import { DC } from "../drawing/dec";
  16. const { misPixel } = useGlobalVar();
  17. const props = defineProps<{ items: { time: number }[], top: number }>();
  18. const s = 6;
  19. const invConfig = useViewerInvertTransformConfig();
  20. const lines = computed(() => {
  21. return props.items.map((item) => {
  22. const origin = { x: item.time * misPixel, y: props.top + 10 };
  23. const points = [
  24. { x: origin.x - s / 2, y: origin.y },
  25. { x: origin.x + s / 2, y: origin.y },
  26. { x: origin.x + s / 2, y: origin.y + s * 1.5 },
  27. { x: origin.x, y: origin.y + s * 2 },
  28. { x: origin.x - s / 2, y: origin.y + s * 1.5 },
  29. ];
  30. return {
  31. points: flatPositions(points),
  32. closed: true,
  33. fill: "#fff",
  34. ...new Transform()
  35. .translate(origin.x, 0)
  36. .scale(invConfig.value.scaleX, 1)
  37. .translate(-origin.x, 0)
  38. .decompose(),
  39. };
  40. });
  41. });
  42. const frameShapes = ref<DC<Line>[]>([]);
  43. defineExpose({
  44. get shapes() {
  45. return frameShapes.value;
  46. },
  47. });
  48. </script>