frame.vue 1.5 KB

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