Browse Source

feat:下载处理更改属性-image情况

ananzhusen 11 months ago
parent
commit
b35835268f
1 changed files with 140 additions and 1 deletions
  1. 140 1
      src/services/download.ts

+ 140 - 1
src/services/download.ts

@@ -105,8 +105,69 @@ export const getDownloadList = (meta2dData: any, path: string = 'v') => {
         }
       }
     }
+    pen.events?.forEach((event) => {
+      if (event.actions?.length) {
+        event.actions.forEach((action) => {
+          if (action.action === 1) {
+            //更改属性
+            if (action.value?.image) {
+              let image = action.value.image;
+              if (
+                image.startsWith('/') ||
+                image.startsWith(img_cdn) ||
+                image.startsWith(img_upCdn)
+              ) {
+                // 只考虑相对路径下的 image ,绝对路径图片无需下载
+                let _img = image.replace(img_cdn, '').replace(img_upCdn, '');
+                if (_img.startsWith('/v/')) {
+                  _img = _img.slice(2);
+                }
+                if (!images.includes(image)) {
+                  lists.add({
+                    url: image,
+                    path: `/view/projects/assets` + _img,
+                  });
+                }
+                action.value.image = `projects/assets` + _img;
+              }
+            }
+          }
+        });
+      }
+    });
+    pen.triggers?.forEach((trigger) => {
+      trigger?.status?.forEach((state) => {
+        if (state.actions?.length) {
+          state.actions.forEach((action) => {
+            if (action.action === 1) {
+              //更改属性
+              if (action.value?.image) {
+                let image = action.value.image;
+                if (
+                  image.startsWith('/') ||
+                  image.startsWith(img_cdn) ||
+                  image.startsWith(img_upCdn)
+                ) {
+                  // 只考虑相对路径下的 image ,绝对路径图片无需下载
+                  let _img = image.replace(img_cdn, '').replace(img_upCdn, '');
+                  if (_img.startsWith('/v/')) {
+                    _img = _img.slice(2);
+                  }
+                  if (!images.includes(image)) {
+                    lists.add({
+                      url: image,
+                      path: `/view/projects/assets` + _img,
+                    });
+                  }
+                  action.value.image = `projects/assets` + _img;
+                }
+              }
+            }
+          });
+        }
+      });
+    });
   }
-
   if(path === 'v'){ //iframe嵌入的页面无需再次下载
     //其他文件
     const files = [
@@ -715,6 +776,84 @@ export const getFrameDownloadList =(meta2dData: any, path: string = 'v',type:Fra
         }
       }
     }
+    pen.events?.forEach((event) => {
+      if (event.actions?.length) {
+        event.actions.forEach((action) => {
+          if (action.action === 1) {
+            //更改属性
+            if (action.value?.image) {
+              let image = action.value.image;
+              if (
+                image.startsWith('/') ||
+                image.startsWith(img_cdn) ||
+                image.startsWith(img_upCdn)
+              ) {
+                // 只考虑相对路径下的 image ,绝对路径图片无需下载
+                let _img = image.replace(img_cdn, '').replace(img_upCdn, '');
+                if (_img.startsWith('/v/')) {
+                  _img = _img.slice(2);
+                }
+                let path =  (`${
+                  type === Frame.vue3
+                      ? 'meta2d-vue3'
+                      : type === Frame.vue2
+                      ? 'meta2d-vue2'
+                      : 'meta2d-react'
+                  }/public`) + _img
+                if (!images.includes(image)) {
+                  // let _img = image.replace(cdn, '').replace(upCdn, '');
+                  lists.add({
+                    url: image,
+                    path,
+                  });
+                }
+                action.value.image = _img;
+              }
+            }
+          }
+        });
+      }
+    });
+    pen.triggers?.forEach((trigger) => {
+      trigger?.status?.forEach((state) => {
+        if (state.actions?.length) {
+          state.actions.forEach((action) => {
+            if (action.action === 1) {
+              //更改属性
+              if (action.value?.image) {
+                let image = action.value.image;
+                if (
+                  image.startsWith('/') ||
+                  image.startsWith(img_cdn) ||
+                  image.startsWith(img_upCdn)
+                ) {
+                  // 只考虑相对路径下的 image ,绝对路径图片无需下载
+                  let _img = image.replace(img_cdn, '').replace(img_upCdn, '');
+                  if (_img.startsWith('/v/')) {
+                    _img = _img.slice(2);
+                  }
+                  let path =  (`${
+                    type === Frame.vue3
+                        ? 'meta2d-vue3'
+                        : type === Frame.vue2
+                        ? 'meta2d-vue2'
+                        : 'meta2d-react'
+                    }/public`) + _img
+                  if (!images.includes(image)) {
+                    // let _img = image.replace(cdn, '').replace(upCdn, '');
+                    lists.add({
+                      url: image,
+                      path,
+                    });
+                  }
+                  action.value.image = _img;
+                }
+              }
+            }
+          });
+        }
+      });
+    });
   }
 
   let folderName =type===Frame.vue3?'meta2d-vue3':type===Frame.vue2?'meta2d-vue2': 'meta2d-react';