Commit a3e85107 by qlintonger xeno

feat: 使用LCS对比+12

parent cde83139
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
<CEP> <CEP>
<EFFECT EFFRG="001999"></EFFECT> <EFFECT EFFRG="001999"></EFFECT>
<TITLEC>发动机QEC拆卸(V2500-A5系列)</TITLEC> <TITLEC>发动机QEC拆卸(V2500-A5系列)</TITLEC>
<TITLE>Remove the Engine's QEC(V2500-A5 series)XXXX</TITLE> <TITLE>Remove the Engine's QEC(V2500-A5 series)xxx</TITLE>
<TITLE>Remove the Engine's QEC(V2500-A5 series)XXXX</TITLE>
<TOPIC CK-LEVEL="C"> <TOPIC CK-LEVEL="C">
<TITLEC>飞机/发动机基本信息</TITLEC> <TITLEC>飞机/发动机基本信息</TITLEC>
<TITLE>AIRCRAFT/ENGINE INFORMATION</TITLE> <TITLE>AIRCRAFT/ENGINE INFORMATION</TITLE>
......
// 引入 TreeRenderResult 类型,该类型定义在 @/lib/XMLProcessor/src/typing 模块中 // 引入 TreeRenderResult 类型,该类型定义在 @/lib/XMLProcessor/src/typing 模块中
import { NewTreeModification, OldTreeModification, TreeRenderResult, TreeRenderResultFlatted } from '@/lib/XMLProcessor/src/typing' import { NewTreeModification, OldTreeModification, TreeRenderResult, TreeRenderResultFlatted } from '@/lib/XMLProcessor/src/typing'
import { md5 } from 'js-md5' import { md5 } from 'js-md5'
import {getUUID} from '../utils/uuid.ts' import { getUUID } from '../utils/uuid.ts'
import {dualCompare} from '@/lib/XMLProcessor/src/core/dualCompare.ts' import { dualCompare } from '@/lib/XMLProcessor/src/core/dualCompare.ts'
// 定义 Processing 类,用于处理 XML 数据 // 定义 Processing 类,用于处理 XML 数据
export class Processing { export class Processing {
...@@ -60,23 +60,32 @@ export class Processing { ...@@ -60,23 +60,32 @@ export class Processing {
treeA.documentElement.querySelectorAll(':not([data-key])').forEach((node) => node.remove()) treeA.documentElement.querySelectorAll(':not([data-key])').forEach((node) => node.remove())
treeB.documentElement.querySelectorAll(':not([data-key])').forEach((node) => node.remove()) treeB.documentElement.querySelectorAll(':not([data-key])').forEach((node) => node.remove())
// 扁平化所有节点 // 扁平化所有节点
const resultAFlatted = this.flattenTree(resultA).filter((item) => { const resultAFlatted = this.flattenTree(resultA)
.filter((item) => {
return contentHoldNode.includes(item.label) return contentHoldNode.includes(item.label)
}) })
const resultBFlatted = this.flattenTree(resultB).filter((item) => { .map((item, index) => ({
...item,
index
}))
const resultBFlatted = this.flattenTree(resultB)
.filter((item) => {
return contentHoldNode.includes(item.label) return contentHoldNode.includes(item.label)
}) })
.map((item, index) => ({
...item,
index
}))
const results = dualCompare(resultAFlatted, resultBFlatted) const results = dualCompare(resultAFlatted, resultBFlatted).filter((a) => a.type !== 'same')
.filter(a=>a.type !=='same');
console.log('results here', results) console.log('results here', results)
const dataForOld: OldTreeModification = { const dataForOld: OldTreeModification = {
Deleted: results.filter(item => item.type === 'deleted').map(a=>a.item) Deleted: results.filter((item) => item.type === 'deleted').map((a) => a.item)
} }
const dataForNew: NewTreeModification = { const dataForNew: NewTreeModification = {
Added: results.filter(item => item.type === 'added').map(a=>a.item) Added: results.filter((item) => item.type === 'added').map((a) => a.item)
} }
return { return {
...@@ -88,7 +97,7 @@ export class Processing { ...@@ -88,7 +97,7 @@ export class Processing {
treeNew: resultB, treeNew: resultB,
xmlContentOld: this.serializeXML(treeA), xmlContentOld: this.serializeXML(treeA),
xmlContentNew: this.serializeXML(treeB) xmlContentNew: this.serializeXML(treeB)
}; }
} }
// 处理 XML 字符串的方法,返回树形数据和 XML DOM 对象 // 处理 XML 字符串的方法,返回树形数据和 XML DOM 对象
......
...@@ -5,6 +5,8 @@ export function dualCompare(oldItems: TreeRenderResultFlatted[], newItems: TreeR ...@@ -5,6 +5,8 @@ export function dualCompare(oldItems: TreeRenderResultFlatted[], newItems: TreeR
const oldItemsCount = oldItems.length const oldItemsCount = oldItems.length
const newItemsCount = newItems.length const newItemsCount = newItems.length
console.log('old and new', { oldItems, newItems })
const dp: number[][] = Array.from({ length: oldItemsCount + 1 }, () => Array(newItemsCount + 1).fill(0)) const dp: number[][] = Array.from({ length: oldItemsCount + 1 }, () => Array(newItemsCount + 1).fill(0))
for (let i = 1; i <= oldItemsCount; i++) { for (let i = 1; i <= oldItemsCount; i++) {
...@@ -19,10 +21,10 @@ export function dualCompare(oldItems: TreeRenderResultFlatted[], newItems: TreeR ...@@ -19,10 +21,10 @@ export function dualCompare(oldItems: TreeRenderResultFlatted[], newItems: TreeR
let i = oldItemsCount, let i = oldItemsCount,
j = newItemsCount j = newItemsCount
const result: Array<{ type: 'same' | 'deleted' | 'added'; item: TreeRenderResultFlatted }> = [] const result: Array<{ type: 'same' | 'deleted' | 'added' | 'changedOld' | 'changedNew'; item: TreeRenderResultFlatted }> = []
while (i > 0 && j > 0) { while (i > 0 && j > 0) {
if (oldItems[i - 1].hash === newItems[j - 1].hash && oldItems[i - 1].label === newItems[j - 1].label) { if (oldItems[i - 1].hash === newItems[j - 1].hash && oldItems[i - 1].label === newItems[j - 1].label) {
result.unshift({ type: 'same', item: cloneDeep(oldItems[i - 1]) }) // result.unshift({ type: 'same', item: cloneDeep(oldItems[i - 1]) })
i-- i--
j-- j--
} else if (dp[i - 1][j] > dp[i][j - 1]) { } else if (dp[i - 1][j] > dp[i][j - 1]) {
......
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