ananzhusen пре 1 месец
родитељ
комит
b16b4bfaa7
3 измењених фајлова са 31 додато и 8 уклоњено
  1. 4 0
      src/services/api.ts
  2. 16 2
      src/services/common.ts
  3. 11 6
      src/services/download.ts

+ 4 - 0
src/services/api.ts

@@ -47,6 +47,10 @@ export async function updateCollection(collection: string, data: any) {
   return await axios.post(`/api/data/${collection}/update`, data);
 }
 
+export async function getCollection(collection: string, id: string, projection?: any) {
+  return await axios.post(`/api/data/${collection}/get`, {id,projection});
+}
+
 export async function getCollectionList(
   collection: string,
   data: any,

+ 16 - 2
src/services/common.ts

@@ -15,8 +15,12 @@ import { deepClone, isDomShapes } from '@meta2d/core';
 import { useSelection } from '@/services/selections';
 import { rootDomain } from './defaults';
 import { updateObject } from './object';
+import { useProject } from './project';
+
 import i18n from '../i18n';
 const $t = i18n.global.t;
+
+const {saveProject, clearProject } = useProject();
 const { select } = useSelection();
 
 const assets = reactive({
@@ -389,7 +393,7 @@ export const save = async (
       }
     }
   });
-  
+  let projectId = null;
   // data.childIds = childIds;
   const body:any = {
     data,
@@ -426,7 +430,13 @@ export const save = async (
     //   delete data.folder;
     //   ret = await updateCollection(collection, data);
     // } else
-    
+    if(collection === 'v'){
+      projectId = await saveProject();
+      if(projectId){
+        body.otherData = {projectId};
+      }
+    }
+
     if (data.id || data._id) {
       body.ownerId = data.ownerId;
       body.ownerName = data.ownerName;
@@ -438,6 +448,9 @@ export const save = async (
   if (ret.error) {
     return;
   }
+  if(ret.id){
+    await saveProject(ret.id);
+  }
   //  保存图纸之后的钩子函数
   globalThis.afterSaveMeta2d && (await globalThis.afterSaveMeta2d(ret));
   if (
@@ -646,6 +659,7 @@ export const newFile = () => {
       r: Date.now() + '',
     },
   });
+  clearProject();
   // setTimeout(() => {
   //   autoSave(true);
   // }, 300);

+ 11 - 6
src/services/download.ts

@@ -63,6 +63,7 @@ export const getDownloadList = (meta2dData: any, path: string = 'v') => {
   //TODO 加一个type区分是数据/还是接口
   //背景图片
   // const meta2dData = meta2d.data();
+  if(meta2dData){
   let img = meta2dData.bkImage;
   if (img) {
     if (
@@ -82,7 +83,7 @@ export const getDownloadList = (meta2dData: any, path: string = 'v') => {
       meta2dData.bkImage = `projects/assets` + _img;
     }
   }
-
+  
   //图片图元(image strokeImage backgroundImage)
   const imageKeys = ['image', 'strokeImage', 'backgroundImage','activeBgImage','bgImage'];
   const images: string[] = [];
@@ -207,6 +208,7 @@ export const getDownloadList = (meta2dData: any, path: string = 'v') => {
       }
     }
   }
+  }
   if(path === 'v'){ //iframe嵌入的页面无需再次下载
     //其他文件
     const files = [
@@ -273,6 +275,7 @@ export const getDownloadList = (meta2dData: any, path: string = 'v') => {
       });
     });
   }
+  if(meta2dData){
   //数据
   // const data: any = meta2d.data();
   if (meta2dData._id) delete meta2dData._id;
@@ -285,7 +288,7 @@ export const getDownloadList = (meta2dData: any, path: string = 'v') => {
       .replaceAll(img_upCdn, ''),
     path: `/view/projects/${path}`,
   });
-
+  }
   return lists;
 };
 
@@ -390,7 +393,7 @@ export const getComponentPurchased = async (list: any) => {
     list: _list,
   });
 
-  if (res.error) {
+  if (res?.error) {
     return [];
   }
 
@@ -405,7 +408,7 @@ export const getComponentPurchased = async (list: any) => {
   //   ([...list.iotPens].length - purchasedIot.length) * 70+
   //   ([...list.svgPens].length - purchasedSvg.length) * 10;
 
-  return res.list;
+  return res?.list||[];
 };
 
 export const get2dComponentJs = async (names: string[] = components) => {
@@ -779,6 +782,7 @@ export async function zipImages(zip: JSZip, pens: Pen[]) {
 
 export const getFrameDownloadList =(meta2dData: any, path: string = 'v',type:Frame, flag_3d=false) => {
   const lists = new Set();
+  if(meta2dData){
   let img = meta2dData.bkImage;
   if (img) {
     if (
@@ -922,7 +926,7 @@ export const getFrameDownloadList =(meta2dData: any, path: string = 'v',type:Fra
       });
     });
   }
-
+  }
   let folderName =type===Frame.vue3?'meta2d-vue3':type===Frame.vue2?'meta2d-vue2': 'meta2d-react';
   if(path === 'v'){ //iframe嵌入的页面无需再次下载
     //其他文件
@@ -1122,6 +1126,7 @@ export const getFrameDownloadList =(meta2dData: any, path: string = 'v',type:Fra
       });
     }); 
   }
+  if(meta2dData){
   //图纸数据
   if (meta2dData._id) delete meta2dData._id;
   if (meta2dData.id) delete meta2dData.id;
@@ -1132,7 +1137,7 @@ export const getFrameDownloadList =(meta2dData: any, path: string = 'v',type:Fra
       .replaceAll(img_upCdn, ''),
     path: `/${folderName}/public/json/${path}.json`,
   });
-
+  }
   return lists;
 };