Skip to content

Commit

Permalink
feat: add zone attribute to getControlValue api
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Dec 15, 2023
1 parent 2a904fe commit 285aeec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/editor/core/draw/control/Control.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ControlComponent, ControlType } from '../../../dataset/enum/Control'
import { EditorZone } from '../../../dataset/enum/Editor'
import { ElementType } from '../../../dataset/enum/Element'
import {
IControl,
Expand Down Expand Up @@ -432,7 +433,7 @@ export class Control {
): IGetControlValueResult {
const { conceptId } = payload
const result: IGetControlValueResult = []
const getValue = (elementList: IElement[]) => {
const getValue = (elementList: IElement[], zone: EditorZone) => {
let i = 0
while (i < elementList.length) {
const element = elementList[i]
Expand All @@ -444,7 +445,7 @@ export class Control {
const tr = trList[r]
for (let d = 0; d < tr.tdList.length; d++) {
const td = tr.tdList[d]
getValue(td.value)
getValue(td.value, zone)
}
}
}
Expand All @@ -466,6 +467,7 @@ export class Control {
if (type === ControlType.TEXT) {
result.push({
...element.control,
zone,
value: textControlValue || null,
innerText: textControlValue || null
})
Expand All @@ -483,19 +485,31 @@ export class Control {
.join('')
result.push({
...element.control,
zone,
value: code || null,
innerText: innerText || null
})
}
i = j
}
}
const elementList = [
...this.draw.getHeaderElementList(),
...this.draw.getOriginalMainElementList(),
...this.draw.getFooterElementList()
const data = [
{
zone: EditorZone.HEADER,
elementList: this.draw.getHeaderElementList()
},
{
zone: EditorZone.MAIN,
elementList: this.draw.getOriginalMainElementList()
},
{
zone: EditorZone.FOOTER,
elementList: this.draw.getFooterElementList()
}
]
getValue(elementList)
for (const { zone, elementList } of data) {
getValue(elementList, zone)
}
return result
}

Expand Down
2 changes: 2 additions & 0 deletions src/editor/interface/Control.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ControlType, ControlIndentation } from '../dataset/enum/Control'
import { EditorZone } from '../dataset/enum/Editor'
import { ICheckbox } from './Checkbox'
import { IElement } from './Element'
import { IRange } from './Range'
Expand Down Expand Up @@ -95,6 +96,7 @@ export interface IGetControlValueOption {
export type IGetControlValueResult = (Omit<IControl, 'value'> & {
value: string | null
innerText: string | null
zone: EditorZone
})[]

export interface ISetControlValueOption {
Expand Down

0 comments on commit 285aeec

Please sign in to comment.