line.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <TempLine
  3. :data="tData"
  4. :ref="(v: any) => shape = v?.shape"
  5. :id="data.id"
  6. @update:position="updatePosition"
  7. @update="emit('updateShape', { ...data })"
  8. @deletePoint="deletePoint"
  9. @addPoint="addPoint"
  10. canEdit
  11. />
  12. <PropertyUpdate
  13. :describes="describes"
  14. :data="data"
  15. :target="shape"
  16. @change="emit('updateShape', { ...data })"
  17. @delete="emit('delShape')"
  18. />
  19. <Operate :target="shape" :menus="operateMenus" />
  20. </template>
  21. <script lang="ts" setup>
  22. import { SLineData, getMouseStyle, defaultStyle, matResponse } from "./index.ts";
  23. import { useComponentStatus } from "@/core/hook/use-component.ts";
  24. import { PropertyUpdate, Operate } from "../../html-mount/propertys/index.ts";
  25. import TempLine from "./temp-line.vue";
  26. import { useInteractiveDrawShapeAPI } from "@/core/hook/use-draw.ts";
  27. import { useStore } from "@/core/store/index.ts";
  28. import { Pos } from "@/utils/math.ts";
  29. const props = defineProps<{ data: SLineData }>();
  30. const emit = defineEmits<{
  31. (e: "updateShape", value: SLineData): void;
  32. (e: "addShape", value: SLineData): void;
  33. (e: "delShape"): void;
  34. }>();
  35. const { shape, tData, data, operateMenus, describes } = useComponentStatus({
  36. emit,
  37. props,
  38. getMouseStyle,
  39. transformType: "line",
  40. // alignment(data, mat) {
  41. // return matResponse({ mat, data, increment: true });
  42. // },
  43. // type: "line",
  44. defaultStyle,
  45. copyHandler(mat, data) {
  46. return matResponse({ mat, data, increment: true });
  47. },
  48. propertys: [
  49. "stroke",
  50. "strokeWidth",
  51. // "dash",
  52. "opacity",
  53. // "ref", "zIndex"
  54. ],
  55. });
  56. const updatePosition = ({ ndx, val }: { ndx: number; val: Pos }) => {
  57. Object.assign(data.value.points[ndx], val);
  58. shape.value?.getNode().fire("bound-change");
  59. };
  60. const deletePoint = (ndx: number) => {
  61. data.value.points.splice(ndx, 1);
  62. if (data.value.points.length <= 1) {
  63. emit("delShape");
  64. } else {
  65. shape.value?.getNode().fire("bound-change");
  66. }
  67. };
  68. const addPoint = ({ ndx, val }: { ndx: number; val: Pos }) => {
  69. data.value.points.splice(ndx + 1, 0, val);
  70. shape.value?.getNode().fire("bound-change");
  71. };
  72. const draw = useInteractiveDrawShapeAPI();
  73. const store = useStore();
  74. operateMenus.push({
  75. label: "钢笔编辑",
  76. handler() {
  77. draw.enterDrawShape("sequentLine", {
  78. ...props.data,
  79. getMessages: () => {
  80. const line = store.getItemById(props.data.id) as SLineData;
  81. return line ? line.points : [];
  82. },
  83. });
  84. },
  85. });
  86. </script>