|
|
|
|
@ -40,7 +40,60 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme
|
|
|
|
|
let i = 0
|
|
|
|
|
while (i < elementList.length) {
|
|
|
|
|
let el = elementList[i]
|
|
|
|
|
if (el.type === ElementType.TABLE) {
|
|
|
|
|
// 优先处理虚拟元素
|
|
|
|
|
if (el.type === ElementType.TITLE) {
|
|
|
|
|
// 移除父节点
|
|
|
|
|
elementList.splice(i, 1)
|
|
|
|
|
// 格式化元素
|
|
|
|
|
const valueList = el.valueList || []
|
|
|
|
|
formatElementList(valueList, {
|
|
|
|
|
...options,
|
|
|
|
|
isHandleFirstElement: false
|
|
|
|
|
})
|
|
|
|
|
// 追加节点
|
|
|
|
|
if (valueList.length) {
|
|
|
|
|
const titleId = getUUID()
|
|
|
|
|
const titleOptions = editorOptions.title
|
|
|
|
|
for (let v = 0; v < valueList.length; v++) {
|
|
|
|
|
const value = valueList[v]
|
|
|
|
|
value.titleId = titleId
|
|
|
|
|
value.level = el.level
|
|
|
|
|
// 文本型元素设置字体及加粗
|
|
|
|
|
if (isTextLikeElement(value)) {
|
|
|
|
|
if (!value.size) {
|
|
|
|
|
value.size = titleOptions[titleSizeMapping[value.level!]]
|
|
|
|
|
}
|
|
|
|
|
if (value.bold === undefined) {
|
|
|
|
|
value.bold = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
elementList.splice(i, 0, value)
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
i--
|
|
|
|
|
} else if (el.type === ElementType.LIST) {
|
|
|
|
|
// 移除父节点
|
|
|
|
|
elementList.splice(i, 1)
|
|
|
|
|
// 格式化元素
|
|
|
|
|
const valueList = el.valueList || []
|
|
|
|
|
formatElementList(valueList, {
|
|
|
|
|
...options
|
|
|
|
|
})
|
|
|
|
|
// 追加节点
|
|
|
|
|
if (valueList.length) {
|
|
|
|
|
const listId = getUUID()
|
|
|
|
|
for (let v = 0; v < valueList.length; v++) {
|
|
|
|
|
const value = valueList[v]
|
|
|
|
|
value.listId = listId
|
|
|
|
|
value.listType = el.listType
|
|
|
|
|
value.listStyle = el.listStyle
|
|
|
|
|
elementList.splice(i, 0, value)
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
i--
|
|
|
|
|
} else if (el.type === ElementType.TABLE) {
|
|
|
|
|
const tableId = getUUID()
|
|
|
|
|
el.id = tableId
|
|
|
|
|
if (el.trList) {
|
|
|
|
|
@ -107,58 +160,6 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
i--
|
|
|
|
|
} else if (el.type === ElementType.TITLE) {
|
|
|
|
|
// 移除父节点
|
|
|
|
|
elementList.splice(i, 1)
|
|
|
|
|
// 格式化元素
|
|
|
|
|
const valueList = el.valueList || []
|
|
|
|
|
formatElementList(valueList, {
|
|
|
|
|
...options,
|
|
|
|
|
isHandleFirstElement: false
|
|
|
|
|
})
|
|
|
|
|
// 追加节点
|
|
|
|
|
if (valueList.length) {
|
|
|
|
|
const titleId = getUUID()
|
|
|
|
|
const titleOptions = editorOptions.title
|
|
|
|
|
for (let v = 0; v < valueList.length; v++) {
|
|
|
|
|
const value = valueList[v]
|
|
|
|
|
value.titleId = titleId
|
|
|
|
|
value.level = el.level
|
|
|
|
|
// 文本型元素设置字体及加粗
|
|
|
|
|
if (isTextLikeElement(value)) {
|
|
|
|
|
if (!value.size) {
|
|
|
|
|
value.size = titleOptions[titleSizeMapping[value.level!]]
|
|
|
|
|
}
|
|
|
|
|
if (value.bold === undefined) {
|
|
|
|
|
value.bold = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
elementList.splice(i, 0, value)
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
i--
|
|
|
|
|
} else if (el.type === ElementType.LIST) {
|
|
|
|
|
// 移除父节点
|
|
|
|
|
elementList.splice(i, 1)
|
|
|
|
|
// 格式化元素
|
|
|
|
|
const valueList = el.valueList || []
|
|
|
|
|
formatElementList(valueList, {
|
|
|
|
|
...options
|
|
|
|
|
})
|
|
|
|
|
// 追加节点
|
|
|
|
|
if (valueList.length) {
|
|
|
|
|
const listId = getUUID()
|
|
|
|
|
for (let v = 0; v < valueList.length; v++) {
|
|
|
|
|
const value = valueList[v]
|
|
|
|
|
value.listId = listId
|
|
|
|
|
value.listType = el.listType
|
|
|
|
|
value.listStyle = el.listStyle
|
|
|
|
|
elementList.splice(i, 0, value)
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
i--
|
|
|
|
|
} else if (el.type === ElementType.CONTROL) {
|
|
|
|
|
const { prefix, postfix, value, placeholder, code, type, valueSets } = el.control!
|
|
|
|
|
const controlId = getUUID()
|
|
|
|
|
@ -359,8 +360,56 @@ export function zipElementList(payload: IElement[]): IElement[] {
|
|
|
|
|
e++
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
// 表格、超链接、日期、控件特殊处理
|
|
|
|
|
if (element.type === ElementType.TABLE) {
|
|
|
|
|
// 优先处理虚拟元素,后表格、超链接、日期、控件特殊处理
|
|
|
|
|
if (element.titleId && element.level) {
|
|
|
|
|
// 标题处理
|
|
|
|
|
const titleId = element.titleId
|
|
|
|
|
const level = element.level
|
|
|
|
|
const titleElement: IElement = {
|
|
|
|
|
type: ElementType.TITLE,
|
|
|
|
|
value: '',
|
|
|
|
|
level
|
|
|
|
|
}
|
|
|
|
|
const valueList: IElement[] = []
|
|
|
|
|
while (e < elementList.length) {
|
|
|
|
|
const titleE = elementList[e]
|
|
|
|
|
if (titleId !== titleE.titleId) {
|
|
|
|
|
e--
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
delete titleE.level
|
|
|
|
|
valueList.push(titleE)
|
|
|
|
|
e++
|
|
|
|
|
}
|
|
|
|
|
titleElement.valueList = zipElementList(valueList)
|
|
|
|
|
element = titleElement
|
|
|
|
|
} else if (element.listId && element.listType) {
|
|
|
|
|
// 列表处理
|
|
|
|
|
const listId = element.listId
|
|
|
|
|
const listType = element.listType
|
|
|
|
|
const listStyle = element.listStyle
|
|
|
|
|
const listElement: IElement = {
|
|
|
|
|
type: ElementType.LIST,
|
|
|
|
|
value: '',
|
|
|
|
|
listId,
|
|
|
|
|
listType,
|
|
|
|
|
listStyle
|
|
|
|
|
}
|
|
|
|
|
const valueList: IElement[] = []
|
|
|
|
|
while (e < elementList.length) {
|
|
|
|
|
const listE = elementList[e]
|
|
|
|
|
if (listId !== listE.listId) {
|
|
|
|
|
e--
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
delete listE.listType
|
|
|
|
|
delete listE.listStyle
|
|
|
|
|
valueList.push(listE)
|
|
|
|
|
e++
|
|
|
|
|
}
|
|
|
|
|
listElement.valueList = zipElementList(valueList)
|
|
|
|
|
element = listElement
|
|
|
|
|
} else if (element.type === ElementType.TABLE) {
|
|
|
|
|
if (element.trList) {
|
|
|
|
|
for (let t = 0; t < element.trList.length; t++) {
|
|
|
|
|
const tr = element.trList[t]
|
|
|
|
|
@ -422,54 +471,6 @@ export function zipElementList(payload: IElement[]): IElement[] {
|
|
|
|
|
}
|
|
|
|
|
dateElement.valueList = zipElementList(valueList)
|
|
|
|
|
element = dateElement
|
|
|
|
|
} else if (element.titleId && element.level) {
|
|
|
|
|
// 标题处理
|
|
|
|
|
const titleId = element.titleId
|
|
|
|
|
const level = element.level
|
|
|
|
|
const titleElement: IElement = {
|
|
|
|
|
type: ElementType.TITLE,
|
|
|
|
|
value: '',
|
|
|
|
|
level
|
|
|
|
|
}
|
|
|
|
|
const valueList: IElement[] = []
|
|
|
|
|
while (e < elementList.length) {
|
|
|
|
|
const titleE = elementList[e]
|
|
|
|
|
if (titleId !== titleE.titleId) {
|
|
|
|
|
e--
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
delete titleE.level
|
|
|
|
|
valueList.push(titleE)
|
|
|
|
|
e++
|
|
|
|
|
}
|
|
|
|
|
titleElement.valueList = zipElementList(valueList)
|
|
|
|
|
element = titleElement
|
|
|
|
|
} else if (element.listId && element.listType) {
|
|
|
|
|
// 列表处理
|
|
|
|
|
const listId = element.listId
|
|
|
|
|
const listType = element.listType
|
|
|
|
|
const listStyle = element.listStyle
|
|
|
|
|
const listElement: IElement = {
|
|
|
|
|
type: ElementType.LIST,
|
|
|
|
|
value: '',
|
|
|
|
|
listId,
|
|
|
|
|
listType,
|
|
|
|
|
listStyle
|
|
|
|
|
}
|
|
|
|
|
const valueList: IElement[] = []
|
|
|
|
|
while (e < elementList.length) {
|
|
|
|
|
const listE = elementList[e]
|
|
|
|
|
if (listId !== listE.listId) {
|
|
|
|
|
e--
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
delete listE.listType
|
|
|
|
|
delete listE.listStyle
|
|
|
|
|
valueList.push(listE)
|
|
|
|
|
e++
|
|
|
|
|
}
|
|
|
|
|
listElement.valueList = zipElementList(valueList)
|
|
|
|
|
element = listElement
|
|
|
|
|
} else if (element.type === ElementType.CONTROL) {
|
|
|
|
|
// 控件处理
|
|
|
|
|
const controlId = element.controlId
|
|
|
|
|
|