bill 1 maand geleden
bovenliggende
commit
2c5fffa6f2
5 gewijzigde bestanden met toevoegingen van 62 en 8 verwijderingen
  1. 2 2
      .env.fuse
  2. 1 1
      .env.fusedev
  3. 1 1
      .env.fusetest
  4. 53 0
      src/example/fuse/enter-mix.ts
  5. 5 4
      src/example/fuse/enter.ts

+ 2 - 2
.env.fuse

@@ -1,6 +1,6 @@
 VITE_PRIMARY='#D8000A'
 VITE_TITLE='绘图'
-VITE_ENTRY='/example/fuse/enter.ts'
+VITE_ENTRY='/example/fuse/enter-mix.ts'
 VITE_ENTRY_EXAMPLE='./main.ts'
 VITE_MESH_OSS='https://4dkk.4dage.com/'
 VITE_MESH_API='https://www.4dkankan.com/'
@@ -9,4 +9,4 @@ VITE_FUSE_API='https://mix3d.4dkankan.com/'
 VITE_MESH_VIEW='https://www.4dkankan.com/spg.html?m={m}&lang=zh'
 VITE_CLOUD_VIEW='https://laser.4dkankan.com/index.html?m={m}&lang=zh'
 VITE_FUSE_VIEW='https://mix3d.4dkankan.com/'
-VITE_LOGIN_VIEW='https://test-mix3d.4dkankan.com/fire/?redirect={redirect}#login'
+VITE_LOGIN_VIEW='https://test-mix3d.4dkankan.com/fire/?redirect={redirect}#login'

+ 1 - 1
.env.fusedev

@@ -1,6 +1,6 @@
 VITE_PRIMARY='#D8000A'
 VITE_TITLE='绘图'
-VITE_ENTRY='/example/fuse/enter.ts'
+VITE_ENTRY='/example/fuse/enter-mix.ts'
 VITE_ENTRY_EXAMPLE='./main.ts'
 VITE_MOCK_ENV=fusetest
 

+ 1 - 1
.env.fusetest

@@ -1,6 +1,6 @@
 VITE_PRIMARY='#D8000A'
 VITE_TITLE='绘图'
-VITE_ENTRY='/example/fuse/enter.ts'
+VITE_ENTRY='/example/fuse/enter-mix.ts'
 VITE_ENTRY_EXAMPLE='./main.ts'
 
 VITE_OSS_ROOT="https://4dkk.4dage.com/"

+ 53 - 0
src/example/fuse/enter-mix.ts

@@ -0,0 +1,53 @@
+import { tempStrFill } from "@/utils/shared";
+import { params, urlGetQuery, urlUpdateQuery } from "../env";
+import { post } from "./enter";
+
+let isLoging = false;
+const login = (isBack = true) => {
+  if (isLoging) {
+    throw "登录中";
+  }
+  isLoging = true;
+  if (import.meta.env.DEV && params.value.caseId) {
+    post("/fusion/fdLogin", {
+      code: "0d76b739ded59dd5",
+      deptId: 1,
+      password: "IQVPKappIyMjIyMjIyMmE=2dfWAaLBMjJcP1bu3l",
+      phoneNum: "88888888888",
+    }).then((res) => {
+      params.value.token = res.token;
+      console.error(res.token);
+      // console.log(res.token, {...params.value})
+      setTimeout(() => location.reload(), 1000);
+      isLoging = false;
+    });
+    return;
+  }
+
+  console.log(import.meta.env.VITE_LOGIN_VIEW);
+  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;
+  }
+};
+window.platform.login = login;

+ 5 - 4
src/example/fuse/enter.ts

@@ -31,7 +31,7 @@ const getHeaders = () => ({
   caseId: params.value.caseId || "",
   "page-type": "edit",
 });
-const get = (url: string, params: Record<string, any>) => {
+export const get = (url: string, params: Record<string, any>) => {
   const p = new URLSearchParams();
   for (const key in params) {
     p.append(key, params[key]);
@@ -40,7 +40,7 @@ const get = (url: string, params: Record<string, any>) => {
   return after(fetch(l, { method: "get", headers: getHeaders() }));
 };
 
-const post = (url: string, data: Record<string, any>) => {
+export const post = (url: string, data: Record<string, any>) => {
   const l = `${resourceURLS[SCENE_TYPE.fuse]}${url}`;
   return after(
     fetch(l, {
@@ -122,7 +122,7 @@ const after = async (fet: Promise<Response>) => {
   const res = await fet.then((res) => res.json());
   if ([4008, 4010, 7012].includes(res.code)) {
     setTimeout(() => {
-      login(res.code !== 7012);
+      window.platform.login(res.code !== 7012);
     }, 1000);
     throw res.message;
   } else if (res.code !== 0) {
@@ -227,7 +227,7 @@ const getTabulationData = genLoading(async (id: string) => {
 
 if (!params.value.caseId || !token) {
   ElMessage.error("当前项目号不存在!");
-  login(!!params.value.caseId);
+  window.platform.login(!!params.value.caseId);
 } else {
   setTimeout(() => getSceneList(""), 500);
 }
@@ -272,6 +272,7 @@ const uploadResourse = genLoading(async (file: File) => {
 });
 
 window.platform = {
+  login,
   resourceURLS,
   viewURLS,
   getOverviewData,