|
@@ -1,361 +1,17 @@
|
|
|
-import type { TabCover } from "./store";
|
|
|
-import type { Scene } from "../../example/platform/platform-resource";
|
|
|
-import type { StoreData } from "@/core/store/store";
|
|
|
-import { token, params, urlUpdateQuery, urlGetQuery } from "../env";
|
|
|
-import { genLoading } from "../loadding";
|
|
|
-import { tempStrFill } from "@/utils/shared";
|
|
|
import { ElMessage } from "element-plus";
|
|
|
-import { gdSearch } from "../dialog/basemap/leaflet/mock";
|
|
|
+import { token } from "../env";
|
|
|
+import * as platform from './enter-shared'
|
|
|
|
|
|
-const SCENE_TYPE = {
|
|
|
- fuse: "fuse",
|
|
|
- mesh: "mesh",
|
|
|
- cloud: "cloud",
|
|
|
-} as const;
|
|
|
-
|
|
|
-const resourceURLS = {
|
|
|
- oss: import.meta.env.VITE_MESH_OSS,
|
|
|
- ossRoot: import.meta.env.VITE_OSS_ROOT,
|
|
|
- [SCENE_TYPE.mesh]: import.meta.env.VITE_MESH_API,
|
|
|
- [SCENE_TYPE.cloud]: import.meta.env.VITE_CLOUD_API,
|
|
|
- [SCENE_TYPE.fuse]: import.meta.env.VITE_FUSE_API,
|
|
|
-};
|
|
|
-
|
|
|
-const viewURLS = {
|
|
|
- [SCENE_TYPE.mesh]: import.meta.env.VITE_MESH_VIEW,
|
|
|
- [SCENE_TYPE.cloud]: import.meta.env.VITE_CLOUD_VIEW,
|
|
|
- [SCENE_TYPE.fuse]: import.meta.env.VITE_FUSE_VIEW,
|
|
|
-};
|
|
|
-
|
|
|
-const getHeaders = () => ({
|
|
|
- token: token.value || localStorage.getItem("token") || "",
|
|
|
- caseId: params.value.caseId || "",
|
|
|
- "page-type": "edit",
|
|
|
-});
|
|
|
-export const get = (url: string, params: Record<string, any>) => {
|
|
|
- const p = new URLSearchParams();
|
|
|
- for (const key in params) {
|
|
|
- p.append(key, params[key]);
|
|
|
- }
|
|
|
- const l = `${resourceURLS[SCENE_TYPE.fuse]}${url}?${p.toString()}`;
|
|
|
- return after(fetch(l, { method: "get", headers: getHeaders() }));
|
|
|
-};
|
|
|
-
|
|
|
-export const post = (url: string, data: Record<string, any>) => {
|
|
|
- const l = `${resourceURLS[SCENE_TYPE.fuse]}${url}`;
|
|
|
- return after(
|
|
|
- fetch(l, {
|
|
|
- headers: {
|
|
|
- "Content-Type": "application/json;charset=UTF-8",
|
|
|
- ...getHeaders(),
|
|
|
- },
|
|
|
- method: "post",
|
|
|
- body: JSON.stringify(data),
|
|
|
- })
|
|
|
- );
|
|
|
-};
|
|
|
-
|
|
|
-const postFile = (url: string, data: Record<string, any>) => {
|
|
|
- const formData = new FormData();
|
|
|
- for (const key in data) {
|
|
|
- formData.append(key, data[key]);
|
|
|
- }
|
|
|
-
|
|
|
- const l = `${resourceURLS[SCENE_TYPE.fuse]}${url}`;
|
|
|
- return after(
|
|
|
- fetch(l, {
|
|
|
- headers: getHeaders(),
|
|
|
- method: "post",
|
|
|
- body: formData,
|
|
|
- })
|
|
|
- );
|
|
|
-};
|
|
|
-
|
|
|
-let isLoging = false;
|
|
|
-const login = (isBack = true) => {
|
|
|
- if (isLoging) {
|
|
|
- throw "登录中";
|
|
|
- }
|
|
|
- isLoging = true;
|
|
|
- if (import.meta.env.DEV && params.value.caseId) {
|
|
|
- post("/service/manage/login", {
|
|
|
- password: "JwiuK95dExMjM0NTY=7nHGf5ySQWSuC4G1An",
|
|
|
- username: "super-admin",
|
|
|
- userName: "super-admin",
|
|
|
- }).then((res) => {
|
|
|
- params.value.token = res.token;
|
|
|
- console.error(res.token);
|
|
|
- // console.log(res.token, {...params.value})
|
|
|
- setTimeout(() => location.reload(), 1000);
|
|
|
- isLoging = false;
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- if (import.meta.env.VITE_LOGIN_VIEW) {
|
|
|
- const p: any = { ...params.value };
|
|
|
- delete p.token;
|
|
|
-
|
|
|
- const cur = urlUpdateQuery(location.href, p, true);
|
|
|
- let link = tempStrFill(import.meta.env.VITE_LOGIN_VIEW, {
|
|
|
- redirect: escape(cur),
|
|
|
- });
|
|
|
-
|
|
|
- if (!isBack) {
|
|
|
- let url: URL;
|
|
|
- try {
|
|
|
- url = new URL(link);
|
|
|
- } catch {
|
|
|
- url = new URL(link, location.origin);
|
|
|
- }
|
|
|
- url.searchParams.delete("redirect");
|
|
|
- const query = urlGetQuery(url.toString());
|
|
|
- delete query["redirect"];
|
|
|
- link = urlUpdateQuery(url.toString(), query, true);
|
|
|
- }
|
|
|
- location.replace(link);
|
|
|
- isLoging = false;
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-const after = async (fet: Promise<Response>) => {
|
|
|
- const res = await fet.then((res) => res.json());
|
|
|
- if (res.code === 8034) {
|
|
|
- setTimeout(() => {
|
|
|
- history.back();
|
|
|
- }, 1000);
|
|
|
- throw `${res.message},即将退出`;
|
|
|
- }
|
|
|
-
|
|
|
- if ([4008, 4010, 7012].includes(res.code)) {
|
|
|
- setTimeout(() => {
|
|
|
- window.platform.login(res.code !== 7012);
|
|
|
- }, 1000);
|
|
|
- throw res.message;
|
|
|
- } else if (res.code !== 0) {
|
|
|
- throw res.message;
|
|
|
- } else {
|
|
|
- return res.data;
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-const getSceneList = genLoading(async (keyword: string): Promise<Scene[]> => {
|
|
|
- const list = await post(`fusion/case/sceneListPost`, {
|
|
|
- caseId: params.value.caseId,
|
|
|
- isMesh: 1,
|
|
|
- sceneName: keyword,
|
|
|
- });
|
|
|
- return list.map((item: any) => ({
|
|
|
- type: SCENE_TYPE.mesh,
|
|
|
- m: item.num,
|
|
|
- title: item.name,
|
|
|
- id: item.id.toString(),
|
|
|
- token,
|
|
|
- }));
|
|
|
-});
|
|
|
-
|
|
|
-const getOverviewData = genLoading(async (id: string) => {
|
|
|
- if (!id) {
|
|
|
- return {
|
|
|
- store: {
|
|
|
- layers: {
|
|
|
- default: {},
|
|
|
- },
|
|
|
- },
|
|
|
- viewport: null,
|
|
|
- };
|
|
|
- }
|
|
|
- const data = await get("fusion/caseOverview/info", { overviewId: id });
|
|
|
- return {
|
|
|
- ...data,
|
|
|
- store: JSON.parse(data.store) || {
|
|
|
- layers: {
|
|
|
- default: {},
|
|
|
- },
|
|
|
- },
|
|
|
- viewport: JSON.parse(data.viewport),
|
|
|
- };
|
|
|
-});
|
|
|
-
|
|
|
-const saveOverviewData = genLoading(
|
|
|
- async (
|
|
|
- id: string,
|
|
|
- data: {
|
|
|
- store: StoreData;
|
|
|
- viewport: number[] | null;
|
|
|
- caseTabulation: {
|
|
|
- id: string;
|
|
|
- store: StoreData;
|
|
|
- viewport: number[] | null;
|
|
|
- isAutoGen: boolean;
|
|
|
- cover: TabCover | null;
|
|
|
- paperKey?: string;
|
|
|
- overviewId: string;
|
|
|
- };
|
|
|
- }
|
|
|
- ) => {
|
|
|
- const item = await post(`fusion/caseOverview/addOrUpdate`, {
|
|
|
- ...params.value,
|
|
|
- ...data,
|
|
|
- id,
|
|
|
- store: JSON.stringify(data.store),
|
|
|
- viewport: JSON.stringify(data.viewport),
|
|
|
- caseTabulation: {
|
|
|
- ...data.caseTabulation,
|
|
|
- store: JSON.stringify(data.caseTabulation.store),
|
|
|
- viewport: JSON.stringify(data.caseTabulation.viewport),
|
|
|
- cover: JSON.stringify(data.caseTabulation.cover),
|
|
|
- isAutoGen: Number(data.caseTabulation.isAutoGen),
|
|
|
- paperKey: data.caseTabulation.paperKey,
|
|
|
- overviewId: data.caseTabulation.overviewId,
|
|
|
- },
|
|
|
- });
|
|
|
- return item.id;
|
|
|
- }
|
|
|
-);
|
|
|
-
|
|
|
-const getTabulationId = async (id: string) => {
|
|
|
- const list = await get("fusion/caseTabulation/getByOverviewId", {
|
|
|
- overviewId: id,
|
|
|
- });
|
|
|
- return list[0]?.id;
|
|
|
-};
|
|
|
-
|
|
|
-const getTabulationData = genLoading(async (id: string) => {
|
|
|
- if (!id) {
|
|
|
- return {
|
|
|
- store: {
|
|
|
- layers: {
|
|
|
- default: {},
|
|
|
- },
|
|
|
- },
|
|
|
- cover: null,
|
|
|
- isAutoGen: true,
|
|
|
- viewport: null,
|
|
|
- paperKey: "a4",
|
|
|
- };
|
|
|
- }
|
|
|
- const data = await get(`fusion/caseTabulation/info`, { tabulationId: id });
|
|
|
- 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",
|
|
|
- };
|
|
|
-});
|
|
|
+window.platform = platform
|
|
|
|
|
|
setTimeout(() => {
|
|
|
- if (!params.value.caseId || !token) {
|
|
|
- ElMessage.error("当前项目号不存在!");
|
|
|
- window.platform.login(!!params.value.caseId);
|
|
|
+ if (!token) {
|
|
|
+ ElMessage.error("当前用户未登录");
|
|
|
+ platform.login();
|
|
|
} else {
|
|
|
- getSceneList("");
|
|
|
+ platform.getSceneList("");
|
|
|
}
|
|
|
}, 500);
|
|
|
|
|
|
-const saveTabulationData = genLoading(
|
|
|
- async (
|
|
|
- id: string,
|
|
|
- data: {
|
|
|
- store: StoreData;
|
|
|
- viewport: number[] | null;
|
|
|
- isAutoGen: boolean;
|
|
|
- cover: TabCover | null;
|
|
|
- paperKey?: string;
|
|
|
- overviewId: string;
|
|
|
- }
|
|
|
- ) => {
|
|
|
- const item = await post("fusion/caseTabulation/addOrUpdate", {
|
|
|
- ...params.value,
|
|
|
- ...data,
|
|
|
- id,
|
|
|
- store: JSON.stringify(data.store),
|
|
|
- viewport: JSON.stringify(data.viewport),
|
|
|
- cover: JSON.stringify(data.cover),
|
|
|
- isAutoGen: Number(data.isAutoGen),
|
|
|
- paperKey: data.paperKey,
|
|
|
- overviewId: data.overviewId,
|
|
|
- });
|
|
|
- return item.id;
|
|
|
- }
|
|
|
-);
|
|
|
-// caseId=6&overviewId=195
|
|
|
-const uploadResourse = genLoading(async (file: File) => {
|
|
|
- const url = await postFile(`fusion/upload/file`, { file });
|
|
|
- if (url.includes("//")) {
|
|
|
- return url;
|
|
|
- }
|
|
|
- if (import.meta.env.DEV && import.meta.env.VITE_STATIC) {
|
|
|
- return `${import.meta.env.VITE_STATIC}${url}`;
|
|
|
- } else {
|
|
|
- return url;
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
-const getTableTemp = () => {
|
|
|
- let table: Record<string, string>;
|
|
|
- let title: string = params.value.title;
|
|
|
- if (params.value.table) {
|
|
|
- try {
|
|
|
- table = JSON.parse(params.value.table);
|
|
|
- } catch (e) {
|
|
|
- console.log("tableTemp模板解析失败");
|
|
|
- }
|
|
|
- }
|
|
|
- if (!table!) {
|
|
|
- table = {
|
|
|
- 案发时间: "",
|
|
|
- 案发地点: "",
|
|
|
- 绘图单位: "",
|
|
|
- 绘图人: "",
|
|
|
- 绘图时间: "",
|
|
|
- };
|
|
|
- }
|
|
|
- if (!title) {
|
|
|
- title = "默认标题";
|
|
|
- }
|
|
|
- return { table, title };
|
|
|
-};
|
|
|
-
|
|
|
-const getTileGroups = async () => {
|
|
|
- const data = await get(`fusion/notAuth/getMapConfig`, {});
|
|
|
- return data.map((item: any) => {
|
|
|
- const mitem = JSON.parse(item.mapUrl);
|
|
|
- return {
|
|
|
- name: item.name,
|
|
|
- tiles: mitem.map((tileItem: any) => ({
|
|
|
- url: tileItem.tempUrl,
|
|
|
- minimumLevel: tileItem.minimumLevel || 1,
|
|
|
- maximumLevel: tileItem.maximumLevel || 18,
|
|
|
- })),
|
|
|
- };
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
-const searchAddress = (keyword: string) => {
|
|
|
- return gdSearch(keyword)
|
|
|
-}
|
|
|
-
|
|
|
-window.platform = {
|
|
|
- login,
|
|
|
- resourceURLS,
|
|
|
- viewURLS,
|
|
|
- getOverviewData,
|
|
|
- getSceneList,
|
|
|
- saveOverviewData,
|
|
|
- getTabulationData,
|
|
|
- saveTabulationData,
|
|
|
- uploadResourse,
|
|
|
- getTabulationId,
|
|
|
- getTableTemp,
|
|
|
- getTileGroups,
|
|
|
- searchAddress
|
|
|
-};
|
|
|
-
|
|
|
/* @vite-ignore */
|
|
|
-import(import.meta.env.VITE_ENTRY_EXAMPLE);
|
|
|
+import(import.meta.env.VITE_ENTRY_EXAMPLE);
|