bill 2 miesięcy temu
rodzic
commit
6501d832cb

+ 0 - 2
src/core/components/circle/temp-circle.vue

@@ -52,14 +52,12 @@ import { DC } from "@/deconstruction.js";
 import { Circle } from "konva/lib/shapes/Circle";
 import { Transform } from "konva/lib/Util";
 import { useConfig } from "@/core/hook/use-config.ts";
-import { zeroEq } from "@/utils/math.ts";
 
 const props = defineProps<{ data: CircleData; addMode?: boolean; editer?: boolean }>();
 const emit = defineEmits<{
   (e: "updateContent", data: string): void;
   (e: "update:isEdit", data: boolean): void;
 }>();
-console.log(props.data.radiusX, props.data.radiusY);
 
 const config = useConfig();
 const data = computed(() => ({ ...defaultStyle, ...props.data }));

+ 20 - 6
src/core/components/share/edit-line.vue

@@ -19,15 +19,20 @@
 </template>
 
 <script lang="ts" setup>
-import { copy, flatPositions } from "@/utils/shared";
-import { computed, ref, watch } from "vue";
+import { copy, flatPositions, mergeFuns } from "@/utils/shared";
+import { computed, onUnmounted, ref, watch } from "vue";
 import { DC } from "@/deconstruction";
 import { Line } from "konva/lib/shapes/Line";
 import { useShapeDrag } from "@/core/hook/use-transformer";
 import { useShapeIsHover, useShapeClick } from "@/core/hook/use-mouse-status";
 import { useCursor } from "@/core/hook/use-global-vars";
 import { lineCenter, Pos } from "@/utils/math";
-import { useCustomSnapInfos, useGlobalSnapInfos, useSnap } from "@/core/hook/use-snap";
+import {
+  useCustomSnapInfos,
+  useGlobalSnapInfos,
+  useSnap,
+  useSnapResultInfo,
+} from "@/core/hook/use-snap";
 import { ComponentSnapInfo } from "..";
 import { generateSnapInfos } from "../util";
 import { getMouseColors } from "@/utils/colors";
