serial.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <TempComponent
  3. :data="tData"
  4. :ref="(v: any) => shape = v?.shape"
  5. :id="data.id"
  6. @update-content="updateContent"
  7. />
  8. <PropertyUpdate
  9. :describes="describes"
  10. :data="data"
  11. :target="shape"
  12. @change="emit('updateShape', { ...data })"
  13. />
  14. <Operate :target="shape" :menus="operateMenus" />
  15. </template>
  16. <script lang="ts" setup>
  17. import { SerialData, getMouseStyle, defaultStyle, matResponse } from "./index.ts";
  18. import { PropertyUpdate, Operate } from "../../html-mount/propertys/index.ts";
  19. import { TempComponent } from "./";
  20. import { useComponentStatus } from "@/core/hook/use-component.ts";
  21. import { Transform } from "konva/lib/Util";
  22. import { cloneRepShape, useCustomTransformer } from "@/core/hook/use-transformer.ts";
  23. import { Ellipse } from "konva/lib/shapes/Ellipse";
  24. import { Pos } from "@/utils/math.ts";
  25. const props = defineProps<{ data: SerialData }>();
  26. const emit = defineEmits<{
  27. (e: "updateShape", value: SerialData): void;
  28. (e: "addShape", value: SerialData): void;
  29. (e: "delShape"): void;
  30. }>();
  31. const updateContent = (val: string) => {
  32. data.value.content = val;
  33. emit("updateShape", { ...data.value });
  34. };
  35. const { shape, tData, data, operateMenus, describes } = useComponentStatus<
  36. Ellipse,
  37. SerialData
  38. >({
  39. emit,
  40. props,
  41. getMouseStyle,
  42. defaultStyle,
  43. alignment: (data, mat) => {
  44. return matResponse({ mat: mat.multiply(new Transform(data.mat)), data });
  45. },
  46. transformType: "custom",
  47. customTransform(callback, shape, data) {
  48. let initRadius: Pos;
  49. useCustomTransformer(shape, data, {
  50. openSnap: true,
  51. getRepShape($shape) {
  52. const repShape = cloneRepShape($shape).shape;
  53. initRadius = { x: repShape.radiusX(), y: repShape.radiusY() };
  54. return {
  55. shape: repShape,
  56. };
  57. },
  58. // beforeHandler(data, mat) {
  59. // return matToData(copy(data), mat);
  60. // },
  61. handler(data, mat) {
  62. matResponse({ data, mat }, initRadius);
  63. return true;
  64. },
  65. callback,
  66. transformerConfig: {
  67. rotateEnabled: false,
  68. enabledAnchors: ["top-left", "top-right", "bottom-left", "bottom-right"],
  69. },
  70. });
  71. },
  72. copyHandler(mat, data) {
  73. return matResponse({ data, mat: mat.multiply(new Transform(data.mat)) });
  74. },
  75. propertys: [
  76. "fill",
  77. "stroke",
  78. "fontColor",
  79. "strokeWidth",
  80. // "fontSize",
  81. // "ref",
  82. "opacity",
  83. "dash",
  84. // "zIndex"
  85. "fontStyle",
  86. // "ref", "zIndex"
  87. ],
  88. });
  89. </script>