bianjiang 1 rok temu
rodzic
commit
b0b0894244

+ 20 - 2
src/comm/controllers/ProjectCtrl/index.ts

@@ -74,7 +74,7 @@ export class ProjectController extends Controller {
 
     console.log("host url=>", this.HostURL);
 
-    await this.loadProject();
+    // await this.loadProject();
   }
   async save() {
     const detail = this._spu3dFile;
@@ -114,7 +114,25 @@ export class ProjectController extends Controller {
       );
       let data = {} as any;
       if (!text) {
-        data = { categories: ["64e4281a12c676099617ffc6"], title: "" };
+        data = null;
+      } else {
+        data = JSON.parse(text);
+      }
+
+      return data;
+    } catch (error) {
+      alert("项目加载失败" + error);
+    }
+  }
+  async loadFilesCache() {
+    const deviceCtrl = useCtx().deviceCtrl;
+    try {
+      const { text } = await deviceCtrl.ReadFileText(
+        `${this.RootDir}/queen5/assets.cache.queen5`
+      );
+      let data = {} as any;
+      if (!text) {
+        data = null;
       } else {
         data = JSON.parse(text);
       }

+ 2 - 1
src/modules/editor/components/index.ts

@@ -1,7 +1,8 @@
 import Preview from "./Preview";
 import CompSave from "./CompSave";
-
+import PromotionCreate from "@/modules/resource/components/PromotionCreate";
 export default {
   Preview,
   CompSave,
+  PromotionCreate
 };

+ 17 - 8
src/modules/editor/controllers/PageCtrl/index.ts

@@ -64,7 +64,7 @@ export class PageCtrl extends ModuleControl<EditorModule> {
     const out: any = {
       _id: this.designData._id,
       version: this.designData.version,
-      categories:this.designData.categories,
+      categories: this.designData.categories,
       title: this.designData.title,
       desc: this.designData.desc,
       pageStyle: this.designData.pageStyle,
@@ -103,15 +103,16 @@ export class PageCtrl extends ModuleControl<EditorModule> {
 
   async saveAssetsLocal(comp: DesignComp) {
     const { deviceCtrl, prjCtrl } = useCtx();
-    if (!prjCtrl.isLocalUrl(comp.value.url)) {
-      const nameIndex = comp.value.url.lastIndexOf("/");
-      const assetsName = comp.value.url.substring(nameIndex + 1);
+    const assetUrl = comp.value.url;
+    if (!prjCtrl.isLocalUrl(assetUrl)) {
+      const assetsName = assetUrl.replace(/(.*\/)*((\S|\s)+\.*)(\?.*)?/g, "$2");
+      const assetKey = assetsName.replace(/\s/g, "");
       const fpath = `queen5/assets/${assetsName}`;
-      if (this.store.filesCacheUrl.get(assetsName)) {
+      if (this.store.filesCacheUrl[assetKey]) {
         comp.value.url = fpath;
         return;
       }
-      this.store.filesCacheUrl.set(assetsName, "start");
+
       deviceCtrl.DownloadFile(
         comp.value.url,
         prjCtrl.createPath(fpath),
@@ -119,15 +120,23 @@ export class PageCtrl extends ModuleControl<EditorModule> {
         (status: string, p: any) => {
           if (status == "succ") {
             comp.value.url = fpath;
-            this.store.filesCacheUrl.set(assetsName, "succ");
+            this.store.filesCacheUrl[assetKey] = assetUrl;
+            this.localFilesCacheSave();
           }
           if (status == "error") {
-            this.store.filesCacheUrl.delete(assetsName);
+            this.store.filesCacheUrl[assetKey] = undefined;
           }
         }
       );
     }
   }
+  async localFilesCacheSave() {
+    const { deviceCtrl, prjCtrl } = useCtx();
+    await deviceCtrl.WriteFileText(
+      `${prjCtrl.RootDir}/queen5/assets.cache.queen5`,
+      JSON.stringify(this.store.filesCacheUrl)
+    );
+  }
 
   setDesignData(data: Partial<DesignTemp>) {
     history.enable = false;

+ 12 - 0
src/modules/editor/module/actions/edit.tsx

@@ -1147,4 +1147,16 @@ export const editActions = EditorModule.action({
 
     ctrl.state.setDesignId(_id as string);
   },
+  async createLocalPromotion() {
+    const ret = await this.showModal(
+      <this.components.PromotionCreate sourceType="template" />,
+      {
+        width: "340px",
+        maskClosable: false,
+        title: "新建",
+        closable: false,
+      }
+    );
+    return ret;
+  },
 });

+ 11 - 1
src/modules/editor/module/actions/init.ts

@@ -42,7 +42,10 @@ export const initActions = EditorModule.action({
   async initQueen5Design() {
     // const ret = await this.https.getDesignDetail(id, { isSys });
     const ctx = useCtx();
-    const ret =await ctx.prjCtrl.loadQueen5();
+    let ret = await ctx.prjCtrl.loadQueen5();
+    if (!ret) {
+      ret = await this.actions.createLocalPromotion();
+    }
     if (!ret.compMap) {
       const cate: any = this.store.tplCategory || [];
       const item = cate.find((d: any) => ret.categories?.includes(d.id));
@@ -55,6 +58,13 @@ export const initActions = EditorModule.action({
     const page = this.controls.pageCtrl;
     page.setDesignData(ret);
   },
+  async initLocalFilesCache() {
+    const ctx = useCtx();
+    const ret = await ctx.prjCtrl.loadFilesCache();
+    if (ret) {
+      this.store.filesCacheUrl = ret;
+    }
+  },
 
   async initWkDesign(id: string) {
     this.store.setWk(true);

+ 2 - 2
src/modules/editor/module/stores/index.ts

@@ -11,7 +11,7 @@ export const store = EditorModule.store({
     compEditMode: false, //组件编辑模式
     compEditReslut: 0, // -1 取消, 1 确定
     tplCategory: undefined,
-    filesCacheUrl: new Map(),
+    filesCacheUrl: {} as any,
   }),
   getters: {
     currCompId() {
@@ -33,7 +33,7 @@ export const store = EditorModule.store({
     isDisplay(state) {
       return state.mode === "display";
     },
-    
+
     previewImageList(state) {
       const res: string[] = [];
       let scope = this;

+ 1 - 0
src/pages/editor/EditPage/index.tsx

@@ -31,6 +31,7 @@ export default defineComponent(() => {
     //     return;
     //   }
       editor.actions.initQueen5Design();
+      editor.actions.initLocalFilesCache();
     // } else {
     //   editor.jumpIndexHtml();
     // }

+ 0 - 1
src/pages/share/local/style.less

@@ -4,7 +4,6 @@
   height: 100%;
   min-width: 0;
   min-height: 100%;
-  background-color: #fff;
   overflow: auto;
 }