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
3fc454e0
Commit
3fc454e0
authored
Apr 10, 2025
by
qlintonger xeno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 使用LCS对比+1234
parent
538dc862
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
5 deletions
+48
-5
src/assets/file/Trans-Convert.xml
+0
-0
src/lib/XMLProcessor/src/core/Processing.ts
+46
-3
src/lib/XMLProcessor/src/core/dualCompare.ts
+2
-2
No files found.
src/assets/file/Trans-Convert.xml
View file @
3fc454e0
This diff is collapsed.
Click to expand it.
src/lib/XMLProcessor/src/core/Processing.ts
View file @
3fc454e0
...
@@ -3,6 +3,7 @@ import { NewTreeModification, OldTreeModification, TreeRenderResult, TreeRenderR
...
@@ -3,6 +3,7 @@ import { NewTreeModification, OldTreeModification, TreeRenderResult, TreeRenderR
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'
import
{
cloneDeep
}
from
'lodash'
// 定义 Processing 类,用于处理 XML 数据
// 定义 Processing 类,用于处理 XML 数据
export
class
Processing
{
export
class
Processing
{
...
@@ -39,6 +40,43 @@ export class Processing {
...
@@ -39,6 +40,43 @@ export class Processing {
return
resp
return
resp
}
}
private
buildTreeFromFlatted
(
flatted
:
TreeRenderResultFlatted
[],
):
TreeRenderResult
[]
{
const
result
:
TreeRenderResult
[]
=
[]
if
(
!
flatted
.
length
)
{
return
result
}
const
flattedTreeSorted
=
flatted
.
toSorted
((
a
,
b
)
=>
{
return
a
.
chained
.
length
-
b
.
chained
.
length
;
});
const
buildTree
=
(
singleItem
:
TreeRenderResultFlatted
,
flattedDataSet
:
TreeRenderResultFlatted
[])
=>
{
const
singleItemRendered
:
TreeRenderResult
=
Object
.
assign
({},
singleItem
,
{
children
:
[]});
const
currentChainedLength
=
singleItemRendered
.
chained
.
length
;
const
maxChainedLength
=
Math
.
max
(...
flattedDataSet
.
map
(
a
=>
a
.
chained
.
length
));
const
currentChainedPrefix
=
singleItemRendered
.
chained
.
join
(
'.'
);
for
(
let
i
=
currentChainedLength
+
1
;
i
<=
maxChainedLength
;
i
++
)
{
const
allSubItems
=
flattedDataSet
.
filter
(
a
=>
a
.
chained
.
length
===
i
&&
a
.
chained
.
join
(
'.'
).
startsWith
(
currentChainedPrefix
));
if
(
allSubItems
.
length
)
{
for
(
let
j
=
flattedDataSet
.
length
-
1
;
j
>=
0
;
j
--
)
{
if
(
allSubItems
.
includes
(
flattedDataSet
[
j
]))
{
flattedDataSet
.
splice
(
j
,
1
)
}
}
for
(
const
item
of
allSubItems
)
{
const
subTree
=
buildTree
(
item
,
flattedDataSet
);
singleItemRendered
.
children
?.
push
(
subTree
)
}
}
}
return
singleItemRendered
}
for
(
const
item
of
flattedTreeSorted
)
{
result
.
push
(
buildTree
(
item
,
flattedTreeSorted
))
}
return
result
}
dualCompareFromString
(
dualCompareFromString
(
xmlStringOld
:
string
,
xmlStringOld
:
string
,
xmlStringNew
:
string
,
xmlStringNew
:
string
,
...
@@ -66,13 +104,18 @@ export class Processing {
...
@@ -66,13 +104,18 @@ export class Processing {
const
results
=
dualCompare
(
resultAFlatted
,
resultBFlatted
).
filter
((
a
)
=>
a
.
type
!==
'same'
)
const
results
=
dualCompare
(
resultAFlatted
,
resultBFlatted
).
filter
((
a
)
=>
a
.
type
!==
'same'
)
console
.
log
(
'results here'
,
results
)
console
.
log
(
'after-compare'
,
results
)
// 分组构建树
const
allDeletedTree
=
results
.
filter
((
item
)
=>
item
.
type
===
'deleted'
).
map
(
a
=>
a
.
item
);
const
allAddedTree
=
results
.
filter
((
item
)
=>
item
.
type
===
'added'
).
map
(
a
=>
a
.
item
);
const
dataForOld
:
OldTreeModification
=
{
const
dataForOld
:
OldTreeModification
=
{
Deleted
:
results
.
filter
((
item
)
=>
item
.
type
===
'deleted'
).
map
((
a
)
=>
a
.
item
)
Deleted
:
this
.
buildTreeFromFlatted
(
allDeletedTree
)
}
}
const
dataForNew
:
NewTreeModification
=
{
const
dataForNew
:
NewTreeModification
=
{
Added
:
results
.
filter
((
item
)
=>
item
.
type
===
'added'
).
map
((
a
)
=>
a
.
item
)
Added
:
this
.
buildTreeFromFlatted
(
allAddedTree
)
}
}
return
{
return
{
...
...
src/lib/XMLProcessor/src/core/dualCompare.ts
View file @
3fc454e0
...
@@ -9,7 +9,7 @@ export function dualCompare(oldItems: TreeRenderResultFlatted[], newItems: TreeR
...
@@ -9,7 +9,7 @@ export function dualCompare(oldItems: TreeRenderResultFlatted[], newItems: TreeR
for
(
let
i
=
1
;
i
<=
oldItemsCount
;
i
++
)
{
for
(
let
i
=
1
;
i
<=
oldItemsCount
;
i
++
)
{
for
(
let
j
=
1
;
j
<=
newItemsCount
;
j
++
)
{
for
(
let
j
=
1
;
j
<=
newItemsCount
;
j
++
)
{
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
)
{
dp
[
i
][
j
]
=
dp
[
i
-
1
][
j
-
1
]
+
1
dp
[
i
][
j
]
=
dp
[
i
-
1
][
j
-
1
]
+
1
}
else
{
}
else
{
dp
[
i
][
j
]
=
Math
.
max
(
dp
[
i
-
1
][
j
],
dp
[
i
][
j
-
1
])
dp
[
i
][
j
]
=
Math
.
max
(
dp
[
i
-
1
][
j
],
dp
[
i
][
j
-
1
])
...
@@ -21,7 +21,7 @@ export function dualCompare(oldItems: TreeRenderResultFlatted[], newItems: TreeR
...
@@ -21,7 +21,7 @@ export function dualCompare(oldItems: TreeRenderResultFlatted[], newItems: TreeR
j
=
newItemsCount
j
=
newItemsCount
const
result
:
Array
<
{
type
:
'same'
|
'deleted'
|
'added'
|
'changedOld'
|
'changedNew'
;
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
)
{
// result.unshift({ type: 'same', item: cloneDeep(oldItems[i - 1]) })
// result.unshift({ type: 'same', item: cloneDeep(oldItems[i - 1]) })
i
--
i
--
j
--
j
--
...
...
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