소스 검색

feat: Merge branch 'master' into merge-selection

bill 2 달 전
부모
커밋
cb9915c05c

+ 1 - 0
src/core/components/circle/index.ts

@@ -80,6 +80,7 @@ export const interactiveToData: InteractiveTo<'circle'> = ({
   if (info.cur) {
     const item = {
       ...defaultStyle,
+      fill: null,
       ...getBaseItem(),
       ...preset,
     } as unknown as CircleData;

+ 3 - 2
src/core/components/polygon/index.ts

@@ -47,7 +47,7 @@ export const getSnapPoints = (data: PolygonData) => {
 
 export type PolygonData = Partial<typeof defaultStyle> &
   BaseItem & {
-    fill?: string;
+    fill?: string | null;
     points: Pos[];
     attitude: number[];
   };
@@ -63,8 +63,9 @@ export const interactiveToData: InteractiveTo<"polygon"> = ({
       info,
       data: {
         ...getBaseItem(),
-        ...preset,
         ...defaultStyle,
+        fill: null,
+        ...preset,
         points: [],
         attitude: [1, 0, 0, 1, 0, 0],
       },

+ 1 - 0
src/core/components/rectangle/index.ts

@@ -72,6 +72,7 @@ export const interactiveToData: InteractiveTo<"rectangle"> = ({
     const item = {
       ...getBaseItem(),
       ...defaultStyle,
+      fill: null,
       ...preset,
       id: onlyId(),
       createTime: Date.now(),

+ 2 - 1
src/core/components/triangle/index.ts

@@ -60,8 +60,9 @@ export const interactiveToData: InteractiveTo<"triangle"> = ({
   if (info.cur) {
     const item = {
       ...getBaseItem(),
-      ...preset,
       ...defaultStyle,
+      fill: null,
+      ...preset,
       points: [],
     } as unknown as TriangleData;
     return interactiveFixData({ ...args, info, data: item });

+ 6 - 6
src/core/hook/use-dxf.ts

@@ -300,18 +300,18 @@ export const useGetDXF = () => {
             if (isStart) {
               const start = vector
                 .clone()
-                .multiplyScalar(item.pointerLength!)
+                .multiplyScalar(item.pointerLength! * 2)
                 .add(line[0]);
               nline[0] = start;
               const l1 = verticalVectorLine(
                 vector,
                 start,
-                item.pointerLength! / 2
+                item.pointerLength! 
               );
               const l2 = verticalVectorLine(
                 vector,
                 start,
-                -item.pointerLength! / 2
+                -item.pointerLength! 
               );
               writerPolyline({
                 points: [line[0], l1[1], l2[1]],
@@ -322,18 +322,18 @@ export const useGetDXF = () => {
             if (isEnd) {
               const start = vector
                 .clone()
-                .multiplyScalar(-item.pointerLength!)
+                .multiplyScalar(-item.pointerLength! * 2)
                 .add(line[1]);
               nline[1] = start;
               const l1 = verticalVectorLine(
                 vector,
                 start,
-                item.pointerLength! / 2
+                item.pointerLength! 
               );
               const l2 = verticalVectorLine(
                 vector,
                 start,
-                -item.pointerLength! / 2
+                -item.pointerLength! 
               );
               writerPolyline({
                 points: [line[1], l1[1], l2[1]],

+ 7 - 3
src/core/hook/use-expose.ts

@@ -30,7 +30,7 @@ import { mergeFuns } from "@/utils/shared.ts";
 import { getImage, isSvgString } from "@/utils/resource.ts";
 import { useResourceHandler } from "./use-fetch.ts";
 import { useConfig } from "./use-config.ts";
-import { useSelectionRevise } from "./use-selection.ts";
+import { useExcludeSelection, useSelectionRevise } from "./use-selection.ts";
 import { useFormalLayer, useGetFormalChildren } from "./use-layer.ts";
 import { components } from "../components/index.ts";
 import { useProportion } from "./use-proportion.ts";
@@ -92,6 +92,7 @@ export const useShortcutKey = () => {
   // 自动退出添加模式
   const { quitDrawShape, enterDrawShape } = useInteractiveDrawShapeAPI();
   const interactiveProps = useInteractiveProps();
+  
   const store = useStore();
   useListener(
     "contextmenu",
@@ -115,7 +116,8 @@ export const useShortcutKey = () => {
   const status = useMouseShapesStatus();
   const getChildren = useGetFormalChildren();
   const operMode = useOperMode();
-  const getShapeBelong = useGetShapeBelong();
+  const eSelection = useExcludeSelection()
+  const getShapeBelong = useGetShapeBelong()
   useListener(
     "keydown",
     (ev) => {
@@ -163,7 +165,8 @@ export const useShortcutKey = () => {
         if (status.selects.length) {
           status.selects = [];
         } else {
-          status.selects = getChildren();
+          
+          status.selects = getChildren().filter(shape => !eSelection.value.includes(shape.id()));
         }
       }
     },
@@ -292,6 +295,7 @@ export const useExpose = installGlobalVar(() => {
     },
     getViewBoxPositionPixel: useGetViewBoxPositionPixel(),
     viewer,
+    excludeSelection: useExcludeSelection(),
     runHook: useRunHook(),
     presetAdd: interactiveProps,
     config: useConfig(),

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

@@ -25,6 +25,7 @@ import { Group } from "konva/lib/Group";
 import { usePause } from "./use-pause.ts";
 import { lineLen, Pos } from "@/utils/math.ts";
 import { useFormalLayer } from "./use-layer.ts";
+import { useExcludeSelection } from "./use-selection.ts";
 
 const stageHoverMap = new WeakMap<
   Stage,
@@ -235,6 +236,7 @@ export const useMouseShapesStatus = installGlobalVar(() => {
   const selects = ref([]) as Ref<EntityShape[]>;
   const actives = ref([]) as Ref<EntityShape[]>;
   const operMode = useOperMode();
+  const eSelection = useExcludeSelection()
   const pointerIsTransformerInner = usePointerIsTransformerInner();
 
   const init = (stage: Stage) => {
@@ -295,11 +297,12 @@ export const useMouseShapesStatus = installGlobalVar(() => {
             return;
           }
           if (operMode.value.mulSelection) {
-            if (!target) return;
+            if (!target || eSelection.value.includes(target.id())) return;
             actives.value = [];
             const ndx = selects.value.findIndex(
               (item) => item.id() === target?.id()
             );
+            
             if (~ndx) {
               selects.value.splice(ndx, 1);
             } else {

+ 3 - 0
src/core/hook/use-selection.ts

@@ -49,9 +49,11 @@ import mitt, { Emitter } from "mitt";
 import { components, ShapeType, shapeTypes } from "../components";
 import { getFlatChildren } from "@/utils/shape";
 
+export const useExcludeSelection = installGlobalVar(() => ref<string[]>([]))
 // 多选不包含分组, 只包含选中者
 export const useSelection = installGlobalVar(() => {
   const layer = useHelperLayer();
+  const eSelection = useExcludeSelection()
   const getChildren = useGetFormalChildren();
   const box = new Rect({
     stroke: themeColor,
@@ -119,6 +121,7 @@ export const useSelection = installGlobalVar(() => {
     itemShapes = getChildren().map((item) =>
       getFlatChildren(item).filter(
         (shape) =>
+          !eSelection.value.includes(shape.id()) &&
           shape !== toRaw(transformer) &&
           getShapeSelectionManage(shape)?.canSelect(shape)
       )

+ 13 - 8
src/example/fuse/views/overview/header.vue

@@ -81,12 +81,14 @@ const setViewToTableCover = async () => {
   const oldBack = draw.config.back;
   const oldShowCompass = draw.config.showCompass;
   const oldLabelLineConfig = { ...draw.config.labelLineConfig };
+  const oldShowOffset = draw.config.labelLineConfig.showOffset;
   const getRect = () => draw.stage!.findOne<Group>(`#${DataGroupId}`)!.getClientRect();
 
   const pop = draw.mode.push(Mode.readonly);
   const rect = getRect();
   const rectScale = (rect.width || 1080) / (rect.height || 850);
   const tableCoverScale = tableCoverWidth / tableCoverHeight;
+  const padding = 70;
 
   let width: number, height: number;
   if (rectScale > tableCoverScale) {
@@ -96,6 +98,12 @@ const setViewToTableCover = async () => {
     height = 850;
     width = rectScale * height;
   }
+  if (width < padding * 2) {
+    width += padding * 2;
+  }
+  if (height < padding * 2) {
+    height += padding * 2;
+  }
 
   draw.config.size = { width, height };
   draw.config.showGrid = false;
@@ -104,20 +112,17 @@ const setViewToTableCover = async () => {
 
   draw.config.labelLineConfig.type = "auto";
   draw.config.labelLineConfig.strokeWidth = 2;
-  draw.config.labelLineConfig.fontSize = 16;
+  draw.config.labelLineConfig.fontSize = 10;
 
   await nextTick();
-  const padding = 20;
+  draw.config.labelLineConfig.showOffset = padding;
   draw.initViewport(padding);
   await nextTick();
 
-  const currentRect = getRect();
   return [
     {
-      x: currentRect.x - padding,
-      y: currentRect.y - padding,
-      width: currentRect.width + 2 * padding,
-      height: currentRect.height + 2 * padding,
+      width,
+      height,
     },
     () => {
       pop();
@@ -126,6 +131,7 @@ const setViewToTableCover = async () => {
       draw.config.back = oldBack;
       draw.config.showCompass = oldShowCompass;
       draw.config.labelLineConfig = oldLabelLineConfig;
+      draw.config.labelLineConfig.showOffset = oldShowOffset;
       draw.viewer.setViewMat(oldViewMat);
     },
   ] as const;
@@ -163,7 +169,6 @@ const saveHandler = repeatedlyOnly(async () => {
     proportion: { ...draw.store.config.proportion, scale },
   };
 
-  console.log({ ...storeData.config.compass });
   tabulationId.value = await window.platform.getTabulationId(overviewId.value);
   await refreshTabulationData();
   const tabStore = await repTabulationStore(

+ 2 - 0
src/example/fuse/views/tabulation/gen-tab.ts

@@ -262,7 +262,9 @@ export const repTabulationStore = async (paperKey: PaperKey, compass?: number, c
     const imageData = repData.image[0]
     const images = layer.image || []
     const imageNdx = images.findIndex(item => item.key === imageData.key)
+    
     if (~imageNdx) {
+      images[imageNdx] = imageData
       images[imageNdx] = {
         ...imageData,
         mat: images[imageNdx].mat

+ 10 - 11
src/example/fuse/views/tabulation/index.vue

@@ -49,7 +49,6 @@ import { StoreData } from "@/core/store/store";
 import { getImageSize } from "@/utils/shape";
 import { tabCustomStyle } from "../defStyle";
 import { defaultLayer } from "@/constant";
-import { useViewBoxPixelRect } from "@/core/hook/use-viewer";
 
 const uploadResourse = window.platform.uploadResourse;
 const full = ref(false);
@@ -105,16 +104,6 @@ const init = async (draw: Draw) => {
     },
   });
   inited.value = true;
-
-  draw.runHook(() => {
-    const size = useViewBoxPixelRect();
-    quitMerges.push(
-      watchEffect(() => {
-        console.log("当前视口:", size.value);
-      })
-    );
-  });
-
   quitMerges.push(tabCustomStyle(p, draw));
   return () => mergeFuns(quitMerges)();
 };
@@ -150,6 +139,11 @@ watch(draw, (draw, _, onCleanup) => {
 const cover = computed(
   () => draw.value?.store.items.find((item) => item.key === tableCoverKey) as ImageData
 );
+watchEffect(() => {
+  if (cover.value && draw.value) {
+    draw.value.excludeSelection.push(cover.value.id);
+  }
+});
 const coverScale = computed({
   get: () =>
     cover.value &&
@@ -164,6 +158,11 @@ watch(cover, (cover, _, onCleanup) => {
   const mountMenus = draw.value.mountFilter;
   const menusFilter = draw.value.menusFilter;
   const quits = [
+    watchEffect(() => {
+      console.log("当前图片宽高:", cover.width, cover.height);
+      console.log("当前图片真实宽高:", cover.widthRaw, cover.heightRaw);
+      console.log("当前图片比例:", { ...cover.proportion });
+    }),
     menusFilter.setShapeMenusFilter(cover.id, () => []),
     mountMenus.setShapeMenusFilter(cover.id, (des) => ({
       ...des,