line.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. canEdit
  9. />
  10. <PropertyUpdate
  11. :describes="describes"
  12. :data="data"
  13. :target="shape"
  14. @change="emit('updateShape', { ...data })"
  15. />
  16. <Operate :target="shape" :menus="operateMenus" />
  17. </template>
  18. <script lang="ts" setup>
  19. import { LineData, getMouseStyle, defaultStyle, matResponse } from "./index.ts";
  20. import { useComponentStatus } from "@/core/hook/use-component.ts";
  21. import { PropertyUpdate, Operate } from "../../propertys";
  22. import TempLine from "./temp-line.vue";
  23. import { EditPen } from "@element-plus/icons-vue";
  24. import { useInteractiveDrawShapeAPI } from "@/core/hook/use-draw.ts";
  25. import { useStore } from "@/core/store/index.ts";
  26. import { Pos } from "@/utils/math.ts";
  27. const props = defineProps<{ data: LineData }>();
  28. const emit = defineEmits<{
  29. (e: "updateShape", value: LineData): void;
  30. (e: "addShape", value: LineData): void;
  31. (e: "delShape"): void;
  32. }>();
  33. const { shape, tData, data, operateMenus, describes } = useComponentStatus({
  34. emit,
  35. props,
  36. getMouseStyle,
  37. transformType: "line",
  38. alignment(data, mat) {
  39. return matResponse({ mat, data, increment: true });
  40. },
  41. // type: "line",
  42. defaultStyle,
  43. copyHandler(mat, data) {
  44. return matResponse({ mat, data, increment: true });
  45. },
  46. propertys: [
  47. "stroke",
  48. "strokeWidth",
  49. "dash",
  50. "opacity",
  51. // "ref", "zIndex"
  52. ],
  53. });
  54. const updatePosition = ({ ndx, val }: { ndx: number; val: Pos }) => {
  55. Object.assign(data.value.points[ndx], val);
  56. shape.value?.getNode().fire("bound-change");
  57. };
  58. const draw = useInteractiveDrawShapeAPI();
  59. const store = useStore();
  60. operateMenus.push({
  61. label: "钢笔编辑",
  62. icon: EditPen,
  63. handler() {
  64. draw.enterDrawShape("line", {
  65. ...props.data,
  66. getMessages: () => {
  67. const line = store.getItemById(props.data.id) as LineData;
  68. return line ? line.points : [];
  69. },
  70. });
  71. },
  72. });
  73. </script>