Преглед изворни кода

fix(example): preserve tabulation state; transform geocode coords

- Only apply table temp/title injection on initial fetch
- Keep existing compass icon when regenerating tabulation store
- Skip overviewId assignment in DEV
- Convert selected geocode coords from GCJ-02 to WGS84 for leaflet basemap
bill пре 1 дан
родитељ
комит
a5d722a3e7

+ 10 - 6
src/example/dialog/basemap/leaflet/index.vue

@@ -28,12 +28,12 @@
         :class="{ success: mark }"
       >
         <template v-if="mark">
-          <h3>{{$t('background.setting.latlng.success')}}</h3>
+          <h3>{{ $t("background.setting.latlng.success") }}</h3>
           <p>{{ $t("background.setting.lat") }}:{{ mark.lat }}</p>
           <p>{{ $t("background.setting.lng") }}:{{ mark.lng }}</p>
         </template>
         <template v-else>
-          <h3>{{$t('background.setting.latlng.errname')}}</h3>
+          <h3>{{ $t("background.setting.latlng.errname") }}</h3>
           <div class="err-tip" v-html="$t('background.setting.latlng.errtip')"></div>
         </template>
       </div>
@@ -50,7 +50,7 @@
             {{ option.address }}
           </div>
         </template>
-        <p v-else style="text-align: center">{{ $t('icons.undata') }}</p>
+        <p v-else style="text-align: center">{{ $t("icons.undata") }}</p>
       </div>
     </div>
 
@@ -78,6 +78,7 @@ import html2canvas from "html2canvas";
 import { ElInput, ElSelect, ElOption } from "element-plus";
 import { asyncTimeout } from "@/utils/shared";
 import { ui18n } from "@/lang";
+import coordtransform from "coordtransform";
 
 const props = defineProps<SelectMapImageProps>();
 
@@ -97,8 +98,8 @@ const tiles = computed(() => props.tileGroups[groupIndex.value].tiles);
 watchEffect(() => setTileLayers(tiles.value));
 
 const searchTypes = [
-  { label: ui18n.t('background.map.name'), value:  "name" },
-  { label: ui18n.t('background.map.latlng'), value: "latlng" },
+  { label: ui18n.t("background.map.name"), value: "name" },
+  { label: ui18n.t("background.map.latlng"), value: "latlng" },
 ];
 const searchType = ref(searchTypes[1].value as "latlng" | "name");
 const searchName = computed(
@@ -116,8 +117,11 @@ const options = ref<SearchResultItem[]>([]);
 const activeOption = ref<SearchResultItem>();
 const clickOption = (item: SearchResultItem) => {
   activeOption.value = item;
+  [item.latlng.lng, item.latlng.lat] = coordtransform.gcj02towgs84(
+    item.latlng.lng,
+    item.latlng.lat
+  );
   mark.value = item.latlng;
-  console.log(item);
 };
 let token = 0;
 const done = ref(false);

+ 102 - 88
src/example/fuse/enter-shared.ts

@@ -10,13 +10,12 @@ import {
 } from "../dialog/basemap/leaflet/useLeaflet";
 import mitt from "mitt";
 import { defaultLayer } from "@/constant";
-import { tableTitleKey } from '../constant'
+import { tableTitleKey } from "../constant";
 import { getPaperConfig, paperConfigs } from "../components/slide/actions";
 import { getBaseItem } from "@/core/components/util";
 import { getRealPixel } from "./views/tabulation/gen-tab";
 import { ui18n } from "@/lang";
 
-
 export const SCENE_TYPE = {
   fuse: "fuse",
   mesh: "mesh",
@@ -50,7 +49,7 @@ export const get = (url: string, params: Record<string, any>) => {
   }
   const l = `${resourceURLS[SCENE_TYPE.fuse]}${url}?${p.toString()}`;
   return after(
-    fetch(l, { method: "get", headers: window.platform.getHeaders() })
+    fetch(l, { method: "get", headers: window.platform.getHeaders() }),
   );
 };
 
@@ -64,7 +63,7 @@ export const post = (url: string, data: Record<string, any>) => {
       },
       method: "post",
       body: JSON.stringify(data),
-    })
+    }),
   );
 };
 
@@ -80,7 +79,7 @@ export const postFile = (url: string, data: Record<string, any>) => {
       headers: window.platform.getHeaders(),
       method: "post",
       body: formData,
-    })
+    }),
   );
 };
 
@@ -115,12 +114,12 @@ const after = async (fet: Promise<Response>) => {
     if (response.status === 404) {
       res = {
         code: 404,
-        message: ui18n.t('res.code.404'),
+        message: ui18n.t("res.code.404"),
       };
     } else {
       res = {
         code: 500,
-        message: ui18n.t('res.code.500'),
+        message: ui18n.t("res.code.500"),
       };
     }
   } else {
@@ -129,7 +128,7 @@ const after = async (fet: Promise<Response>) => {
     } catch {
       res = {
         code: 500,
-        message: ui18n.t('res.code.500'),
+        message: ui18n.t("res.code.500"),
       };
     }
   }
