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
23f3b31b
Commit
23f3b31b
authored
Apr 16, 2025
by
qlintonger xeno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 额外设置内容
parent
67fbd5eb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
29 deletions
+43
-29
src/lib/XMLProcessor/src/core/Processing.ts
+2
-2
src/lib/XMLProcessor/src/core/buildTree.ts
+41
-27
No files found.
src/lib/XMLProcessor/src/core/Processing.ts
View file @
23f3b31b
...
...
@@ -245,8 +245,8 @@ export class Processing {
}
}
}
const
treeOld
=
reconstructTree
(
constructNodeA
)
const
treeNew
=
reconstructTree
(
constructNodeB
)
const
treeOld
=
reconstructTree
(
constructNodeA
,
contentHoldNode
)
const
treeNew
=
reconstructTree
(
constructNodeB
,
contentHoldNode
)
console
.
log
(
'the resp'
,
{
constructNodeA
,
constructNodeB
})
return
{
treeOld
,
treeNew
...
...
src/lib/XMLProcessor/src/core/buildTree.ts
View file @
23f3b31b
import
{
TreeReconstructed
}
from
'@/lib/XMLProcessor/src/typing'
function
createNodeFormDataItem
(
current
:
any
,
d
:
Document
,
contentHoldNode
:
string
[])
{
let
rootNode
=
d
.
createElement
(
current
.
label
);
rootNode
.
setAttribute
(
'data-key'
,
current
.
key
);
rootNode
.
setAttribute
(
'data-indent-level'
,
current
.
chained
.
length
.
toString
());
rootNode
.
setAttribute
(
'data-w-e-type'
,
current
.
label
);
if
(
current
.
type
)
{
rootNode
.
setAttribute
(
'data-modify-type'
,
current
.
type
);
}
if
(
contentHoldNode
.
includes
(
current
.
label
))
{
rootNode
.
textContent
=
current
.
textContent
;
}
return
rootNode
}
export
function
reconstructTree
(
data
:
TreeReconstructed
[]):
string
{
const
doc
=
new
Document
()
let
root
:
any
export
function
reconstructTree
(
data
:
any
[],
contentHoldNode
:
string
[])
{
const
d
=
new
Document
();
let
rootNode
:
any
=
null
;
const
nodeMap
=
new
Map
<
string
,
any
>
();
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
if
(
i
===
0
)
{
root
=
doc
.
createElement
(
data
[
i
].
label
)
root
.
setAttribute
(
'data-key'
,
data
[
i
].
key
)
root
.
setAttribute
(
'data-indent-level'
,
data
[
i
].
chained
.
length
.
toString
())
root
.
setAttribute
(
'data-w-e-type'
,
data
[
i
].
label
)
doc
.
appendChild
(
root
)
const
current
=
data
[
i
];
if
(
!
rootNode
)
{
rootNode
=
createNodeFormDataItem
(
current
,
d
,
contentHoldNode
)
nodeMap
.
set
(
current
.
key
,
rootNode
)
d
.
appendChild
(
rootNode
);
}
else
{
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
console
.
log
(
'indent-here'
,
data
[
i
].
chained
.
length
)
const
previousNode
=
data
[
i
-
1
];
// 截取至当前节点的结合
const
nodeSetUntilNow
=
data
.
slice
(
0
,
i
+
1
);
if
(
previousNode
.
chained
.
length
<
current
.
chained
.
length
)
{
// 把上一个节点视为parent即可
const
parentNode
=
nodeMap
.
get
(
previousNode
.
key
)
!
;
const
currentNode
=
createNodeFormDataItem
(
current
,
d
,
contentHoldNode
);
parentNode
.
appendChild
(
currentNode
);
nodeMap
.
set
(
current
.
key
,
currentNode
);
}
else
{
nv
.
textContent
=
' '
nv
.
setAttribute
(
'data-modify-type'
,
'null-blank'
)
// 找到离自己最近的上层节点
const
parentItem
=
nodeSetUntilNow
.
findLast
((
node
)
=>
{
return
node
.
chained
.
length
===
current
.
chained
.
length
-
1
;
})
!
;
const
parentNode
=
nodeMap
.
get
(
parentItem
.
key
)
!
;
const
currentNode
=
createNodeFormDataItem
(
current
,
d
,
contentHoldNode
);
parentNode
.
appendChild
(
currentNode
);
nodeMap
.
set
(
current
.
key
,
currentNode
);
}
root
.
appendChild
(
nv
)
}
}
// Serialize to XML string
const
serializer
=
new
XMLSerializer
()
return
serializer
.
serializeToString
(
doc
)
return
new
XMLSerializer
().
serializeToString
(
d
)
}
\ 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