@@ -102,12 +107,20 @@ const refSnapInfos = computed(() => {
 const snap = useSnap(refSnapInfos);
 
 let init: Pos[];
+let onUmHooks: (() => void)[] = [];
+const resultInfo = useSnapResultInfo();
 watch(offset, (offset, oldOffsert) => {
   snap.clear();
   if (!oldOffsert) {
     emit("dragstart");
     init = copy(points.value);
     dragStartHandler();
+    onUmHooks.push(() => {
+      clearInfos();
+      emit("dragend");
+      viewer.disabled.value = false;
+      resultInfo.clear();
+    });
   }
   if (offset) {
     const current = init.map((p) => ({
@@ -118,12 +131,13 @@ watch(offset, (offset, oldOffsert) => {
     const transform = snap.move(refSnapInfos);
     emit("update:line", transform ? current.map((p) => transform.point(p)) : current);
   } else {
-    clearInfos();
-    emit("dragend");
-    viewer.disabled.value = false;
+    mergeFuns(onUmHooks)();
+    onUmHooks.length = 0;
   }
 });
 
+onUnmounted(() => mergeFuns(onUmHooks)());
+
 const point = ref<DC<Circle>>();
 const [isPointHover] = useShapeIsHover(point);
 let addCursorPop: () => void;

+ 21 - 12
src/core/components/share/edit-point.vue

@@ -13,19 +13,23 @@
 <script lang="ts" setup>
 import { Pos } from "@/utils/math.ts";
 import { themeColor } from "@/constant";
-import { computed, ref, watch } from "vue";
+import { computed, onUnmounted, ref, watch } from "vue";
 import { DC } from "@/deconstruction";
 import { Circle } from "konva/lib/shapes/Circle";
 import { useShapeDrag } from "@/core/hook/use-transformer.ts";
 import { getMouseColors } from "@/utils/colors";
-import { useCustomSnapInfos, useGlobalSnapInfos, useSnap } from "@/core/hook/use-snap";
+import {
+  useCustomSnapInfos,
+  useGlobalSnapInfos,
+  useSnap,
+  useSnapResultInfo,
+} from "@/core/hook/use-snap";
 import { generateSnapInfos } from "../util";
 import { ComponentSnapInfo } from "..";
 import { useShapeIsHover } from "@/core/hook/use-mouse-status";
 import { useCursor } from "@/core/hook/use-global-vars";
-import { rangMod } from "@/utils/shared";
+import { mergeFuns, rangMod } from "@/utils/shared";
 import { Operate } from "../../html-mount/propertys/index.ts";
-import { collapseItemProps } from "element-plus";
 import { useViewer } from "@/core/hook/use-viewer.ts";
 
 const props = defineProps<{
@@ -116,14 +120,21 @@ watch(
 );
 const dragIng = ref(false);
 let init: Pos;
+let onUmHooks: (() => void)[] = [];
+const resultInfo = useSnapResultInfo();
 watch(offset, (offset, oldOffsert) => {
   snap.clear();
   if (!oldOffsert) {
     init = { ...position.value };
     startHandler();
-    emit("dragstart");
-    cursor.push("./icons/m_move.png");
     dragIng.value = true;
+    onUmHooks.push(() => {
+      emit("dragend");
+      clearInfos();
+      dragIng.value = false;
+      viewer.disabled.value = false;
+      resultInfo.clear();
+    });
   }
   if (offset) {
     const point = {
@@ -133,18 +144,16 @@ watch(offset, (offset, oldOffsert) => {
     const refSnapInfos = props.getSelfSnapInfos
       ? props.getSelfSnapInfos(point)
       : generateSnapInfos([point], true, true);
-    // console.log(refSnapInfos);
     const transform = snap.move(refSnapInfos);
     emit("update:position", transform ? transform.point(point) : point);
   } else {
-    emit("dragend");
-    cursor.pop();
-    clearInfos();
-    dragIng.value = false;
-    viewer.disabled.value = false;
+    mergeFuns(onUmHooks)();
+    onUmHooks.length = 0;
   }
 });
 
+onUnmounted(() => mergeFuns(onUmHooks)());
+
 watch(
   () => props.disable,
   (disable) => {

+ 0 - 1
src/core/helper/compass.vue

@@ -82,7 +82,6 @@ const [style] = useAnimationMouseStyle({
 
 let currentRotation = store.config.compass.rotation;
 const describes = mergeDescribes(data, {}, ["rotate"]);
-console.log(describes);
 describes.rotate = {
   ...describes.rotate,
   sort: 3,

+ 11 - 19
src/core/hook/use-dxf.ts

@@ -15,7 +15,7 @@ import Zip from "jszip";
 import { LineData } from "../components/line";
 import { CircleData } from "../components/circle";
 import { Transform } from "konva/lib/Util";
-import { lineVector, Pos, Size, verticalVectorLine } from "@/utils/math";
+import { lineLen, lineVector, Pos, Size, verticalVectorLine, zeroEq } from "@/utils/math";
 import { RectangleData } from "../components/rectangle";
 import { useStage } from "./use-global-vars";
 import { Group } from "konva/lib/Group";
@@ -98,7 +98,6 @@ export const useGetDXF = () => {
       const width = $text.width();
       const charWidth = fontSize * 0.9;
 
-      console.log(text);
       const lineCharCount = sp
         ? Math.max(Math.floor(width / charWidth), 2)
         : Number.MAX_VALUE;
@@ -141,15 +140,6 @@ export const useGetDXF = () => {
           p.x = width - lineWidth;
         }
         const start = mat.point(p);
-        console.log(point3d(start.x, -start.y), fontSize, item.content, {
-          rotation: $text.rotation(),
-          // horizontalAlignment:
-          //   align === "center"
-          //     ? TextHorizontalAlignment.Center
-          //     : align === "right"
-          //     ? TextHorizontalAlignment.Right
-          //     : TextHorizontalAlignment.Left,
-        });
         const text = writer.addText(
           point3d(start.x, -start.y),
           fontSize,
@@ -280,14 +270,16 @@ export const useGetDXF = () => {
 
         case "arrow":
           item = _item as ArrowData;
-          // writer.addLWPolyline(
-          //   item.points.map((p) => ({ point: point2d(p.x, -p.y) })),
-          //   {
-          //     flags: LWPolylineFlags.None,
-          //     constantWidth: item.strokeWidth,
-          //     trueColor: TrueColor.fromHex(item.fill || "#FFFFFF").toString(),
-          //   }
-          // );
+          if (zeroEq(lineLen(item.points[0], item.points[1]))) {
+            item = {
+              ...item,
+              points: [...item.points]
+            }
+            item.points[0] = {
+              ...item.points[0],
+              x: item.points[1].x - (item.pointerLength || 1)
+            }
+          }
           const isEnd = [PointerPosition.end, PointerPosition.all].includes(
             item.pointerPosition || PointerPosition.start
           );

+ 1 - 1
src/core/hook/use-mouse-status.ts

@@ -446,7 +446,7 @@ export const useActiveItem = <T extends EntityShape>() => {
 
 type MouseStyleProps<T extends ShapeType> = {
   shape?: Ref<DC<EntityShape> | undefined>;
-  getMouseStyle: ComponentValue<T, "getMouseStyle">;
+  getMouseStyle: (data: any) => Record<string, any>;
   data: Ref<DrawItem<T>>;
 };
 export const useMouseStyle = <T extends ShapeType>(

+ 15 - 30
src/core/hook/use-transformer.ts

@@ -16,7 +16,6 @@ import { getOffset, listener } from "@/utils/event.ts";
 import {
   debounce,
   flatPositions,
-  frameEebounce,
   mergeFuns,
   round,
 } from "@/utils/shared.ts";
@@ -266,8 +265,6 @@ export const useShapeDrag = (shape: Ref<DC<EntityShape> | undefined>) => {
       }
     };
     const leave = () => {
-      stopMove && stopMove()
-      stopMove = null
       if (start) {
         offset.value = void 0;
         mode.pop();
@@ -277,40 +274,28 @@ export const useShapeDrag = (shape: Ref<DC<EntityShape> | undefined>) => {
       }
     };
 
-    // shape.draggable(true);
-    // shape.dragBoundFunc((_, ev) => {
-    //   if (!start) {
-    //     // enter(conversion(getOffset(ev, dom)));
-    //     return shape.absolutePosition();
-    //   } else if (can.dragMode) {
-    //     const end = conversion(getOffset(ev, dom));
-    //     offset.value = {
-    //       x: end.x - start.x,
-    //       y: end.y - start.y,
-    //     };
-    //   }
-    //   return shape.absolutePosition();
-    // });
-
-    let stopMove: (() => void) | null = null
+    shape.draggable(true);
+    shape.dragBoundFunc((_, ev) => {
+      if (!start) {
+        return shape.absolutePosition();
+      } else if (can.dragMode) {
+        const end = conversion(getOffset(ev, dom));
+        offset.value = {
+          x: end.x - start.x,
+          y: end.y - start.y,
+        };
+      }
+      return shape.absolutePosition();
+    });
+
     shape.on("pointerdown.mouse-drag", (ev) => {
       if (ev.evt.button !== 0) return;
       enter(conversion(getOffset(ev.evt)));
-      stopMove = listener(document.documentElement, "pointermove", (ev) => {
-        if (start && can.dragMode) {
-          const end = conversion(getOffset(ev, dom));
-
-          offset.value = {
-            x: end.x - start.x,
-            y: end.y - start.y,
-          };
-        }
-      })
     });
 
     return mergeFuns([
       () => {
-        // shape.draggable(false);
+        shape.draggable(false);
         shape.off("pointerdown.mouse-drag");
         start && leave();
       },

+ 1 - 1
src/core/html-mount/propertys/components/text.vue

@@ -3,7 +3,7 @@
     :modelValue="value"
     style="width: 140px"
     @update:model-value="(value: string) => $emit('update:value', value)"
-    placeholder="Please input"
+    placeholder="请输入"
     @change="$emit('change')"
   />
 </template>

+ 51 - 51
src/core/renderer/renderer.vue

@@ -1,63 +1,63 @@
 <template>
-  <div
-    class="draw-layout"
-    @contextmenu.prevent
-    :style="{ cursor: cursorStyle }"
-    ref="layout"
-    :class="{ temp: tempStatus }"
-  >
-    <div class="mount-mask" :id="DomOutMountId" />
     <div
-      class="draw-content"
-      :style="fix && { width: size?.width + 'px', height: size?.height + 'px' }"
+      class="draw-layout"
+      @contextmenu.prevent
+      :style="{ cursor: cursorStyle }"
+      ref="layout"
+      :class="{ temp: tempStatus }"
     >
-      <div class="mount-mask" :id="DomMountId"></div>
+      <div class="mount-mask" :id="DomOutMountId" />
+      <div
+        class="draw-content"
+        :style="fix && { width: size?.width + 'px', height: size?.height + 'px' }"
+      >
+        <div class="mount-mask" :id="DomMountId"></div>
 
-      <v-stage ref="stage" :config="size" v-if="layout">
-        <v-layer :config="viewerConfig" id="formal">
-          <v-group>
+        <v-stage ref="stage" :config="size" v-if="layout">
+          <v-layer :config="viewerConfig" id="formal">
             <v-group>
-              <Back />
+              <v-group>
+                <Back />
+              </v-group>
+              <v-group>
+                <BackGrid v-if="expose.config.showGrid" />
+              </v-group>
+            </v-group>
+            <v-group :id="DataGroupId">
+              <component
+                :is="GroupComponentMap[type]"
+                v-for="type in types"
+                :type="type"
+                :key="type"
+              />
             </v-group>
             <v-group>
-              <BackGrid v-if="expose.config.showGrid" />
+              <component
+                v-for="part in mountParts.value"
+                :is="part.comp"
+                :key="part.props.key"
+                v-bind="part.props"
+              />
             </v-group>
-          </v-group>
-          <v-group :id="DataGroupId">
-            <component
-              :is="GroupComponentMap[type]"
-              v-for="type in types"
-              :type="type"
-              :key="type"
-            />
-          </v-group>
-          <v-group>
-            <component
-              v-for="part in mountParts.value"
-              :is="part.comp"
-              :key="part.props.key"
-              v-bind="part.props"
-            />
-          </v-group>
-        </v-layer>
-        <!--	临时组,提供临时绘画,以及高频率渲染	-->
-        <v-layer :config="viewerConfig" id="temp">
-          <template v-if="mode.include(Mode.draw)">
-            <TempShapeGroup v-for="type in types" :type="type" :key="type" />
-          </template>
-        </v-layer>
-        <v-layer id="helper">
-          <!-- <ActiveBoxs /> -->
-          <SnapLines />
-          <SplitLine v-if="expose.config.showLabelLine" />
-          <Compass v-if="config.showCompass" />
-          <layers v-if="store.layers.length > 1" />
-          <Debugger v-if="isDev" />
-          <Border />
-        </v-layer>
-      </v-stage>
+          </v-layer>
+          <!--	临时组,提供临时绘画,以及高频率渲染	-->
+          <v-layer :config="viewerConfig" id="temp">
+            <template v-if="mode.include(Mode.draw)">
+              <TempShapeGroup v-for="type in types" :type="type" :key="type" />
+            </template>
+          </v-layer>
+          <v-layer id="helper">
+            <!-- <ActiveBoxs /> -->
+            <SnapLines />
+            <SplitLine v-if="expose.config.showLabelLine" />
+            <Compass v-if="config.showCompass" />
+            <layers v-if="store.layers.length > 1" />
+            <Debugger v-if="isDev" />
+            <Border />
+          </v-layer>
+        </v-stage>
+      </div>
     </div>
-  </div>
 </template>
 
 <script lang="ts" setup>

+ 5 - 4
src/example/components/header/index.vue

@@ -3,10 +3,11 @@
     <div class="nav">
       <slot name="nav" v-if="$slots.nav" />
       <span v-else class="nav-back">
-        <span class="back operate" v-if="!noBack">
-          <Icon name="back" @click="router.back()" />
+        <span class="back operate" v-if="!noBack" @click="$emit('back')">
+          <Icon name="back" />
+          {{ title }}
         </span>
-        <span class="title">{{ title }}</span>
+        <span class="title" v-else>{{ title }}</span>
       </span>
     </div>
     <div class="draw-operate">
@@ -46,7 +47,6 @@
 </template>
 
 <script lang="ts" setup>
-import { router } from "@/example/fuse/router";
 import { ActionGroups } from "./actions";
 import { ElDropdown, ElDropdownItem, ElDropdownMenu } from "element-plus";
 import { Draw } from "../container/use-draw";
@@ -57,6 +57,7 @@ defineProps<{
   title?: string;
   noBack?: boolean;
 }>();
+defineEmits<{ (e: "back"): void }>();
 </script>
 
 <style lang="scss" scoped>

+ 0 - 3
src/example/components/slide/actions.ts

@@ -11,7 +11,6 @@ import { MenuItem } from "./menu";
 import { copy } from "@/utils/shared";
 import { ElMessage } from "element-plus";
 import { getRealPixel } from "@/example/fuse/views/tabulation/gen-tab";
-import { Mode } from "@/constant/mode";
 import { nextTick } from "vue";
 import { Rect } from "konva/lib/shapes/Rect";
 
@@ -108,9 +107,7 @@ export const getPaperConfig = (p: number[], scale: number) => {
   const pad = 5 * scale;
   const size = { width: p[0] * scale, height: p[1] * scale };
   const margin = [pad, pad, pad, pad * 5];
-  console.log(margin);
   const a = getRealPixel(5, "a4");
-  console.log([a, getRealPixel(25, "a4")]);
   return { size, margin };
 };
 export const paperConfigs = {

+ 7 - 1
src/example/fuse/views/tabulation/header.vue

@@ -1,5 +1,10 @@
 <template>
-  <Header :action-groups="actions" title="图纸" :draw="draw">
+  <Header
+    :action-groups="actions"
+    title="图纸"
+    :draw="draw"
+    @back="router.replace({ name: 'overview', query: router.currentRoute.value.query })"
+  >
     <template #saves>
       <el-button type="primary" @click="saveHandler" :disabled="draw.drawing">
         保存
@@ -24,6 +29,7 @@ import { tabulationData } from "../../store.ts";
 import { Mode } from "@/constant/mode.ts";
 import { tabulationId } from "@/example/env.ts";
 import { listener } from "@/utils/event.ts";
+import { router } from "../../router.ts";
 
 const draw = useDraw();
 

+ 0 - 1
src/example/loadding.ts

@@ -12,7 +12,6 @@ const loadingStack = ref<Array<Options | undefined>>([])
 const tokens: string[] = []
 let instance: ReturnType<typeof ElLoading.service> | null = null;
 watchEffect(() => {
-  console.log(loadingStack.value)
   if (!loadingStack.value.length && instance) {
     instance.close()
     instance = null