Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vue3_onlineEditor
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pangchong
vue3_onlineEditor
Commits
8110c56b
Commit
8110c56b
authored
Apr 15, 2025
by
qlintonger xeno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 使用diff_match_patch来对比完毕+2345
parent
0a4ed742
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
82 deletions
+25
-82
src/assets/file/Trans-Convert.xml
+1
-0
src/lib/XMLProcessor/src/core/buildTree.ts
+24
-82
No files found.
src/assets/file/Trans-Convert.xml
View file @
8110c56b
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
<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)XXXX
</TITLE>
<TITLE>
Remove the Engine's QEC(V2500-A5 series)XXXX
</TITLE>
<TITLE>
Remove the Engine's QEC(V2500-A5 series)XXXX
</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>
...
...
src/lib/XMLProcessor/src/core/buildTree.ts
View file @
8110c56b
export
function
reconstructTree
(
data
:
any
[])
{
import
{
TreeReconstructed
}
from
'@/lib/XMLProcessor/src/typing'
// Step 1: Sort data by chained array to ensure parent-child order
const
sortedData
=
[...
data
].
sort
((
a
,
b
)
=>
{
export
function
reconstructTree
(
data
:
TreeReconstructed
[]):
string
{
const
aChained
=
a
.
chained
;
const
doc
=
new
Document
()
const
bChained
=
b
.
chained
;
let
root
:
any
for
(
let
i
=
0
;
i
<
Math
.
max
(
aChained
.
length
,
bChained
.
length
);
i
++
)
{
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
const
aVal
=
aChained
[
i
]
||
0
;
if
(
i
===
0
)
{
const
bVal
=
bChained
[
i
]
||
0
;
root
=
doc
.
createElement
(
data
[
i
].
label
)
if
(
aVal
!==
bVal
)
return
aVal
-
bVal
;
root
.
setAttribute
(
'data-key'
,
data
[
i
].
key
)
}
root
.
setAttribute
(
'data-indent-level'
,
data
[
i
].
chained
.
length
.
toString
())
return
0
;
root
.
setAttribute
(
'data-w-e-type'
,
data
[
i
].
label
)
});
doc
.
appendChild
(
root
)
// Step 2: Build a map for quick lookup and to track children
const
nodeMap
=
new
Map
();
const
result
:
any
[]
=
[];
sortedData
.
forEach
(
item
=>
{
nodeMap
.
set
(
item
.
key
,
{
...
item
,
children
:
[]
});
});
// Step 3: Assign children to parents based on chained hierarchy
sortedData
.
forEach
(
item
=>
{
const
node
=
nodeMap
.
get
(
item
.
key
);
const
chained
=
item
.
chained
;
// Find the parent by looking for the closest shorter chained array
let
parent
=
null
;
for
(
let
i
=
chained
.
length
-
1
;
i
>
0
;
i
--
)
{
const
parentChained
=
chained
.
slice
(
0
,
i
);
const
parentKey
=
sortedData
.
find
(
d
=>
d
.
type
!==
'placeholder'
&&
d
.
chained
.
length
===
parentChained
.
length
&&
d
.
chained
.
every
((
val
:
any
,
idx
:
number
)
=>
val
===
parentChained
[
idx
])
)?.
key
;
if
(
parentKey
)
{
parent
=
nodeMap
.
get
(
parentKey
);
break
;
}
}
if
(
parent
)
{
parent
.
children
.
push
(
node
);
}
else
{
}
else
{
result
.
push
(
node
);
const
nv
=
doc
.
createElement
(
data
[
i
].
label
)
nv
.
setAttribute
(
'data-key'
,
data
[
i
].
key
)
nv
.
setAttribute
(
'data-indent-level'
,
data
[
i
].
chained
.
length
.
toString
())
nv
.
setAttribute
(
'data-w-e-type'
,
data
[
i
].
label
)
if
(
data
[
i
].
type
)
{
nv
.
setAttribute
(
'data-modify-type'
,
data
[
i
].
type
)
}
}
});
if
(
data
[
i
].
label
===
'PARA'
||
data
[
i
].
label
===
'TITLE'
)
{
nv
.
textContent
=
data
[
i
].
textContent
// Step 4: Convert to XML
function
createXmlNode
(
node
:
any
,
doc
:
Document
)
{
const
element
=
doc
.
createElement
(
node
.
label
);
// Set data-key attribute
element
.
setAttribute
(
'data-key'
,
node
.
key
);
// Set data-type attribute if type is not null
if
(
node
.
type
!==
null
)
{
element
.
setAttribute
(
'data-modify-type'
,
node
.
type
);
}
}
root
.
appendChild
(
nv
)
element
.
setAttribute
(
'data-w-e-type'
,
node
.
label
)
element
.
setAttribute
(
'data-indent-level'
,
node
.
chained
.
length
.
toString
())
// Set textContent for TITLE or PARA nodes
if
(
node
.
label
===
'TITLE'
||
node
.
label
===
'PARA'
)
{
element
.
textContent
=
node
.
textContent
;
}
}
// Recursively add children
node
.
children
.
forEach
((
child
:
any
)
=>
{
element
.
appendChild
(
createXmlNode
(
child
,
doc
));
});
return
element
;
}
// Create XML document
const
doc
=
new
Document
();
// Use the first element (JOBCARD) as the root if it exists
if
(
result
.
length
>
0
)
{
const
rootNode
=
createXmlNode
(
result
[
0
],
doc
)
doc
.
appendChild
(
rootNode
)
}
}
// Serialize to XML string
// Serialize to XML string
const
serializer
=
new
XMLSerializer
()
;
const
serializer
=
new
XMLSerializer
()
return
serializer
.
serializeToString
(
doc
)
;
return
serializer
.
serializeToString
(
doc
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment