|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import { getUUID } from "."
|
|
|
|
|
import { deepClone, getUUID } from "."
|
|
|
|
|
import { ElementType, IElement } from ".."
|
|
|
|
|
import { ZERO } from "../dataset/constant/Common"
|
|
|
|
|
import { EDITOR_ELEMENT_ZIP_ATTR } from "../dataset/constant/Element"
|
|
|
|
|
|
|
|
|
|
export function formatElementList(elementList: IElement[]) {
|
|
|
|
|
if (elementList[0]?.value !== ZERO) {
|
|
|
|
|
@ -60,3 +61,69 @@ export function formatElementList(elementList: IElement[]) {
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function zipElementList(payload: IElement[]): IElement[] {
|
|
|
|
|
const elementList = deepClone(payload)
|
|
|
|
|
const zipElementListData: IElement[] = []
|
|
|
|
|
let e = 0
|
|
|
|
|
while (e < elementList.length) {
|
|
|
|
|
let element = elementList[e]
|
|
|
|
|
// 筛选所需项
|
|
|
|
|
if (e === 0 && element.value === ZERO) {
|
|
|
|
|
e++
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
// 表格处理
|
|
|
|
|
if (element.type === ElementType.TABLE) {
|
|
|
|
|
if (element.trList) {
|
|
|
|
|
for (let t = 0; t < element.trList.length; t++) {
|
|
|
|
|
const tr = element.trList[t]
|
|
|
|
|
delete tr.id
|
|
|
|
|
for (let d = 0; d < tr.tdList.length; d++) {
|
|
|
|
|
const td = tr.tdList[d]
|
|
|
|
|
tr.tdList[d] = {
|
|
|
|
|
colspan: td.colspan,
|
|
|
|
|
rowspan: td.rowspan,
|
|
|
|
|
value: zipElementList(td.value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (element.type === ElementType.HYPERLINK) {
|
|
|
|
|
// 超链接处理
|
|
|
|
|
const hyperlinkId = element.hyperlinkId
|
|
|
|
|
const hyperlinkElement: IElement = {
|
|
|
|
|
type: ElementType.HYPERLINK,
|
|
|
|
|
value: '',
|
|
|
|
|
url: element.url
|
|
|
|
|
}
|
|
|
|
|
const valueList: IElement[] = []
|
|
|
|
|
while (e < elementList.length) {
|
|
|
|
|
const hyperlinkE = elementList[e]
|
|
|
|
|
if (hyperlinkId !== hyperlinkE.hyperlinkId) {
|
|
|
|
|
e--
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
delete hyperlinkE.type
|
|
|
|
|
delete hyperlinkE.url
|
|
|
|
|
valueList.push(hyperlinkE)
|
|
|
|
|
e++
|
|
|
|
|
}
|
|
|
|
|
hyperlinkElement.valueList = zipElementList(valueList)
|
|
|
|
|
element = hyperlinkElement
|
|
|
|
|
}
|
|
|
|
|
// 压缩保留字段
|
|
|
|
|
const newElement: IElement = {
|
|
|
|
|
value: element.value === ZERO ? `\n` : element.value,
|
|
|
|
|
}
|
|
|
|
|
EDITOR_ELEMENT_ZIP_ATTR.forEach(attr => {
|
|
|
|
|
const value = element[attr] as never
|
|
|
|
|
if (value !== undefined) {
|
|
|
|
|
newElement[attr] = value
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
zipElementListData.push(newElement)
|
|
|
|
|
e++
|
|
|
|
|
}
|
|
|
|
|
return zipElementListData
|
|
|
|
|
}
|
|
|
|
|
|