line.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. />
  18. <Operate :target="shape" :menus="operateMenus" />
  19. </template>
  20. <script lang="ts" setup>
  21. import { LineData, getMouseStyle, defaultStyle, matResponse } from "./index.ts";
  22. import { useComponentStatus } from "@/core/hook/use-component.ts";
  23. import { PropertyUpdate, Operate } from "../../html-mount/propertys/index.ts";
  24. import TempLine from "./temp-line.vue";
  25. import { EditPen } from "@element-plus/icons-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. import { de } from "element-plus/es/locale/index.mjs";
  30. const props = defineProps<{ data: LineData }>();
  31. const emit = defineEmits<{
  32. (e: "updateShape", value: LineData): void;
  33. (e: "addShape", value: LineData): void;
  34. (e: "delShape"): void;
  35. }>();
  36. const { shape, tData, data, operateMenus, describes } = useComponentStatus({
  37. emit,
  38. props,
  39. getMouseStyle,
  40. transformType: "line",
  41. alignment(data, mat) {
  42. return matResponse({ mat, data, increment: true });
  43. },
  44. // type: "line",
  45. defaultStyle,
  46. copyHandler(mat, data) {
  47. return matResponse({ mat, data, increment: true });
  48. },
  49. propertys: [
  50. "stroke",
  51. "strokeWidth",
  52. "dash",
  53. "opacity",
  54. // "ref", "zIndex"
  55. ],
  56. });
  57. const updatePosition = ({ ndx, val }: { ndx: number; val: Pos }) => {
  58. Object.assign(data.value.points[ndx], val);
  59. shape.value?.getNode().fire("bound-change");
  60. };
  61. const deletePoint = (ndx: number) => {
  62. data.value.points.splice(ndx, 1);
  63. shape.value?.getNode().fire("bound-change");
  64. };
  65. const addPoint = ({ ndx, val }: { ndx: number; val: Pos }) => {
  66. console.log(ndx, val);
  67. data.value.points.splice(ndx + 1, 0, val);
  68. shape.value?.getNode().fire("bound-change");
  69. };
  70. const draw = useInteractiveDrawShapeAPI();
  71. const store = useStore();
  72. operateMenus.push({
  73. label: "钢笔编辑",
  74. icon: EditPen,
  75. handler() {
  76. draw.enterDrawShape("line", {
  77. ...props.data,
  78. getMessages: () => {
  79. const line = store.getItemById(props.data.id) as LineData;
  80. return line ? line.points : [];
  81. },
  82. });
  83. },
  84. });
  85. </script>