Commit 823fc252 by qlintonger xeno

feat: 新增data-key赋值设定+1

parent 07b9bd4e
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { TreeRenderResult } from '@/lib/XMLProcessor/src/typing'; import { TreeRenderResult } from '@/lib/XMLProcessor/src/typing';
// 引入 UUID 类用于生成唯一标识符 // 引入 UUID 类用于生成唯一标识符
import { UUID } from 'uuidjs'; import { UUID } from 'uuidjs';
import { md5 } from 'js-md5'
// 定义 Processing 类,用于处理 XML 数据 // 定义 Processing 类,用于处理 XML 数据
export class Processing { export class Processing {
...@@ -20,7 +21,13 @@ export class Processing { ...@@ -20,7 +21,13 @@ export class Processing {
} }
dualCompareFromString(xmlStringA: string, xmlStringB: string, bothHandledNode: string[]) { dualCompareFromString(xmlStringA: string, xmlStringB: string, bothHandledNode: string[]) {
const treeA = this.domParser.parseFromString(xmlStringA, 'text/xml');
const treeB = this.domParser.parseFromString(xmlStringB, 'text/xml');
const resultA = this.innerHandle(treeA.documentElement, bothHandledNode);
const resultB = this.innerHandle(treeB.documentElement, bothHandledNode)
treeA.documentElement.querySelectorAll(':not([data-key])').forEach((node) => node.remove())
treeB.documentElement.querySelectorAll(':not([data-key])').forEach((node) => node.remove())
console.log('both -res', {resultA, resultB})
} }
// 处理 XML 字符串的方法,返回树形数据和 XML DOM 对象 // 处理 XML 字符串的方法,返回树形数据和 XML DOM 对象
...@@ -91,7 +98,8 @@ export class Processing { ...@@ -91,7 +98,8 @@ export class Processing {
label: domNode.nodeName, label: domNode.nodeName,
children: [], children: [],
index: 0, index: 0,
chained: [0] chained: [0],
hash: md5.hex(domNode.textContent! || '')
}; };
// 为 DOM 节点设置 data-key 属性 // 为 DOM 节点设置 data-key 属性
domNode.setAttribute('data-key', targetKey); domNode.setAttribute('data-key', targetKey);
...@@ -131,7 +139,8 @@ export class Processing { ...@@ -131,7 +139,8 @@ export class Processing {
key: targetKey, key: targetKey,
label: node.nodeName, label: node.nodeName,
index: realIndex, index: realIndex,
chained: [...startChained, realIndex] chained: [...startChained, realIndex],
hash: md5.hex(node.textContent! || '')
}; };
// 为 DOM 节点设置 data-key 属性 // 为 DOM 节点设置 data-key 属性
node.setAttribute('data-key', targetKey); node.setAttribute('data-key', targetKey);
......
import {Processing} from '@/lib/XMLProcessor/src/core/Processing.ts' import {Processing} from '@/lib/XMLProcessor/src/core/Processing.ts'
import {Plugin, getCurrentInstance} from 'vue' import {Plugin, getCurrentInstance} from 'vue'
import TextA from "@/assets/file/CES-QEC-V250-A.xml?raw"
import TextB from "@/assets/file/Trans-Convert.xml?raw"
import {nodeSet} from '@/views/editor/constants/nodeParsed.ts'
const p = new Processing() const p = new Processing()
// @ts-ignore
window.$p = function() {
p.dualCompareFromString(
TextA,
TextB,
nodeSet
)
}
export const XMLProcessing: Plugin = function(app) { export const XMLProcessing: Plugin = function(app) {
app.provide('xmlProcessing', p); app.provide('xmlProcessing', p);
} }
......
...@@ -2,7 +2,7 @@ export type TreeRenderResult = { ...@@ -2,7 +2,7 @@ export type TreeRenderResult = {
key: string, key: string,
label: string, label: string,
children?: TreeRenderResult[], children?: TreeRenderResult[],
hash?: string, hash: string,
index: number, index: number,
chained: number[] chained: number[]
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment