|
@@ -1,5 +1,9 @@
|
|
|
import type { TabCover } from "./store";
|
|
|
-import type { Scene } from "../platform/platform-resource";
|
|
|
+import type { Scene } from "../../example/platform/platform-resource";
|
|
|
+import type { StoreData } from "@/core/store/store";
|
|
|
+import { params } from "../env";
|
|
|
+import { genLoading } from "../loadding";
|
|
|
+import { tempStrFill } from "@/utils/shared";
|
|
|
|
|
|
const SCENE_TYPE = {
|
|
|
fuse: "fuse",
|
|
@@ -7,127 +11,182 @@ const SCENE_TYPE = {
|
|
|
cloud: "cloud",
|
|
|
} as const;
|
|
|
|
|
|
-const getSceneList = async (): Promise<Scene[]> => [
|
|
|
- {
|
|
|
- m: 'SG-t-KclpWad2dW5',
|
|
|
- title: "有AI",
|
|
|
- id: onlyId(),
|
|
|
- type: SCENE_TYPE.mesh,
|
|
|
-
|
|
|
- },
|
|
|
- {
|
|
|
- m: "SG-t-jvab1SlVA1r",
|
|
|
- title: "多楼层",
|
|
|
- id: onlyId(),
|
|
|
- type: SCENE_TYPE.mesh,
|
|
|
- },
|
|
|
- {
|
|
|
- m: "SG-t-N6no657Kuze",
|
|
|
- title: "单楼层",
|
|
|
- id: onlyId(),
|
|
|
- type: SCENE_TYPE.mesh,
|
|
|
- },
|
|
|
- {
|
|
|
- m: "SS-t-hiNBZjf5EK8",
|
|
|
- title: "庙堂火灾",
|
|
|
- id: onlyId(),
|
|
|
- type: SCENE_TYPE.mesh,
|
|
|
- },
|
|
|
- {
|
|
|
- m: "SS-t-2tWYj9q5whZ",
|
|
|
- title: "车行",
|
|
|
- id: onlyId(),
|
|
|
- type: SCENE_TYPE.mesh,
|
|
|
- },
|
|
|
- {
|
|
|
- m: "SS-t-qnGLxHvngli",
|
|
|
- title: "商品房",
|
|
|
- id: onlyId(),
|
|
|
- type: SCENE_TYPE.mesh,
|
|
|
- },
|
|
|
- {
|
|
|
- m: "SG-t-lDhbbylq4sf",
|
|
|
- title: "多楼层17.30",
|
|
|
- id: onlyId(),
|
|
|
- type: SCENE_TYPE.mesh,
|
|
|
- },
|
|
|
-] as Scene[]
|
|
|
+const resourceURLS = {
|
|
|
+ oss: import.meta.env.VITE_MESH_OSS,
|
|
|
+ [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]: "https://test.4dkankan.com/spg.html?m={m}&lang=zh",
|
|
|
- [SCENE_TYPE.cloud]:
|
|
|
- "https://uat-laser.4dkankan.com/uat/index.html?m={m}&lang=zh",
|
|
|
- [SCENE_TYPE.fuse]:
|
|
|
- "https://test-mix3d.4dkankan.com/code/index.html?caseId={m}&app=1&share=1#/show/summary",
|
|
|
+ [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 resourceURLS = {
|
|
|
- oss: "/meshOSS",
|
|
|
- [SCENE_TYPE.mesh]: "/meshAPI",
|
|
|
- [SCENE_TYPE.cloud]: "/cloudAPI",
|
|
|
- [SCENE_TYPE.fuse]: "/fuseAPI",
|
|
|
+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: { token } }));
|
|
|
};
|
|
|
|
|
|
-import type { StoreData } from "@/core/store/store";
|
|
|
-import { onlyId } from "../../utils/shared";
|
|
|
-
|
|
|
-const getOverviewData = async () => {
|
|
|
- const storeStr = localStorage.getItem("draw-data");
|
|
|
- const store = (storeStr ? JSON.parse(storeStr) : {}) as StoreData;
|
|
|
-
|
|
|
- const vportStr = localStorage.getItem("view-port");
|
|
|
- const vport = (vportStr ? JSON.parse(vportStr) : null) as number[] | null;
|
|
|
-
|
|
|
- return {
|
|
|
- store,
|
|
|
- viewport: vport,
|
|
|
- };
|
|
|
+const post = (url: string, data: Record<string, any>) => {
|
|
|
+ const l = `${resourceURLS[SCENE_TYPE.fuse]}${url}`;
|
|
|
+ return after(
|
|
|
+ fetch(l, {
|
|
|
+ headers: { token, "Content-Type": "application/json;charset=UTF-8" },
|
|
|
+ method: "post",
|
|
|
+ body: JSON.stringify(data),
|
|
|
+ })
|
|
|
+ );
|
|
|
};
|
|
|
|
|
|
-const saveOverviewData = async (data: {
|
|
|
- store: StoreData;
|
|
|
- viewport: number[] | null;
|
|
|
-}) => {
|
|
|
- localStorage.setItem("draw-data", JSON.stringify(data.store));
|
|
|
- localStorage.setItem("view-port", JSON.stringify(data.viewport));
|
|
|
+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: { token },
|
|
|
+ method: "post",
|
|
|
+ body: formData,
|
|
|
+ })
|
|
|
+ );
|
|
|
};
|
|
|
|
|
|
-const getTabulationData = async () => {
|
|
|
- const storeStr = localStorage.getItem("tab-draw-data");
|
|
|
- const store = (storeStr ? JSON.parse(storeStr) : {}) as StoreData;
|
|
|
-
|
|
|
- const vportStr = localStorage.getItem("tab-view-port");
|
|
|
- const vport = (vportStr ? JSON.parse(vportStr) : null) as number[] | null;
|
|
|
-
|
|
|
- const paperKeyStr = localStorage.getItem("tab-paper-key");
|
|
|
- const paperKey = paperKeyStr ? JSON.parse(paperKeyStr) : "a4";
|
|
|
-
|
|
|
- return {
|
|
|
- store,
|
|
|
- cover: tabCover,
|
|
|
- paperKey,
|
|
|
- viewport: vport,
|
|
|
- };
|
|
|
+const login = () => {
|
|
|
+ if (import.meta.env.VITE_LOGIN_VIEW) {
|
|
|
+ setTimeout(() => {
|
|
|
+ location.replace(
|
|
|
+ tempStrFill(import.meta.env.VITE_LOGIN_VIEW, {
|
|
|
+ redirect: escape(location.href),
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }, 3000);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
-const saveTabulationData = async (data: {
|
|
|
- store: StoreData;
|
|
|
- viewport: number[] | null;
|
|
|
- paperKey?: string;
|
|
|
-}) => {
|
|
|
- localStorage.setItem("tab-draw-data", JSON.stringify(data.store));
|
|
|
- localStorage.setItem("tab-view-port", JSON.stringify(data.viewport));
|
|
|
- localStorage.setItem("tab-paper-key", JSON.stringify(data.paperKey));
|
|
|
+const after = async (fet: Promise<Response>) => {
|
|
|
+ const res = await fet.then((res) => res.json());
|
|
|
+ if (res.code === 4008) {
|
|
|
+ login();
|
|
|
+ throw res.message;
|
|
|
+ } else if (res.code !== 0) {
|
|
|
+ throw res.message;
|
|
|
+ } else {
|
|
|
+ return res.data;
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
-let tabCover: TabCover | null = null;
|
|
|
-const saveTabulationCover = async (data: TabCover) => {
|
|
|
- tabCover = data;
|
|
|
+const token = params.token;
|
|
|
+const getSceneList = genLoading(async (keyword: string): Promise<Scene[]> => {
|
|
|
+ const list = await post(`fusion/case/sceneListPost`, {
|
|
|
+ caseId: params.caseId,
|
|
|
+ isMesh: 1,
|
|
|
+ sceneName: keyword,
|
|
|
+ });
|
|
|
+ return list.map((item: any) => ({
|
|
|
+ type: SCENE_TYPE.mesh,
|
|
|
+ m: item.num,
|
|
|
+ title: item.name,
|
|
|
+ id: item.id.toString(),
|
|
|
+ }));
|
|
|
+});
|
|
|
+
|
|
|
+const getOverviewData = genLoading(async (id: string) => {
|
|
|
+ if (!id) {
|
|
|
+ return {
|
|
|
+ store: {},
|
|
|
+ viewport: null,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ const data = await get("fusion/caseOverview/info", { overviewId: id });
|
|
|
+ return {
|
|
|
+ store: JSON.parse(data.store),
|
|
|
+ viewport: JSON.parse(data.viewport),
|
|
|
+ };
|
|
|
+});
|
|
|
+
|
|
|
+const saveOverviewData = genLoading(
|
|
|
+ async (
|
|
|
+ id: string,
|
|
|
+ data: {
|
|
|
+ store: StoreData;
|
|
|
+ viewport: number[] | null;
|
|
|
+ }
|
|
|
+ ) => {
|
|
|
+ const item = await post(`fusion/caseOverview/addOrUpdate`, {
|
|
|
+ ...params,
|
|
|
+ id,
|
|
|
+ store: JSON.stringify(data.store),
|
|
|
+ viewport: JSON.stringify(data.viewport),
|
|
|
+ });
|
|
|
+ return item.id;
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
+const getTabulationId = async (id: string) => {
|
|
|
+ const list = await get("fusion/caseTabulation/getByOverviewId", {
|
|
|
+ overviewId: id,
|
|
|
+ });
|
|
|
+ return list[0]?.id;
|
|
|
};
|
|
|
|
|
|
-const uploadResourse = async (file: File) => {
|
|
|
- return URL.createObjectURL(file);
|
|
|
-};
|
|
|
+const getTabulationData = genLoading(async (id: string) => {
|
|
|
+ if (!id) {
|
|
|
+ return {
|
|
|
+ store: {},
|
|
|
+ cover: null,
|
|
|
+ isAutoGen: true,
|
|
|
+ viewport: null,
|
|
|
+ paperKey: "a4",
|
|
|
+ };
|
|
|
+ }
|
|
|
+ const data = await get(`fusion/caseTabulation/info`, { tabulationId: id });
|
|
|
+ return {
|
|
|
+ store: JSON.parse(data.store),
|
|
|
+ viewport: JSON.parse(data.viewport),
|
|
|
+ cover: JSON.parse(data.cover),
|
|
|
+ isAutoGen: Number(data.isAutoGen),
|
|
|
+ paperKey: data.paperKey,
|
|
|
+ };
|
|
|
+});
|
|
|
+
|
|
|
+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,
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
+const uploadResourse = genLoading(async (file: File) => {
|
|
|
+ return postFile(`fusion/upload/file`, { file });
|
|
|
+});
|
|
|
|
|
|
window.platform = {
|
|
|
resourceURLS,
|
|
@@ -137,8 +196,9 @@ window.platform = {
|
|
|
saveOverviewData,
|
|
|
getTabulationData,
|
|
|
saveTabulationData,
|
|
|
- saveTabulationCover,
|
|
|
uploadResourse,
|
|
|
+ getTabulationId,
|
|
|
};
|
|
|
+
|
|
|
/* @vite-ignore */
|
|
|
import(import.meta.env.VITE_ENTRY_EXAMPLE);
|