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
1838dc67
Commit
1838dc67
authored
Apr 11, 2025
by
pangchong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 对比调整
parent
2e72ee26
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
49 deletions
+80
-49
src/assets/file/Trans-Convert.xml
+0
-0
src/views/editor/components/Compare.vue
+3
-11
src/views/editor/constants/compare.ts
+21
-2
src/views/editor/functions/compare.ts
+52
-30
src/views/editor/functions/index.ts
+4
-6
No files found.
src/assets/file/Trans-Convert.xml
View file @
1838dc67
This diff is collapsed.
Click to expand it.
src/views/editor/components/Compare.vue
View file @
1838dc67
...
@@ -11,14 +11,14 @@
...
@@ -11,14 +11,14 @@
<div
class=
"choose-row bg-progressRailColor"
ref=
"chooseRowRef"
></div>
<div
class=
"choose-row bg-progressRailColor"
ref=
"chooseRowRef"
></div>
<GlobalEditor
<GlobalEditor
ref=
"compareLeftRef"
ref=
"compareLeftRef"
v-model=
"compare
LeftData
"
v-model=
"compare
Data.xmlContentOld
"
editorId=
"compareLeft"
editorId=
"compareLeft"
:editorConfig=
"
{ readOnly: true }"
:editorConfig=
"
{ readOnly: true }"
@handleScrollTop="handleScrollTopLeft"
@handleScrollTop="handleScrollTopLeft"
/>
/>
<GlobalEditor
<GlobalEditor
ref=
"compareRightRef"
ref=
"compareRightRef"
v-model=
"compare
RightData
"
v-model=
"compare
Data.xmlContentNew
"
editorId=
"compareRight"
editorId=
"compareRight"
:editorConfig=
"
{ readOnly: true }"
:editorConfig=
"
{ readOnly: true }"
@handleScrollTop="handleScrollTopRight"
@handleScrollTop="handleScrollTopRight"
...
@@ -28,15 +28,7 @@
...
@@ -28,15 +28,7 @@
</
template
>
</
template
>
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
import
{
showCompare
,
compareLeftRef
,
compareRightRef
,
compareContainerRef
,
chooseRowRef
,
compareData
}
from
'../constants/compare'
showCompare
,
compareLeftRef
,
compareRightRef
,
compareLeftData
,
compareRightData
,
compareContainerRef
,
chooseRowRef
}
from
'../constants/compare'
import
{
handleScrollTopLeft
,
handleScrollTopRight
}
from
'../functions/compare'
import
{
handleScrollTopLeft
,
handleScrollTopRight
}
from
'../functions/compare'
</
script
>
</
script
>
<
style
lang=
"less"
scoped
>
<
style
lang=
"less"
scoped
>
...
...
src/views/editor/constants/compare.ts
View file @
1838dc67
import
{
NewTreeModification
,
OldTreeModification
,
TreeRenderResult
}
from
'@/lib/XMLProcessor/src/typing'
export
const
showCompare
=
ref
(
false
)
export
const
showCompare
=
ref
(
false
)
export
const
compareLeftRef
=
ref
()
export
const
compareLeftRef
=
ref
()
export
const
compareRightRef
=
ref
()
export
const
compareRightRef
=
ref
()
export
const
compareLeftData
=
ref
(
''
)
export
const
compareRightData
=
ref
(
''
)
export
const
compareContainerRef
=
ref
()
export
const
compareContainerRef
=
ref
()
export
const
chooseRowRef
=
ref
()
export
const
chooseRowRef
=
ref
()
export
const
compareData
=
reactive
<
{
dataForNew
:
NewTreeModification
dataForOld
:
OldTreeModification
domOld
:
Document
domNew
:
Document
treeOld
:
TreeRenderResult
[]
treeNew
:
TreeRenderResult
[]
xmlContentOld
:
string
xmlContentNew
:
string
}
>
({
dataForNew
:
{
Added
:
[]
},
dataForOld
:
{
Deleted
:
[]
},
domOld
:
null
as
any
,
domNew
:
null
as
any
,
treeOld
:
[],
treeNew
:
[],
xmlContentOld
:
''
,
xmlContentNew
:
''
})
src/views/editor/functions/compare.ts
View file @
1838dc67
import
{
NewTreeModification
,
OldTreeModification
,
TreeRenderResult
}
from
'@/lib/XMLProcessor/src/typing'
import
{
TreeRenderResult
}
from
'@/lib/XMLProcessor/src/typing'
import
{
chooseRowRef
,
compareContainerRef
,
compareLeftRef
,
compareRightRef
,
showCompare
}
from
'../constants/compare'
import
{
chooseRowRef
,
compareContainerRef
,
compare
Data
,
compare
LeftRef
,
compareRightRef
,
showCompare
}
from
'../constants/compare'
import
{
uniqBy
}
from
'lodash'
import
{
uniqBy
}
from
'lodash'
export
const
handleClickDom
=
(
event
:
any
)
=>
{
export
const
handleClickDom
=
(
event
:
any
)
=>
{
...
@@ -22,61 +22,65 @@ export const handleScrollTopRight = (event: Event) => {
...
@@ -22,61 +22,65 @@ export const handleScrollTopRight = (event: Event) => {
compareLeftRef
.
value
?.
handleScrollTop
(
scrollTop
)
compareLeftRef
.
value
?.
handleScrollTop
(
scrollTop
)
chooseRowRef
.
value
.
style
.
height
=
'0px'
chooseRowRef
.
value
.
style
.
height
=
'0px'
}
}
export
const
handleLeftDifferent
=
(
dataForOld
:
OldTreeModification
,
treeNew
:
TreeRenderResult
[]
)
=>
{
export
const
handleLeftDifferent
=
()
=>
{
nextTick
(()
=>
{
nextTick
(()
=>
{
const
containerLeft
=
compareLeftRef
.
value
?.
editorRef
.
getEditableContainer
()
const
containerLeft
=
compareLeftRef
.
value
?.
editorRef
.
getEditableContainer
()
const
containerRight
=
compareRightRef
.
value
?.
editorRef
.
getEditableContainer
()
const
containerRight
=
compareRightRef
.
value
?.
editorRef
.
getEditableContainer
()
//新增
const
Added
=
compareData
.
dataForNew
.
Added
.
map
((
item
)
=>
compareNodeAllParent
(
compareData
.
treeNew
,
item
.
key
))
uniqBy
(
dataForOld
.
Deleted
,
'key'
).
map
((
item
:
any
)
=>
{
uniqBy
(
compareData
.
dataForOld
.
Deleted
,
'key'
).
map
((
item
:
any
)
=>
{
debugger
const
allParent
=
compareNodeAllParent
(
compareData
.
treeOld
,
item
.
key
)
const
node
=
containerLeft
!
.
querySelector
(
`[data-key="
${
item
.
key
}
"]`
)
const
node
=
containerLeft
!
.
querySelector
(
`[data-key="
${
item
.
key
}
"]`
)
//处理左边
node
.
classList
.
add
(
'bg-errorColorSuppl'
)
//处理右边
const
parentPath
=
item
.
chained
.
slice
(
0
,
item
.
chained
.
length
-
1
)
const
parentPath
=
item
.
chained
.
slice
(
0
,
item
.
chained
.
length
-
1
)
const
index
=
item
.
chained
[
item
.
chained
.
length
-
1
]
const
index
=
item
.
chained
[
item
.
chained
.
length
-
1
]
const
parentData
=
findNodeByChained
(
treeNew
,
parentPath
)
const
parentData
=
findNodeByChained
(
compareData
.
treeNew
,
parentPath
)
const
parentNode
=
containerRight
!
.
querySelector
(
`[data-key="
${
parentData
?.
key
}
"]`)
const
parentNode
=
containerRight
!
.
querySelector
(
`[data-key="
${
parentData
?.
key
}
"]`)
// 创建一个新节点
if (Added.some((item) => JSON.stringify(item) === JSON.stringify(allParent))) {
const newDiv = document.createElement('div')
newDiv.style.height = `${node.offsetHeight}px`
newDiv.classList.add('bg-dividerColor')
parentNode && parentNode.insertBefore(newDiv, parentNode.childNodes[index])
})
//修改
//修改
dataForOld.Changed.map((item) => {
const node = containerLeft!.querySelector(`[data-key="
$
{
item
.
key
}
"]`)
const node = containerLeft!.querySelector(`[data-key="
$
{
item
.
key
}
"]`)
if (node.childNodes.length == 1 && node.childNodes[0].nodeName == 'SPAN') {
if (node.childNodes.length == 1 && node.childNodes[0].nodeName == 'SPAN') {
node.classList.add('bg-warningColorSuppl')
node.classList.add('bg-warningColorSuppl')
}
}
} else {
//处理左边
node.classList.add('bg-errorColorSuppl')
//处理右边
const newDiv = document.createElement('div')
newDiv.style.height = `${node.offsetHeight}px`
newDiv.classList.add('bg-dividerColor')
parentNode && parentNode.insertBefore(newDiv, parentNode.childNodes[index])
}
})
})
})
})
}
}
export const handleRightDifferent = (
dataForNew: NewTreeModification, treeOld: TreeRenderResult[]
) => {
export const handleRightDifferent = () => {
nextTick(() => {
nextTick(() => {
const containerLeft = compareLeftRef.value?.editorRef.getEditableContainer()
const containerLeft = compareLeftRef.value?.editorRef.getEditableContainer()
const containerRight = compareRightRef.value?.editorRef.getEditableContainer()
const containerRight = compareRightRef.value?.editorRef.getEditableContainer()
//新增
const Deleted = compareData.dataForOld.Deleted.map((item) => compareNodeAllParent(compareData.treeOld, item.key))
uniqBy(dataForNew.Added, 'key').map((item: any) => {
uniqBy(compareData.dataForNew.Added, 'key').map((item) => {
const allParent = compareNodeAllParent(compareData.treeNew, item.key)
const node = containerRight!.querySelector(`[data-key="
$
{
item
.
key
}
"]`)
const node = containerRight!.querySelector(`[data-key="
$
{
item
.
key
}
"]`)
//处理右边
node.classList.add('bg-errorColorSuppl')
//处理左边
const parentPath = item.chained.slice(0, item.chained.length - 1)
const parentPath = item.chained.slice(0, item.chained.length - 1)
const index = item.chained[item.chained.length - 1]
const index = item.chained[item.chained.length - 1]
const parentData = findNodeByChained(treeOld, parentPath)
const parentData = findNodeByChained(
compareData.
treeOld, parentPath)
const parentNode = containerLeft!.querySelector(`[data-key="
$
{
parentData
?.
key
}
"]`)
const parentNode = containerLeft!.querySelector(`[data-key="
$
{
parentData
?.
key
}
"]`)
// 创建一个新节点
if (Deleted.some((item) => JSON.stringify(item) === JSON.stringify(allParent))) {
const newDiv = document.createElement('div')
newDiv.style.height = `${node.offsetHeight}px`
newDiv.classList.add('bg-dividerColor')
parentNode && parentNode.insertBefore(newDiv, parentNode.childNodes[index])
})
//修改
//修改
dataForNew.Changed.map((item: any) => {
const node = containerRight!.querySelector(`[data-key="
$
{
item
.
key
}
"]`)
const node = containerRight!.querySelector(`[data-key="
$
{
item
.
key
}
"]`)
if (node.childNodes.length == 1 && node.childNodes[0].nodeName == 'SPAN') {
if (node.childNodes.length == 1 && node.childNodes[0].nodeName == 'SPAN') {
node.classList.add('bg-warningColorSuppl')
node.classList.add('bg-warningColorSuppl')
}
}
} else {
//新增
//处理右边
node.classList.add('bg-errorColorSuppl')
//处理左边
const newDiv = document.createElement('div')
newDiv.style.height = `${node.offsetHeight}px`
newDiv.classList.add('bg-dividerColor')
parentNode && parentNode.insertBefore(newDiv, parentNode.childNodes[index])
}
})
})
})
})
}
}
...
@@ -110,3 +114,21 @@ export const findNodeByChained = (data: TreeRenderResult[], targetChained: numbe
...
@@ -110,3 +114,21 @@ export const findNodeByChained = (data: TreeRenderResult[], targetChained: numbe
}
}
return null // 没有找到目标节点
return null // 没有找到目标节点
}
}
//根据节点的key获取所有父节点的集合
export const compareNodeAllParent = (root: TreeRenderResult[], key: string) => {
function traverse(node: TreeRenderResult, currentPath: string[]): string[] | null {
currentPath.push(node.label)
if (node.key === key) {
return [...currentPath]
}
if (node.children) {
for (const child of node.children) {
const result = traverse(child, [...currentPath])
if (result) return result
}
}
return null
}
const result = traverse(root[0], [])
return result || []
}
src/views/editor/functions/index.ts
View file @
1838dc67
...
@@ -3,7 +3,7 @@ import { IDomEditor } from '@wangeditor/editor'
...
@@ -3,7 +3,7 @@ import { IDomEditor } from '@wangeditor/editor'
import
{
treeData
,
treeRef
,
treeSelectedKeys
}
from
'../constants/tree'
import
{
treeData
,
treeRef
,
treeSelectedKeys
}
from
'../constants/tree'
import
{
dropdownConfig
,
editorRef
,
editorHtml
}
from
'../constants'
import
{
dropdownConfig
,
editorRef
,
editorHtml
}
from
'../constants'
import
{
getUUID
}
from
'@/utils'
import
{
getUUID
}
from
'@/utils'
import
{
compare
LeftData
,
compareRight
Data
,
showCompare
}
from
'../constants/compare'
import
{
compareData
,
showCompare
}
from
'../constants/compare'
import
TextA
from
'@/assets/file/CES-QEC-V250-A.xml?raw'
import
TextA
from
'@/assets/file/CES-QEC-V250-A.xml?raw'
import
TextB
from
'@/assets/file/Trans-Convert.xml?raw'
import
TextB
from
'@/assets/file/Trans-Convert.xml?raw'
import
{
nodeSet
,
contentHoldNode
}
from
'@/configs/node.config'
import
{
nodeSet
,
contentHoldNode
}
from
'@/configs/node.config'
...
@@ -102,10 +102,8 @@ export const compareXml = () => {
...
@@ -102,10 +102,8 @@ export const compareXml = () => {
const
xmlProcessing
=
useXMLProcessing
()
const
xmlProcessing
=
useXMLProcessing
()
const
res
=
xmlProcessing
.
dualCompareFromString
(
TextA
,
TextB
,
nodeSet
,
contentHoldNode
)
const
res
=
xmlProcessing
.
dualCompareFromString
(
TextA
,
TextB
,
nodeSet
,
contentHoldNode
)
console
.
log
(
res
)
console
.
log
(
res
)
//渲染数据
Object
.
assign
(
compareData
,
res
)
compareLeftData
.
value
=
res
.
xmlContentOld
compareRightData
.
value
=
res
.
xmlContentNew
//比较数据
//比较数据
handleLeftDifferent
(
res
.
dataForOld
,
res
.
treeNew
)
handleLeftDifferent
()
handleRightDifferent
(
res
.
dataForNew
,
res
.
treeOld
)
handleRightDifferent
()
}
}
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