Ver Fonte

feat: JSON和XMl相互转换

Gaokun Wang há 1 semana atrás
pai
commit
a7191294c0
3 ficheiros alterados com 40 adições e 1 exclusões
  1. 31 0
      package-lock.json
  2. 1 0
      package.json
  3. 8 1
      src/views/components/ToolBar/index.vue

+ 31 - 0
package-lock.json

@@ -20,6 +20,7 @@
         "axios": "^1.11.0",
         "electron-updater": "^6.6.2",
         "element-plus": "^2.10.4",
+        "fast-xml-parser": "^5.2.5",
         "insert-css": "^2.0.0",
         "nprogress": "^0.2.0",
         "pinia": "^3.0.3",
@@ -5284,6 +5285,24 @@
       "dev": true,
       "license": "MIT"
     },
+    "node_modules/fast-xml-parser": {
+      "version": "5.2.5",
+      "resolved": "https://registry.npmmirror.com/fast-xml-parser/-/fast-xml-parser-5.2.5.tgz",
+      "integrity": "sha512-pfX9uG9Ki0yekDHx2SiuRIyFdyAr1kMIMitPvb0YBo8SUfKvia7w7FIyd/l6av85pFYRhZscS75MwMnbvY+hcQ==",
+      "funding": [
+        {
+          "type": "github",
+          "url": "https://github.com/sponsors/NaturalIntelligence"
+        }
+      ],
+      "license": "MIT",
+      "dependencies": {
+        "strnum": "^2.1.0"
+      },
+      "bin": {
+        "fxparser": "src/cli/cli.js"
+      }
+    },
     "node_modules/fastq": {
       "version": "1.19.1",
       "resolved": "https://registry.npmmirror.com/fastq/-/fastq-1.19.1.tgz",
@@ -9475,6 +9494,18 @@
       "dev": true,
       "license": "MIT"
     },
+    "node_modules/strnum": {
+      "version": "2.1.1",
+      "resolved": "https://registry.npmmirror.com/strnum/-/strnum-2.1.1.tgz",
+      "integrity": "sha512-7ZvoFTiCnGxBtDqJ//Cu6fWtZtc7Y3x+QOirG15wztbdngGSkht27o2pyGWrVy0b4WAy3jbKmnoK6g5VlVNUUw==",
+      "funding": [
+        {
+          "type": "github",
+          "url": "https://github.com/sponsors/NaturalIntelligence"
+        }
+      ],
+      "license": "MIT"
+    },
     "node_modules/sumchecker": {
       "version": "3.0.1",
       "resolved": "https://registry.npmmirror.com/sumchecker/-/sumchecker-3.0.1.tgz",

+ 1 - 0
package.json

@@ -32,6 +32,7 @@
     "axios": "^1.11.0",
     "electron-updater": "^6.6.2",
     "element-plus": "^2.10.4",
+    "fast-xml-parser": "^5.2.5",
     "insert-css": "^2.0.0",
     "nprogress": "^0.2.0",
     "pinia": "^3.0.3",

+ 8 - 1
src/views/components/ToolBar/index.vue

@@ -71,7 +71,9 @@
 import FlowGraph from '../../graph'
 import { DataUri } from '@antv/x6'
 import { ref } from 'vue'
-
+import { XMLBuilder, XMLParser } from 'fast-xml-parser'
+const builder = new XMLBuilder()
+const parser = new XMLParser()
 const { graph } = FlowGraph
 const { history } = graph
 
@@ -193,6 +195,11 @@ function handleClick(event: Event) {
       console.log(graph.toJSON())
       window.localStorage.setItem('graphJson', JSON.stringify(graph.toJSON()))
       // graph.fromJSON({cells:[graph.toJSON().cells[0],graph.toJSON().cells[1]]})
+      const xmlContent = builder.build(graph.toJSON())
+      window.localStorage.setItem('graphXML', xmlContent)
+      // 解析 XML
+      const jsonObj = parser.parse(xmlContent)
+      window.localStorage.setItem('jsonObj', JSON.stringify(jsonObj))
       break
     default:
       break