Browse Source

fix: 依赖关系冲突修复

bill 15 hours ago
parent
commit
b8c1dff6e0

+ 1 - 0
package.json

@@ -4,6 +4,7 @@
   "version": "1.3.0",
   "type": "module",
   "scripts": {
+    "preview": "vite preview",
     "translate": "node ./scripts/fetch-langs.mjs",
     "dev:exe": "vite --mode=exedev",
     "build:exe": "yarn translate & vite build --mode=exe",

+ 25 - 1
src/core/components/line-chunk/attrib.ts

@@ -1,2 +1,26 @@
+import { getMouseColors } from "@/utils/colors";
+import { LineData } from ".";
+import { installGlobalStyle } from "@/core/hook/use-global-style";
 
-export const fixedStrokeOptions:number[] = [];
+export const fixedStrokeOptions:number[] = [];
+
+export const defaultStyle = installGlobalStyle('lineChunk', {
+  strokeWidth: 3,
+  stroke: "#000000",
+  fixed: true,
+  dash: [30, 0],
+});
+
+export const getMouseStyle = (data: LineData) => {
+  const strokeStatus = getMouseColors(data.stroke || defaultStyle.stroke);
+  const strokeWidth = data.strokeWidth || defaultStyle.strokeWidth;
+
+  console.log(strokeStatus.hover)
+  return {
+    default: { stroke: data.stroke || defaultStyle.stroke, strokeWidth },
+    hover: { stroke: strokeStatus.hover },
+    select: { stroke: strokeStatus.select },
+    focus: { stroke: strokeStatus.hover },
+    press: { stroke: strokeStatus.press },
+  };
+};

+ 20 - 32
src/core/components/line-chunk/index.ts

@@ -2,42 +2,28 @@ import { inRevise, onlyId } from "@/utils/shared";
 import type { InteractiveFix, InteractiveTo } from "..";
 import { LineData, generateUseDraw } from "../line";
 import { getBaseItem } from "../util";
-import { getMouseColors } from "@/utils/colors";
-import { SelectionManageBus, UseGetSelectionManage } from "@/core/hook/use-selection";
+import {
+  SelectionManageBus,
+  UseGetSelectionManage,
+} from "@/core/hook/use-selection";
 import { useStore } from "@/core/store";
 import { EntityShape } from "@/deconstruction";
 import { Group } from "konva/lib/Group";
 import mitt from "mitt";
 import { watch } from "vue";
 import { ui18n } from "@/lang";
-import { installGlobalStyle } from "@/core/hook/use-global-style";
+import { defaultStyle } from './attrib'
 
-export const shapeName = ui18n.t('shape.line.name');
-export const defaultStyle = installGlobalStyle('lineChunk', {
-  strokeWidth: 3,
-  stroke: "#000000",
-  fixed: true,
-  dash: [30, 0],
-});
+export const shapeName = ui18n.t("shape.line.name");
 
 export { fixedStrokeOptions } from "./attrib";
-export const useDraw = generateUseDraw('lineChunk');
+export const useDraw = generateUseDraw("lineChunk");
+export { defaultStyle, getMouseStyle } from "./attrib";
 
-export const getMouseStyle = (data: LineData) => {
-  const strokeStatus = getMouseColors(data.stroke || defaultStyle.stroke);
-  const strokeWidth = data.strokeWidth || defaultStyle.strokeWidth;
-
-  console.log(strokeStatus.hover)
-  return {
-    default: { stroke: data.stroke || defaultStyle.stroke, strokeWidth },
-    hover: { stroke: strokeStatus.hover },
-    select: { stroke: strokeStatus.select },
-    focus: { stroke: strokeStatus.hover },
-    press: { stroke: strokeStatus.press },
-  };
-};
-
-export const interactiveFixData: InteractiveFix<'lineChunk'> = ({ data, info }) => {
+export const interactiveFixData: InteractiveFix<"lineChunk"> = ({
+  data,
+  info,
+}) => {
   const nv = [...info.consumed, info.cur!];
 
   data.points.length = nv.length;
@@ -72,7 +58,7 @@ export const interactiveFixData: InteractiveFix<'lineChunk'> = ({ data, info })
   return data;
 };
 
-export const interactiveToData: InteractiveTo<'lineChunk'> = ({
+export const interactiveToData: InteractiveTo<"lineChunk"> = ({
   info,
   preset = {},
   ...args
@@ -94,14 +80,17 @@ export const interactiveToData: InteractiveTo<'lineChunk'> = ({
   }
 };
 
-
 export const useGetSelectionManage: UseGetSelectionManage = () => {
   const store = useStore();
 
   const canSelect = (shape: EntityShape) => {
     const id = shape.id();
-    const line = store.getTypeItems('lineChunk')[0];
-    return !!(id && line.lines.some((item) => item.id === id) && !(shape instanceof Group));
+    const line = store.getTypeItems("lineChunk")[0];
+    return !!(
+      id &&
+      line.lines.some((item) => item.id === id) &&
+      !(shape instanceof Group)
+    );
   };
   const listener = (shape: EntityShape) => {
     const bus: SelectionManageBus = mitt();
@@ -112,7 +101,7 @@ export const useGetSelectionManage: UseGetSelectionManage = () => {
           bus.emit("del", shape);
         }
       },
-      { immediate: true }
+      { immediate: true },
     );
     return { stop, bus };
   };
@@ -120,6 +109,5 @@ export const useGetSelectionManage: UseGetSelectionManage = () => {
   return { canSelect, listener };
 };
 
-
 export type LineChunkData = LineData;
 export * from "../line";

+ 2 - 2
src/core/components/line/line.vue

@@ -1,11 +1,11 @@
 <template>
-  <TempLine :data="data" @updateShape="emit('updateShape', data)"  />
+  <TempLine :data="data" @updateShape="emit('updateShape', data)" />
 </template>
 
 <script lang="ts" setup>
 import { watch } from "vue";
 import { foreNormalLineData } from "./attach-server.ts";
-import { LineData } from "./index.ts";
+import type { LineData } from "./index.ts";
 import TempLine from "./temp-line.vue";
 
 const props = defineProps<{ data: LineData }>();

+ 1 - 1
src/core/components/line/single-line.vue

@@ -90,7 +90,7 @@ import EditLine from "../share/edit-line.vue";
 import singlePoint from "./single-point.vue";
 import { computed, ref } from "vue";
 import { getMouseStyle, LineData, LineDataLine, renderer } from "./index.ts";
-import { getMouseStyle as getChunkMouseStyle } from "../line-chunk/index.ts";
+import { getMouseStyle as getChunkMouseStyle } from "../line-chunk/attrib.ts";
 import { onlyId } from "@/utils/shared.ts";
 import { Pos } from "@/utils/math.ts";
 import { Line } from "konva/lib/shapes/Line";

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

@@ -236,11 +236,13 @@ const useInteractiveDrawTemp = <T extends ShapeType>({
   refSelf,
   enter,
   quit,
+  addBefore,
   getSnapGeo,
 }: {
   type: T;
   useIA: InteractiveHook;
   refSelf?: boolean;
+  addBefore?: (item: Area | Pos) => boolean,
   enter?: () => void;
   quit?: () => void;
   getSnapGeo?: (data: DrawItem<T>) => SnapPoint[];
@@ -306,11 +308,9 @@ const useInteractiveDrawTemp = <T extends ShapeType>({
     item = reactive(item);
 
     const storeAddItem = (cItem: any) => {
-      const positions = ia.consumedMessage[ia.consumedMessage.length - 1] as Area
-      if (lineLen(positions[0], positions[1]) < 1) {
+      if (addBefore && !addBefore(ia.consumedMessage[ia.consumedMessage.length - 1])) {
         return;
       }
-      
       console.log(ia.consumedMessage)
       const items = store.getTypeItems(type);
       if (!obj.checkItemData || obj.checkItemData(cItem)) {
@@ -387,6 +387,10 @@ export const useInteractiveDrawAreas = <T extends ShapeType>(type: T) => {
     type,
     useIA: useInteractiveAreas,
     refSelf: type === "arrow",
+    addBefore: (data) => {
+      const positions = data as Area
+      return lineLen(positions[0], positions[1]) > 1
+    },
     enter() {
       cursorPop = cursor.push("./icons/m_draw.png");
     },

+ 6 - 3
vite.config.ts

@@ -29,7 +29,7 @@ function getChinaTimeISO() {
 export default ({ mode }: any) => {
   const env = loadEnv(mode, envDir);
   const buildTime = getChinaTimeISO();
-  console.log('current', buildTime)
+  console.log("current", buildTime);
 
   let proxy: any = {};
   if (env.VITE_MOCK_ENV) {
@@ -45,7 +45,7 @@ export default ({ mode }: any) => {
     if (env.VITE_MOCK_PROXY) {
       proxy[env.VITE_MOCK_PROXY] = getProxy(
         env.VITE_MOCK_PROXY,
-        mockEnv.VITE_MOCK_PROXY
+        mockEnv.VITE_MOCK_PROXY,
       );
     } else {
       for (const key in env) {
@@ -91,6 +91,9 @@ export default ({ mode }: any) => {
       host: "0.0.0.0",
       proxy: proxy,
     },
+    preview: {
+      port: 9011,
+    },
     plugins: [
       {
         name: "remove-static-models",
@@ -99,7 +102,7 @@ export default ({ mode }: any) => {
             __dirname,
             "dist",
             outDir || "",
-            "static/models"
+            "static/models",
           );
           console.log("remove dist", dir);
           if (fs.existsSync(dir)) {