Ver Fonte

feat:有动画的svg,name设置为gif

ananzhusen há 1 ano atrás
pai
commit
1410c3a387
2 ficheiros alterados com 19 adições e 3 exclusões
  1. 18 2
      src/services/utils.ts
  2. 1 1
      src/views/components/Graphics.vue

+ 18 - 2
src/services/utils.ts

@@ -2,6 +2,7 @@ import { Pen, Meta2dData } from '@meta2d/core';
 import { MessagePlugin, NotifyPlugin, Button } from 'tdesign-vue-next';
 import { h, ref } from 'vue';
 import { upCdn } from './api';
+import axios from 'axios';
 
 export const noLoginTip = '请先登录,否则无法保存!';
 export const localStorageName = 'le5leV';
@@ -131,8 +132,23 @@ export function gotoAccount() {
   }, 3000);
 }
 
-export function isGif(url: string): boolean {
-  return url.endsWith('.gif');
+export async function isGif(url: string): Promise<boolean> {
+  if (url.endsWith('.svg')) {
+    //请求svg图片
+    // if (url.startsWith('https://drive.le5lecdn.com/')) {
+      let res: any = await axios.get(url);
+      if ((res as string).indexOf('@keyframes') !== -1) {
+        //有动画的svg
+        return true;
+      } else {
+        return false;
+      }
+    // } else {
+    //   return false;
+    // }
+  } else {
+    return url.endsWith('.gif');
+  }
 }
 
 /**

+ 1 - 1
src/views/components/Graphics.vue

@@ -1097,7 +1097,7 @@ 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] = isGif(item.image)
+    const [name, lockedOnCombine] = await isGif(item.image)
       ? ['gif', 0]
       : ['image', undefined];