Explorar o código

feat(views): 优化图片资源的显示逻辑

ccnnde hai 2 meses
pai
achega
db587c54a2
Modificáronse 2 ficheiros con 6 adicións e 4 borrados
  1. 1 1
      src/services/png.ts
  2. 5 3
      src/views/components/Graphics.vue

+ 1 - 1
src/services/png.ts

@@ -34,7 +34,7 @@ export async function getFolders(name: string, isSvg?: boolean) {
           }
           const elem: any = {
             name,
-            image: import.meta.env.VITE_IMG_API + '/' + f,
+            image: f,
             isSvg,
           };
           list.push(elem);

+ 5 - 3
src/views/components/Graphics.vue

@@ -1358,7 +1358,8 @@ const dragStart = async (event: DragEvent | MouseEvent|TouchEvent, item: any) =>
     // firefox naturalWidth svg 图片 可能是 0
     const width = target.naturalWidth || target.width;
     const height = target.naturalHeight || target.height;
-    const [name, lockedOnCombine] = await isGif(item.image)
+    const urlPrefix = item.image.startsWith('http') ? '' : import.meta.env.VITE_IMG_API + '/'
+    const [name, lockedOnCombine] = await isGif(urlPrefix + item.image)
       ? ['gif', 0]
       : ['image', undefined];
 
@@ -1367,7 +1368,7 @@ const dragStart = async (event: DragEvent | MouseEvent|TouchEvent, item: any) =>
       width,
       height,
       isBottom:true,
-      image: item.image,
+      image: urlPrefix + item.image,
       imageRatio: true,
       ratio: true,
       lockedOnCombine,
@@ -2229,7 +2230,8 @@ const onFold = () => {
 };
 
 const getImgSrc = (elem) => {
-  return import.meta.env.VITE_IMG_API + '/' + elem.image + (activeAssets.value === 'user' ? '' : ('?' + Math.random()))
+  const urlPrefix = elem.image.startsWith('http') ? '' : import.meta.env.VITE_IMG_API + '/'
+  return urlPrefix + elem.image + (activeAssets.value === 'user' ? '' : ('?' + Math.random()))
 }
 
 const loadImage = (elem: any) => {