Bläddra i källkod

Merge branch 'local' of https://github.com/le5le-com/visualization-design into local

ananzhusen 1 år sedan
förälder
incheckning
4d50a5c738
1 ändrade filer med 28 tillägg och 18 borttagningar
  1. 28 18
      src/views/components/Graphics.vue

+ 28 - 18
src/views/components/Graphics.vue

@@ -246,7 +246,7 @@ import { autoSave, delAttrs } from '@/services/common';
 import { debounce, throttle } from '@/services/debouce';
 import { searchObjectPinyin } from '@/services/pinyin';
 import { getCookie } from '@/services/cookie';
-
+import { parseSvg } from '@meta2d/svg'
 import WechatPay from './WechatPay.vue';
 import { filename } from '@/services/file';
 import { useUser } from '@/services/user';
@@ -1022,29 +1022,39 @@ const beforeUpload = (file: any) => {
 };
 
 const fileSuccessed = async (content: any) => {
+  let file = content.file.raw
   const c: any = {
     name: filename(content.file.name),
     image: content.response.url,
     folder: uploadGroup.name === '我的组件' ? '' : uploadGroup.name,
   };
-
-  const ret: any = await addCollection('le5leV-components', c);
-
-  if (ret && uploadGroup.name !== '我的组件') {
-    c._id = ret._id || ret.id;
-    if (!uploadGroup.list) {
-      uploadGroup.list = [];
-    }
-    uploadGroup.list.push(c);
-    await axios.post('/api/data/folders/update', {
-      _id: uploadGroup._id || uploadGroup.id,
-      list: uploadGroup.list,
-    });
-  } else {
-    if (!uploadGroup.list) {
-      uploadGroup.list = [];
+  // 若是svg格式 则开启解析
+  if(content.file.name.endsWith('.svg')){
+    let fileReader = new FileReader()
+    fileReader.readAsText(file)
+    fileReader.onload = async ()=>{
+      let svgText = fileReader.result
+      c.componentDatas =  parseSvg(svgText as string)
+      c.component = true
+      const ret: any = await addCollection('le5leV-components', c);
+
+      if (ret && uploadGroup.name !== '我的组件') {
+        c._id = ret._id || ret.id;
+        if (!uploadGroup.list) {
+          uploadGroup.list = [];
+        }
+        uploadGroup.list.push(c);
+        await axios.post('/api/data/folders/update', {
+          _id: uploadGroup._id || uploadGroup.id,
+          list: uploadGroup.list,
+        });
+      } else {
+        if (!uploadGroup.list) {
+          uploadGroup.list = [];
+        }
+        uploadGroup.list.push(c);
+      }
     }
-    uploadGroup.list.push(c);
   }
 };