bill пре 3 месеци
родитељ
комит
f66229ef36

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

@@ -138,6 +138,9 @@ export const useInteractiveDrawShapeAPI = installGlobalVar(() => {
       return currentAddCount;
     },
     drawing: computed(() => mode.include(Mode.draw)),
+    drawType: computed(() => {
+      return interactiveProps.value?.type && components[interactiveProps.value?.type].addMode
+    })
   };
 });
 

+ 1 - 1
src/core/hook/use-expose.ts

@@ -15,7 +15,7 @@ import { useGetViewBoxPositionPixel, useSetViewport, useViewer } from "./use-vie
 import { useGlobalResize, useListener } from "./use-event.ts";
 import { useInteractiveDrawShapeAPI } from "./use-draw.ts";
 import { useHistory } from "./use-history.ts";
-import { nextTick, watchEffect } from "vue";
+import { watchEffect } from "vue";
 import { usePaste } from "./use-paste.ts";
 import { useMouseShapesStatus } from "./use-mouse-status.ts";
 import { Mode } from "@/constant/mode.ts";

+ 1 - 1
src/example/components/container/container.vue

@@ -13,7 +13,7 @@
           @click="draw.quitDrawShape()"
           circle
           class="h-bottom"
-          v-if="draw?.drawing"
+          v-if="draw?.drawType === 'single-dots' || draw?.drawType === 'dots'"
         >
           <template #icon>
             <icon name="pic_yes" size="32px" color="#41c732" />

+ 1 - 1
src/example/components/container/use-draw.ts

@@ -5,7 +5,7 @@ const actionKey = Symbol("drawAction");
 export type Draw = ShallowUnwrapRef<DrawExpose>;
 export const installDraw = (drawRef: Ref<DrawExpose | undefined>) => {
   provide(actionKey, drawRef);
-  return drawRef
+  return drawRef as Ref<Draw | undefined>
 };
 
 export const useDraw = () => {

+ 9 - 4
src/example/dialog/vr/vr.vue

@@ -15,6 +15,7 @@
       remote-show-suffix
       :loading="loading"
     >
+      <template #empty> 123123 </template>
       <el-option
         v-for="item in scenes"
         :key="item.m"
@@ -26,10 +27,10 @@
 </template>
 
 <script lang="ts" setup>
-import { ElSelect, ElOption } from "element-plus";
+import { ElSelect, ElOption, ElMessage } from "element-plus";
 import { computed, ref } from "vue";
 import { asyncTimeout } from "@/utils/shared";
-import { Scene, SCENE_TYPE, SceneTypeNames } from "../../platform/platform-resource";
+import { Scene, SceneTypeNames } from "../../platform/platform-resource";
 
 const props = defineProps<{ value?: Scene; label: string }>();
 const emit = defineEmits<{ (e: "update:value", val: Scene): void }>();
@@ -57,9 +58,13 @@ const searchSenects = async (keyword: string) => {
   oldKeyword = keyword;
 
   loading.value = true;
-  await asyncTimeout(1000);
-  scenes.value = await window.platform.getSceneList(keyword);;
+  await asyncTimeout(300);
+  scenes.value = await window.platform.getSceneList(keyword);
   loading.value = false;
+
+  if (!keyword && scenes.value.length === 0) {
+    ElMessage.error("当前绘图无场景数据");
+  }
 };
 
 searchSenects("");

+ 62 - 47
src/example/env.ts

@@ -1,71 +1,86 @@
 import { inRevise } from "@/utils/shared";
 import { computed, ref, watch } from "vue";
 
-
-export const urlUpdateQuery = (link: string, params: Record<string, string>, rep = false) => {
-  const url = new URL(link)
-  const ndx = url.hash.indexOf('?')
-  let search: URLSearchParams
+export const urlUpdateQuery = (
+  link: string,
+  params: Record<string, string>,
+  rep = false
+) => {
+  const url = new URL(link);
+  const ndx = url.hash.indexOf("?");
+  let search: URLSearchParams;
   if (!rep && ~ndx) {
     search = new URLSearchParams({
       ...(urlGetQuery(link) as any),
-      ...params
-    })
+      ...params,
+    });
     for (const key in params) {
-      search.set(key, params[key])
+      search.set(key, params[key]);
     }
   } else {
-    search = new URLSearchParams(params)
+    search = new URLSearchParams(params);
   }
-  url.hash = url.hash.substring(0, ndx + 1) + search.toString()
+  url.hash = url.hash.substring(0, ndx + 1) + search.toString();
 
-  return url.toString()
-}
+  return url.toString();
+};
 
 export const urlGetQuery = (link: string) => {
-  const url = new URL(link)
-  const hash = url.hash
-  const ndx = hash.indexOf('?')
-  if (!~ndx) return {}
+  const url = new URL(link);
+  const hash = url.hash;
+  const ndx = hash.indexOf("?");
+  if (!~ndx) return {};
 
   const sParams = new URLSearchParams(hash.substring(ndx));
   const rParams: Record<string, string> = {};
-  [...sParams.entries()].forEach(item => {
-    rParams[item[0]] = item[1]
-  })
-  return rParams
-}
+  [...sParams.entries()].forEach((item) => {
+    rParams[item[0]] = item[1];
+  });
+  return rParams;
+};
 
