serial.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. @delete="emit('delShape')"
  14. />
  15. <Operate :target="shape" :menus="operateMenus" />
  16. </template>
  17. <script lang="ts" setup>
  18. import {
  19. SerialData,
  20. getMouseStyle,
  21. defaultStyle,
  22. matResponse,
  23. fixedStrokeOptions,
  24. } from "./index.ts";
  25. import { PropertyUpdate, Operate } from "../../html-mount/propertys/index.ts";
  26. import { TempComponent } from "./";
  27. import { useComponentStatus } from "@/core/hook/use-component.ts";
  28. import { Transform } from "konva/lib/Util";
  29. import { cloneRepShape, useCustomTransformer } from "@/core/hook/use-transformer.ts";
  30. import { Ellipse } from "konva/lib/shapes/Ellipse";
  31. import { Pos } from "@/utils/math.ts";
  32. import { useInstallStrokeWidthDescribe } from "@/core/hook/use-describe.ts";
  33. const props = defineProps<{ data: SerialData }>();
  34. const emit = defineEmits<{
  35. (e: "updateShape", value: SerialData): void;
  36. (e: "addShape", value: SerialData): void;
  37. (e: "delShape"): void;
  38. }>();
  39. const updateContent = (val: string) => {
  40. data.value.content = val;
  41. emit("updateShape", { ...data.value });
  42. };
  43. const { shape, tData, data, operateMenus, describes } = useComponentStatus<
  44. Ellipse,
  45. SerialData
  46. >({
  47. emit,
  48. props,
  49. getMouseStyle,
  50. defaultStyle,
  51. // alignment: (data, mat) => {
  52. // return matResponse({ mat: mat.multiply(new Transform(data.mat)), data });
  53. // },
  54. transformType: "custom",
  55. customTransform(callback, shape, data) {
  56. let initRadius: Pos;
  57. useCustomTransformer(shape, data, {
  58. openSnap: true,
  59. getRepShape($shape) {
  60. const repShape = cloneRepShape($shape).shape;
  61. initRadius = { x: repShape.radiusX(), y: repShape.radiusY() };
  62. return {
  63. shape: repShape,
  64. };
  65. },
  66. // beforeHandler(data, mat) {
  67. // return matToData(copy(data), mat);
  68. // },
  69. handler(data, mat) {
  70. matResponse({ data, mat }, initRadius);
  71. return true;
  72. },
  73. callback,
  74. transformerConfig: {
  75. rotateEnabled: false,
  76. enabledAnchors: ["top-left", "top-right", "bottom-left", "bottom-right"],
  77. },
  78. });
  79. },
  80. copyHandler(mat, data) {
  81. return matResponse({ data, mat: mat.multiply(new Transform(data.mat)) });
  82. },
  83. propertys: [
  84. "fill",
  85. "stroke",
  86. "fontColor",
  87. "strokeWidth",
  88. // "fontSize",
  89. // "ref",
  90. // "opacity",
  91. // "dash",
  92. // "zIndex"
  93. "fontStyle",
  94. // "ref", "zIndex"
  95. ],
  96. });
  97. describes.value.content = {
  98. type: "inputNum",
  99. label: "数值",
  100. "layout-type": "row",
  101. get value() {
  102. return Number(data.value.content || 1);
  103. },
  104. onChange() {
  105. emit("updateShape", { ...data.value });
  106. },
  107. set value(val) {
  108. data.value.content = val.toString();
  109. },
  110. };
  111. useInstallStrokeWidthDescribe(describes, data, fixedStrokeOptions, undefined, true);
  112. </script>