|
@@ -1,7 +1,7 @@
|
|
|
import type { TabCover } from "./store";
|
|
|
import type { Scene } from "../../example/platform/platform-resource";
|
|
|
import type { StoreData } from "@/core/store/store";
|
|
|
-import { params } from "../env";
|
|
|
+import { token, params, urlUpdateQuery, urlGetQuery } from "../env";
|
|
|
import { genLoading } from "../loadding";
|
|
|
import { tempStrFill } from "@/utils/shared";
|
|
|
|
|
@@ -24,22 +24,29 @@ const viewURLS = {
|
|
|
[SCENE_TYPE.fuse]: import.meta.env.VITE_FUSE_VIEW,
|
|
|
};
|
|
|
|
|
|
-const token = (params.token || localStorage.getItem("token")) as string;
|
|
|
-const headers = { token, caseId: params.caseId, 'page-type': 'edit' }
|
|
|
+const getHeaders = () => ({
|
|
|
+ token: token.value || localStorage.getItem("token") || "",
|
|
|
+ caseId: params.value.caseId || "",
|
|
|
+ "page-type": "edit",
|
|
|
+});
|
|
|
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} ));
|
|
|
+ return after(fetch(l, { method: "get", headers: getHeaders() }));
|
|
|
};
|
|
|
|
|
|
const post = (url: string, data: Record<string, any>) => {
|
|
|
const l = `${resourceURLS[SCENE_TYPE.fuse]}${url}`;
|
|
|
+ console.log(data)
|
|
|
return after(
|
|
|
fetch(l, {
|
|
|
- headers: { "Content-Type": "application/json;charset=UTF-8", ...headers },
|
|
|
+ headers: {
|
|
|
+ "Content-Type": "application/json;charset=UTF-8",
|
|
|
+ ...getHeaders(),
|
|
|
+ },
|
|
|
method: "post",
|
|
|
body: JSON.stringify(data),
|
|
|
})
|
|
@@ -55,7 +62,7 @@ const postFile = (url: string, data: Record<string, any>) => {
|
|
|
const l = `${resourceURLS[SCENE_TYPE.fuse]}${url}`;
|
|
|
return after(
|
|
|
fetch(l, {
|
|
|
- headers,
|
|
|
+ headers: getHeaders(),
|
|
|
method: "post",
|
|
|
body: formData,
|
|
|
})
|
|
@@ -64,27 +71,28 @@ const postFile = (url: string, data: Record<string, any>) => {
|
|
|
|
|
|
const login = (isBack = true) => {
|
|
|
if (import.meta.env.VITE_LOGIN_VIEW) {
|
|
|
- const curUrl = new URL(location.href)
|
|
|
- curUrl.searchParams.delete('token')
|
|
|
-
|
|
|
- const link = isBack
|
|
|
- ? tempStrFill(import.meta.env.VITE_LOGIN_VIEW, {
|
|
|
- redirect: escape(curUrl.toString()),
|
|
|
- })
|
|
|
- : import.meta.env.VITE_LOGIN_VIEW;
|
|
|
- const url = new URL(link)
|
|
|
+ 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) {
|
|
|
- url.searchParams.delete('redirect')
|
|
|
+ const url = new URL(link);
|
|
|
+ url.searchParams.delete("redirect");
|
|
|
+ const query = urlGetQuery(url.toString())
|
|
|
+ delete query['redirect']
|
|
|
+ link = urlUpdateQuery(url.toString(), query, true)
|
|
|
}
|
|
|
- location.replace(url.toString());
|
|
|
+ location.replace(link);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const after = async (fet: Promise<Response>) => {
|
|
|
const res = await fet.then((res) => res.json());
|
|
|
- if ([4008, 4010].includes(res.code)) {
|
|
|
+ if ([4008, 4010, 7012].includes(res.code)) {
|
|
|
setTimeout(() => {
|
|
|
- login();
|
|
|
+ login(res.code !== 7012);
|
|
|
}, 1000);
|
|
|
throw res.message;
|
|
|
} else if (res.code !== 0) {
|
|
@@ -94,13 +102,13 @@ const after = async (fet: Promise<Response>) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-if (!params.caseId || !token) {
|
|
|
- login(!!params.caseId);
|
|
|
+if (!params.value.caseId || !token) {
|
|
|
+ login(!!params.value.caseId);
|
|
|
}
|
|
|
|
|
|
const getSceneList = genLoading(async (keyword: string): Promise<Scene[]> => {
|
|
|
const list = await post(`fusion/case/sceneListPost`, {
|
|
|
- caseId: params.caseId,
|
|
|
+ caseId: params.value.caseId,
|
|
|
isMesh: 1,
|
|
|
sceneName: keyword,
|
|
|
});
|
|
@@ -109,7 +117,7 @@ const getSceneList = genLoading(async (keyword: string): Promise<Scene[]> => {
|
|
|
m: item.num,
|
|
|
title: item.name,
|
|
|
id: item.id.toString(),
|
|
|
- token
|
|
|
+ token,
|
|
|
}));
|
|
|
});
|
|
|
|
|
@@ -136,7 +144,7 @@ const saveOverviewData = genLoading(
|
|
|
}
|
|
|
) => {
|
|
|
const item = await post(`fusion/caseOverview/addOrUpdate`, {
|
|
|
- ...params,
|
|
|
+ ...params.value,
|
|
|
id,
|
|
|
store: JSON.stringify(data.store),
|
|
|
viewport: JSON.stringify(data.viewport),
|
|
@@ -149,7 +157,6 @@ const getTabulationId = async (id: string) => {
|
|
|
const list = await get("fusion/caseTabulation/getByOverviewId", {
|
|
|
overviewId: id,
|
|
|
});
|
|
|
- console.log(list)
|
|
|
return list[0]?.id;
|
|
|
};
|
|
|
|
|
@@ -186,7 +193,7 @@ const saveTabulationData = genLoading(
|
|
|
}
|
|
|
) => {
|
|
|
const item = await post("fusion/caseTabulation/addOrUpdate", {
|
|
|
- ...params,
|
|
|
+ ...params.value,
|
|
|
id,
|
|
|
store: JSON.stringify(data.store),
|
|
|
viewport: JSON.stringify(data.viewport),
|
|
@@ -201,13 +208,13 @@ const saveTabulationData = genLoading(
|
|
|
|
|
|
const uploadResourse = genLoading(async (file: File) => {
|
|
|
const url = await postFile(`fusion/upload/file`, { file });
|
|
|
- if (url.includes('//')) {
|
|
|
- return url
|
|
|
+ if (url.includes("//")) {
|
|
|
+ return url;
|
|
|
}
|
|
|
if (import.meta.env.DEV && import.meta.env.VITE_STATIC) {
|
|
|
- return `${import.meta.env.VITE_STATIC}${url}`
|
|
|
+ return `${import.meta.env.VITE_STATIC}${url}`;
|
|
|
} else {
|
|
|
- return url
|
|
|
+ return url;
|
|
|
}
|
|
|
});
|
|
|
|