feat: add getTitleValue api #536

This commit is contained in:
Hufe921
2024-05-02 22:26:00 +08:00
parent 0ae67ec602
commit 15f52c5e43
10 changed files with 136 additions and 3 deletions
+2
View File
@@ -110,6 +110,7 @@ export class Command {
public getControlValue: CommandAdapt['getControlValue']
public getControlList: CommandAdapt['getControlList']
public getContainer: CommandAdapt['getContainer']
public getTitleValue: CommandAdapt['getTitleValue']
constructor(adapt: CommandAdapt) {
// 全局命令
@@ -223,6 +224,7 @@ export class Command {
this.getLocale = adapt.getLocale.bind(adapt)
this.getGroupIds = adapt.getGroupIds.bind(adapt)
this.getContainer = adapt.getContainer.bind(adapt)
this.getTitleValue = adapt.getTitleValue.bind(adapt)
// 控件
this.executeSetControlValue = adapt.setControlValue.bind(adapt)
this.executeSetControlExtension = adapt.setControlExtension.bind(adapt)
+74 -1
View File
@@ -1,6 +1,9 @@
import { NBSP, WRAP, ZERO } from '../../dataset/constant/Common'
import { EDITOR_ELEMENT_STYLE_ATTR } from '../../dataset/constant/Element'
import { titleSizeMapping } from '../../dataset/constant/Title'
import {
titleOrderNumberMapping,
titleSizeMapping
} from '../../dataset/constant/Title'
import { defaultWatermarkOption } from '../../dataset/constant/Watermark'
import { ImageDisplay } from '../../dataset/enum/Common'
import { ControlComponent } from '../../dataset/enum/Control'
@@ -52,6 +55,10 @@ import { IColgroup } from '../../interface/table/Colgroup'
import { ITd } from '../../interface/table/Td'
import { ITr } from '../../interface/table/Tr'
import { ITextDecoration } from '../../interface/Text'
import {
IGetTitleValueOption,
IGetTitleValueResult
} from '../../interface/Title'
import { IWatermark } from '../../interface/Watermark'
import { deepClone, downloadFile, getUUID, isObjectEqual } from '../../utils'
import {
@@ -2398,4 +2405,70 @@ export class CommandAdapt {
public getContainer(): HTMLDivElement {
return this.draw.getContainer()
}
public getTitleValue(
payload: IGetTitleValueOption
): IGetTitleValueResult | null {
const { conceptId } = payload
const result: IGetTitleValueResult = []
const getValue = (elementList: IElement[], zone: EditorZone) => {
let i = 0
while (i < elementList.length) {
const element = elementList[i]
i++
if (element.type === ElementType.TABLE) {
const trList = element.trList!
for (let r = 0; r < trList.length; r++) {
const tr = trList[r]
for (let d = 0; d < tr.tdList.length; d++) {
const td = tr.tdList[d]
getValue(td.value, zone)
}
}
}
if (element?.title?.conceptId !== conceptId) continue
// 先查找到标题,后循环至同级或上级标题处停止
const valueList: IElement[] = []
let j = i
while (j < elementList.length) {
const nextElement = elementList[j]
j++
if (element.titleId === nextElement.titleId) continue
if (
nextElement.level &&
titleOrderNumberMapping[nextElement.level] <=
titleOrderNumberMapping[element.level!]
) {
break
}
valueList.push(nextElement)
}
result.push({
...element.title!,
value: getTextFromElementList(valueList),
elementList: zipElementList(valueList),
zone
})
i = j
}
}
const data = [
{
zone: EditorZone.HEADER,
elementList: this.draw.getHeaderElementList()
},
{
zone: EditorZone.MAIN,
elementList: this.draw.getOriginalMainElementList()
},
{
zone: EditorZone.FOOTER,
elementList: this.draw.getFooterElementList()
}
]
for (const { zone, elementList } of data) {
getValue(elementList, zone)
}
return result
}
}