-export const params = ref<Record<string, string | undefined>>({})
+export const params = ref<Record<string, string | undefined>>({});
+const sParams = new URLSearchParams(location.search);
+[...sParams.entries()].forEach((item) => {
+  params.value[item[0]] = item[1];
+});
 const updateParams = () => {
-  const rParams = urlGetQuery(location.href)
+  const rParams = urlGetQuery(location.href);
   if (inRevise(rParams, params.value)) {
-    params.value = rParams
-  }
-}
-
-watch(params, () => {
-  const sParams = new URLSearchParams();
-  for (const key in params.value) {
-    params.value[key] && sParams.append(key, params.value[key])
+    params.value = rParams;
   }
-  const ndx = location.hash.indexOf('?')
-  location.replace(location.hash.substring(0, ~ndx ? ndx : undefined) + '?' + sParams.toString())
-}, {deep: true})
+};
 
+watch(
+  params,
+  () => {
+    const sParams = new URLSearchParams();
+    for (const key in params.value) {
+      params.value[key] && sParams.append(key, params.value[key]);
+    }
+    const ndx = location.hash.indexOf("?");
+    location.replace(
+      location.hash.substring(0, ~ndx ? ndx : undefined) +
+        "?" +
+        sParams.toString()
+    );
+  },
+  { deep: true }
+);
 
-updateParams()
-window.addEventListener('hashchange', updateParams)
+updateParams();
+window.addEventListener("hashchange", updateParams);
 
-const getQuisk = (key: string) => computed({
-  get() {
-    return params.value[key]
-  },
-  set(val: string) {
-    params.value[key] = val
-  }
-})
+const getQuisk = (key: string) =>
+  computed({
+    get() {
+      return params.value[key];
+    },
+    set(val: string) {
+      params.value[key] = val;
+    },
+  });
 
-export const tabulationId = getQuisk('tabulationId')
-export const overviewId = getQuisk('overviewId')
-export const token = getQuisk('token')
+export const tabulationId = getQuisk("tabulationId");
+export const overviewId = getQuisk("overviewId");
+export const token = getQuisk("token");

+ 10 - 7
src/example/platform/platform-draw.ts

@@ -4,7 +4,7 @@ import { Draw } from "../components/container/use-draw";
 import { SceneFloor } from "./platform-resource";
 import { getBaseItem } from "@/core/components/util";
 import { LineData, defaultStyle } from "@/core/components/line";
-import { getInitCtx } from "@/core/components/line/use-draw";
+import { getInitCtx, normalLineData } from "@/core/components/line/use-draw";
 import { defaultStyle as iconDefaultStyle } from "@/core/components/icon";
 import { Transform } from "konva/lib/Util";
 import { MathUtils } from "three";
@@ -123,7 +123,7 @@ const drawLayerResource = (
   const createTime = Date.now();
 
   let sGeo = draw.store.getTypeItems('line')[0]
-  const geo: LineData = sGeo ? sGeo : {
+  let geo: LineData = sGeo ? sGeo : {
     ...getBaseItem(),
     lines: [],
     points: [],
@@ -154,11 +154,14 @@ const drawLayerResource = (
     geoCtx.add.points[b!] = p
     geo.points.push(p)
   });
-  if (sGeo) {
-    draw.store.setItem('line', {id: geo.id, value: geo });  
-  } else {
-    draw.store.addItem('line', geo);
-  }
+  draw.history.onceTrack(() => {
+    geo = normalLineData(geo, geoCtx)
+    if (sGeo) {
+      draw.store.setItem('line', {id: geo.id, value: geo });  
+    } else {
+      draw.store.addItem('line', geo);
+    }
+  })
 
   if (layerResource.thumb) {
     const box = layerResource.box;

+ 12 - 5
src/example/platform/platform-resource.ts

@@ -53,12 +53,19 @@ export const SceneTypeNames = {
 };
 
 export const getSceneApi = async (type: string, url: string) => {
-  let uri: string;
-  try {
-    uri = new URL(url, window.platform.resourceURLS[type]).toString();
-  } catch {
-    uri = window.platform.resourceURLS[type] + url;
+  if (url[url.length - 1] === '/') {
+    url = url.substring(0, url.length - 1)
   }
+  let origin = window.platform.resourceURLS[type]
+  if (origin[origin.length - 1] !== '/') {
+    origin = origin + '/'
+  }
+  const uri = origin + url
+  // try {
+  //   uri = new URL(window.platform.resourceURLS[type]).toString();
+  // } catch {
+  //   uri = window.platform.resourceURLS[type] + url;
+  // }
   const res = await fetch(uri, { method: "HEAD" });
   if (res.status !== 200) {
     throw `${uri}链接错误`;