@@ -141,7 +140,7 @@ const after = async (fet: Promise<Response>) => {
     //   }, 1000);
     // }
     // throw `${res.message},即将退出`;
-    res.code = 8032
+    res.code = 8032;
   }
 
   if ([4008, 4010, 7012].includes(res.code)) {
@@ -152,7 +151,7 @@ const after = async (fet: Promise<Response>) => {
   }
   // 特殊code 不跳转
   if ([8035].includes(res.code)) {
-    throw ui18n.t('res.code.8035');
+    throw ui18n.t("res.code.8035");
   }
 
   if (res.code !== 0) {
@@ -188,7 +187,7 @@ export const getSceneList = (keyword: string) => {
           id: item.id.toString(),
           mapping: item.mapping || "",
           token,
-        } as Scene)
+        }) as Scene,
     );
     list.push(...current);
     page++;
@@ -219,9 +218,9 @@ export const getOverviewData = genLoading(async (id: string) => {
     };
   }
   const data = await get("fusion/caseOverview/info", { overviewId: id });
-  const tabId = await getTabulationId(id)
+  const tabId = await getTabulationId(id);
   if (tabId) {
-      params.value.tabulationId = tabId;
+    params.value.tabulationId = tabId;
   }
   return {
     ...data,
@@ -249,7 +248,7 @@ export const saveOverviewData = genLoading(
         paperKey?: string;
         overviewId: string;
       };
-    }
+    },
   ) => {
     const item = await post(`fusion/caseOverview/addOrUpdate`, {
       ...params.value,
@@ -269,7 +268,7 @@ export const saveOverviewData = genLoading(
       },
     });
     return item.id;
-  }
+  },
 );
 
 export const getTabulationId = async (id: string) => {
@@ -281,41 +280,47 @@ export const getTabulationId = async (id: string) => {
 
 export const _getTabulationData = genLoading(async (id: string) => {
   if (!id) {
-    return {
-      store: {
-        layers: {
-          default: {},
+    return [
+      {
+        store: {
+          layers: {
+            default: {},
+          },
         },
+        cover: null,
+        isAutoGen: true,
+        viewport: null,
+        paperKey: "a4",
       },
-      cover: null,
-      isAutoGen: true,
-      viewport: null,
-      paperKey: "a4",
-    };
+      true,
+    ];
   }
   const data = await get(`fusion/caseTabulation/info`, { tabulationId: id });
   if (data.overviewId) {
     params.value.overviewId = data.overviewId;
   }
-  return {
-    ...data,
-    store: JSON.parse(data.store) || {
-      layers: {
-        default: {},
+  return [
+    {
+      ...data,
+      store: JSON.parse(data.store) || {
+        layers: {
+          default: {},
+        },
       },
+      viewport: JSON.parse(data.viewport),
+      cover: JSON.parse(data.cover),
+      isAutoGen: Number(data.isAutoGen),
+      paperKey: data.paperKey || "a4",
     },
-    viewport: JSON.parse(data.viewport),
-    cover: JSON.parse(data.cover),
-    isAutoGen: Number(data.isAutoGen),
-    paperKey: data.paperKey || "a4",
-  };
+    false,
+  ] as const;
 });
 
 export const getTabulationData = async (...args: any[]) => {
-  const result = await _getTabulationData.apply(this, args as any);
+  const [result, initial] = await _getTabulationData.apply(this, args as any);
 
   const temp = await getTableTemp();
-  if (!result.title && temp.title) {
+  if (initial && !result.title && temp.title) {
     result.title = temp.title;
   }
   if (!result.store) {
@@ -323,39 +328,41 @@ export const getTabulationData = async (...args: any[]) => {
       ...getEmptyStoreData(),
     };
   }
-  if (result.title) {
-    let texts = result.store.layers[defaultLayer].text;
-    if (!texts) {
-      texts = result.store.layers[defaultLayer].text = [];
-    }
-    let title = texts.find((title: any) => title.key === tableTitleKey);
-    if (title) {
-      title.content = result.title;
-    } else {
-      const { margin, size } = getPaperConfig(
-        (paperConfigs as any)[result.paperKey].size,
-        (paperConfigs as any)[result.paperKey].scale
-      );
-      const title = {
-        ...getBaseItem(),
-        content: result.title,
-        width: getRealPixel(90, result.paperKey),
-        heihgt: getRealPixel(14.4, result.paperKey),
-        fontSize: getRealPixel(12, result.paperKey),
-        key: tableTitleKey,
-        align: "center",
-        mat: [1, 0, 0, 1, 0, 0],
-      };
-      const pos = {
-        x:
-          (size.width - margin[3]) / 2 -
-          getRealPixel(40, result.paperKey) +
-          margin[3],
-        y: getRealPixel(15, result.paperKey) + margin[0],
-      };
-      title.mat[4] = pos.x;
-      title.mat[5] = pos.y;
-      texts.push(title);
+  if (initial) {
+    if (result.title) {
+      let texts = result.store.layers[defaultLayer].text;
+      if (!texts) {
+        texts = result.store.layers[defaultLayer].text = [];
+      }
+      let title = texts.find((title: any) => title.key === tableTitleKey);
+      if (title) {
+        // title.content = result.title;
+      } else {
+        const { margin, size } = getPaperConfig(
+          (paperConfigs as any)[result.paperKey].size,
+          (paperConfigs as any)[result.paperKey].scale,
+        );
+        const title = {
+          ...getBaseItem(),
+          content: result.title,
+          width: getRealPixel(90, result.paperKey),
+          heihgt: getRealPixel(14.4, result.paperKey),
+          fontSize: getRealPixel(12, result.paperKey),
+          key: tableTitleKey,
+          align: "center",
+          mat: [1, 0, 0, 1, 0, 0],
+        };
+        const pos = {
+          x:
+            (size.width - margin[3]) / 2 -
+            getRealPixel(40, result.paperKey) +
+            margin[3],
+          y: getRealPixel(15, result.paperKey) + margin[0],
+        };
+        title.mat[4] = pos.x;
+        title.mat[5] = pos.y;
+        texts.push(title);
+      }
     }
   }
   return result;
@@ -371,7 +378,7 @@ export const _saveTabulationData = genLoading(
       cover: TabCover | null;
       paperKey?: string;
       overviewId: string;
-    }
+    },
   ) => {
     const item = await post("fusion/caseTabulation/addOrUpdate", {
       ...params.value,
@@ -385,7 +392,7 @@ export const _saveTabulationData = genLoading(
       overviewId: data.overviewId,
     });
     return item.id;
-  }
+  },
 );
 
 export const saveTabulationData = (id: any, data: any) => {
@@ -431,11 +438,14 @@ export let getTableTemp = async () => {
 
   if (!table!) {
     table = {
-      [ui18n.t('tableTemp.th1')]: "",
-      [ui18n.t('tableTemp.th2')]: "",
-      [ui18n.t('tableTemp.th3')]: "",
-      [ui18n.t('tableTemp.th4')]: "",
-      [ui18n.t('tableTemp.th5')]: formatDate(new Date(), ui18n.t('tableTemp.th5value'))
+      [ui18n.t("tableTemp.th1")]: "",
+      [ui18n.t("tableTemp.th2")]: "",
+      [ui18n.t("tableTemp.th3")]: "",
+      [ui18n.t("tableTemp.th4")]: "",
+      [ui18n.t("tableTemp.th5")]: formatDate(
+        new Date(),
+        ui18n.t("tableTemp.th5value"),
+      ),
     };
 
     if (window.platform.num) {
@@ -443,22 +453,25 @@ export let getTableTemp = async () => {
         num: window.platform.num,
       });
       if (item) {
-        table[ui18n.t('tableTemp.th1')] = item.crimeTimeBegin;
-        table[ui18n.t('tableTemp.th2')] = item.caseLocation;
-        table[ui18n.t('tableTemp.th3')] = item.orgName;
-        table[ui18n.t('tableTemp.th4')] = item.investigatorName;
-        table[ui18n.t('tableTemp.th5')] = formatDate(new Date(), ui18n.t('tableTemp.th5value'));
+        table[ui18n.t("tableTemp.th1")] = item.crimeTimeBegin;
+        table[ui18n.t("tableTemp.th2")] = item.caseLocation;
+        table[ui18n.t("tableTemp.th3")] = item.orgName;
+        table[ui18n.t("tableTemp.th4")] = item.investigatorName;
+        table[ui18n.t("tableTemp.th5")] = formatDate(
+          new Date(),
+          ui18n.t("tableTemp.th5value"),
+        );
         if (!title) {
-          title = ui18n.t('tableTemp.title', item);
+          title = ui18n.t("tableTemp.title", item);
         }
         return (tempCache = { table, title });
       }
     }
   }
   if (!title) {
-    title = ui18n.t('tableTemp.title1');
+    title = ui18n.t("tableTemp.title1");
   }
-  return { table, title, tableTitle: ui18n.t('tableTemp.title2') };
+  return { table, title, tableTitle: ui18n.t("tableTemp.title2") };
 };
 
 export const getTileGroups = async () => {
@@ -478,10 +491,11 @@ export const getTileGroups = async () => {
 };
 
 export const searchAddress = async (keyword: string, mapId: number) => {
-  const data = await post(`fusion/mapConfig/geocode`, {
-    address: keyword,
-    mapId,
-  }) || [];
+  const data =
+    (await post(`fusion/mapConfig/geocode`, {
+      address: keyword,
+      mapId,
+    })) || [];
   return data.map((item: any) => ({
     ...item,
     latlng: latlngStrTransform(item.location.split(",").reverse().join(",")),

+ 1 - 1
src/example/fuse/enter.ts

@@ -40,7 +40,7 @@ const sceneDrawInit = async () => {
       num: m,
       subGroup,
     });
-    if (data?.id) {
+    if (!import.meta.env.DEV && data?.id) {
       params.value.overviewId = data.id;
       delete params.value.m;
       delete params.value.floor;

+ 1 - 0
src/example/fuse/views/defStyle.ts

@@ -56,6 +56,7 @@ export const tabCustomStyle = (p: PaperKey, draw: Draw) => {
     strokeWidth: defFixelStroke,
     fixed: false,
   };
+  console.log(defF)
   const backs = [
     draw.mountFilter.setMenusFilter("serial", (data) => {
       data = { ...data };

+ 4 - 1
src/example/fuse/views/overview/header.vue

@@ -210,7 +210,8 @@ const saveHandler = repeatedlyOnly(async () => {
     tabulationData.value.paperKey,
     storeData.config.compass.rotation,
     undefined,
-    tabulationData.value.isAutoGen ? undefined : tabulationData.value.store
+    tabulationData.value.isAutoGen ? undefined : tabulationData.value.store,
+    !!tabulationId.value
   );
 
   tabStore.config.compass = storeData.config.compass;
@@ -232,8 +233,10 @@ const saveHandler = repeatedlyOnly(async () => {
     body.kankanCover = kankanUrl;
   }
 
+  // if (!import.meta.env.DEV) {
   overviewId.value = await window.platform.saveOverviewData(overviewId.value, body);
   tabulationId.value = await window.platform.getTabulationId(overviewId.value);
+  // }
   emit("saveAfter");
 });
 

+ 12 - 5
src/example/fuse/views/tabulation/gen-tab.ts

@@ -114,6 +114,8 @@ export const genTabulationData = async (
         { ...nameColl, content: name },
         { ...valueColl, content: value },
       ]),
+      strokeWidth: 0.325,
+      fixed: false,
       fontSize: getRealPixel(4, paperKey),
       key: tableTableKey,
       width: nameColl.width + valueColl.width,
@@ -136,7 +138,6 @@ export const genTabulationData = async (
     return matResponse({ data, mat: new Transform().translate(pos.x, pos.y) });
   };
 
-
   const getCover = async () => {
     if (!cover) return;
     const image = await getImage(window.platform.getResource(cover.url));
@@ -169,7 +170,7 @@ export const genTabulationData = async (
       width,
       height,
       mat: [1, 0, 0, 1, 0, 0],
-      itemName: ui18n.t('cover.itemName'),
+      itemName: ui18n.t("cover.itemName"),
     };
     const pos = getFixPosition(
       {
@@ -241,12 +242,12 @@ export const genTabulationData = async (
       ...getBaseItem(),
       ...style,
       disableDelete: true,
-      itemName: ui18n.t('compass.name'),
+      itemName: ui18n.t("compass.name"),
       coverOpcatiy: 0,
       strokeScaleEnabled: false,
       key: tableCompassKey,
       mat: mat.m,
-      name: ui18n.t('compass.name'),
+      name: ui18n.t("compass.name"),
     };
 
     const pos = getFixPosition(
@@ -334,6 +335,7 @@ export const repTabulationStore = async (
   compass?: number,
   cover?: TabCover,
   store?: StoreData,
+  initial?: boolean,
 ) => {
   const repData = await genTabulationData(paperKey, compass, cover);
   const layer = store?.layers && store?.layers[defaultLayer];
@@ -385,8 +387,12 @@ export const repTabulationStore = async (
     const iconData = repData.icon[0];
     const icons = layer.icon || [];
     const iconNdx = icons.findIndex((item) => item.key === iconData.key);
+
     if (~iconNdx) {
-      icons[iconNdx] = iconData;
+      // 指南针保存过则不更新
+      if (iconData.key !== tableCompassKey) {
+        icons[iconNdx] = iconData;
+      }
     } else {
       icons.push(iconData);
     }
@@ -435,6 +441,7 @@ export const repTabulationStore = async (
   //   layer.text = repData.text
   // }
 
+  console.error(layer.text, repData.text);
   store.layers[defaultLayer] = layer;
 
   return store;