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
158a36b2
Commit
158a36b2
authored
Apr 15, 2025
by
qlintonger xeno
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
8110c56b
9c7358f2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
133 deletions
+9
-133
components.d.ts
+1
-0
src/views/editor/components/Compare.vue
+3
-2
src/views/editor/constants/compare.ts
+4
-18
src/views/editor/functions/compare.ts
+1
-113
No files found.
components.d.ts
View file @
158a36b2
...
@@ -12,6 +12,7 @@ declare module 'vue' {
...
@@ -12,6 +12,7 @@ declare module 'vue' {
NButton
:
typeof
import
(
'naive-ui'
)[
'NButton'
]
NButton
:
typeof
import
(
'naive-ui'
)[
'NButton'
]
NCard
:
typeof
import
(
'naive-ui'
)[
'NCard'
]
NCard
:
typeof
import
(
'naive-ui'
)[
'NCard'
]
NConfigProvider
:
typeof
import
(
'naive-ui'
)[
'NConfigProvider'
]
NConfigProvider
:
typeof
import
(
'naive-ui'
)[
'NConfigProvider'
]
NDataTable
:
typeof
import
(
'naive-ui'
)[
'NDataTable'
]
NDropdown
:
typeof
import
(
'naive-ui'
)[
'NDropdown'
]
NDropdown
:
typeof
import
(
'naive-ui'
)[
'NDropdown'
]
NInput
:
typeof
import
(
'naive-ui'
)[
'NInput'
]
NInput
:
typeof
import
(
'naive-ui'
)[
'NInput'
]
NLayout
:
typeof
import
(
'naive-ui'
)[
'NLayout'
]
NLayout
:
typeof
import
(
'naive-ui'
)[
'NLayout'
]
...
...
src/views/editor/components/Compare.vue
View file @
158a36b2
...
@@ -33,13 +33,14 @@ import { handleScrollTopLeft, handleScrollTopRight } from '../functions/compare'
...
@@ -33,13 +33,14 @@ import { handleScrollTopLeft, handleScrollTopRight } from '../functions/compare'
</
script
>
</
script
>
<
style
lang=
"less"
>
<
style
lang=
"less"
>
[
data-modify-type
=
'removed'
]
{
[
data-modify-type
=
'removed'
]
{
background-color
:
red
;
background-color
:
var
(
--error-color-suppl
)
;
}
}
[
data-modify-type
=
'added'
]
{
[
data-modify-type
=
'added'
]
{
background-color
:
blue
;
background-color
:
var
(
--success-color-suppl
)
;
}
}
[
data-modify-type
=
'placeholder'
]
{
[
data-modify-type
=
'placeholder'
]
{
visibility
:
hidden
;
visibility
:
hidden
;
background-color
:
var
(
--warning-color-suppl
);
}
}
</
style
>
</
style
>
<
style
lang=
"less"
scoped
>
<
style
lang=
"less"
scoped
>
...
...
src/views/editor/constants/compare.ts
View file @
158a36b2
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
compareContainerRef
=
ref
()
export
const
compareContainerRef
=
ref
()
export
const
chooseRowRef
=
ref
()
export
const
chooseRowRef
=
ref
()
export
const
compareData
=
reactive
<
{
export
const
compareData
=
reactive
<
{
dataForNew
:
NewTreeModification
treeOld
:
string
dataForOld
:
OldTreeModification
treeNew
:
string
domOld
:
Document
domNew
:
Document
treeOld
:
TreeRenderResult
[]
treeNew
:
TreeRenderResult
[]
xmlContentOld
:
string
xmlContentNew
:
string
}
>
({
}
>
({
dataForNew
:
{
Added
:
[]
},
treeOld
:
''
,
dataForOld
:
{
Deleted
:
[]
},
treeNew
:
''
domOld
:
null
as
any
,
domNew
:
null
as
any
,
treeOld
:
[],
treeNew
:
[],
xmlContentOld
:
''
,
xmlContentNew
:
''
})
})
src/views/editor/functions/compare.ts
View file @
158a36b2
import
{
TreeRenderResult
}
from
'@/lib/XMLProcessor/src/typing'
import
{
chooseRowRef
,
compareContainerRef
,
compareLeftRef
,
compareRightRef
,
showCompare
}
from
'../constants/compare'
import
{
chooseRowRef
,
compareContainerRef
,
compareData
,
compareLeftRef
,
compareRightRef
,
showCompare
}
from
'../constants/compare'
import
{
uniqBy
}
from
'lodash'
export
const
handleClickDom
=
(
event
:
any
)
=>
{
export
const
handleClickDom
=
(
event
:
any
)
=>
{
if
(
!
showCompare
.
value
)
return
if
(
!
showCompare
.
value
)
return
...
@@ -22,113 +20,3 @@ export const handleScrollTopRight = (event: Event) => {
...
@@ -22,113 +20,3 @@ 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
=
()
=>
{
nextTick
(()
=>
{
const
containerLeft
=
compareLeftRef
.
value
?.
editorRef
.
getEditableContainer
()
const
containerRight
=
compareRightRef
.
value
?.
editorRef
.
getEditableContainer
()
const
Added
=
compareData
.
dataForNew
.
Added
.
map
((
item
)
=>
compareNodeAllParent
(
compareData
.
treeNew
,
item
.
key
))
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
parentPath
=
item
.
chained
.
slice
(
0
,
item
.
chained
.
length
-
1
)
const
index
=
item
.
chained
[
item
.
chained
.
length
-
1
]
const
parentData
=
findNodeByChained
(
compareData
.
treeNew
,
parentPath
)
const
parentNode
=
containerRight
!
.
querySelector
(
`[data-key="
${
parentData
?.
key
}
"]`)
if (Added.some((item) => JSON.stringify(item) === JSON.stringify(allParent))) {
//修改
const node = containerLeft!.querySelector(`[data-key="
$
{
item
.
key
}
"]`)
if (node.childNodes.length == 1 && node.childNodes[0].nodeName == 'SPAN') {
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 = () => {
nextTick(() => {
const containerLeft = compareLeftRef.value?.editorRef.getEditableContainer()
const containerRight = compareRightRef.value?.editorRef.getEditableContainer()
const Deleted = compareData.dataForOld.Deleted.map((item) => compareNodeAllParent(compareData.treeOld, item.key))
uniqBy(compareData.dataForNew.Added, 'key').map((item) => {
const allParent = compareNodeAllParent(compareData.treeNew, item.key)
const node = containerRight!.querySelector(`[data-key="
$
{
item
.
key
}
"]`)
const parentPath = item.chained.slice(0, item.chained.length - 1)
const index = item.chained[item.chained.length - 1]
const parentData = findNodeByChained(compareData.treeOld, parentPath)
const parentNode = containerLeft!.querySelector(`[data-key="
$
{
parentData
?.
key
}
"]`)
if (Deleted.some((item) => JSON.stringify(item) === JSON.stringify(allParent))) {
//修改
const node = containerRight!.querySelector(`[data-key="
$
{
item
.
key
}
"]`)
if (node.childNodes.length == 1 && node.childNodes[0].nodeName == 'SPAN') {
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 findNodeByChained = (data: TreeRenderResult[], targetChained: number[]): TreeRenderResult | null => {
const dfs = (currentNode: TreeRenderResult): TreeRenderResult | null => {
if (Array.isArray(currentNode.chained) && currentNode.chained.length === targetChained.length) {
const isMatch = currentNode.chained.every((value, index) => value === targetChained[index])
if (isMatch) {
return currentNode // 找到目标节点
}
}
if (currentNode.children && currentNode.children.length > 0) {
for (const child of currentNode.children) {
const result = dfs(child)
if (result !== null) {
return result
}
}
}
return null // 当前节点及其子节点中没有找到目标节点
}
if (!Array.isArray(data) || data.length === 0) {
return null // 数据无效
}
for (const node of data) {
const result = dfs(node)
if (result !== null) {
return result
}
}
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 || []
}
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