From 285aeec2f6eeba676361b109e595744c2f1e4641 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Fri, 15 Dec 2023 20:53:52 +0800 Subject: [PATCH] feat: add zone attribute to getControlValue api --- src/editor/core/draw/control/Control.ts | 28 ++++++++++++++++++------- src/editor/interface/Control.ts | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index 2abb1d9..f2bc4c8 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -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, @@ -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] @@ -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) } } } @@ -466,6 +467,7 @@ export class Control { if (type === ControlType.TEXT) { result.push({ ...element.control, + zone, value: textControlValue || null, innerText: textControlValue || null }) @@ -483,6 +485,7 @@ export class Control { .join('') result.push({ ...element.control, + zone, value: code || null, innerText: innerText || null }) @@ -490,12 +493,23 @@ export class Control { 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 } diff --git a/src/editor/interface/Control.ts b/src/editor/interface/Control.ts index 8540dfd..fa23ea8 100644 --- a/src/editor/interface/Control.ts +++ b/src/editor/interface/Control.ts @@ -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' @@ -95,6 +96,7 @@ export interface IGetControlValueOption { export type IGetControlValueResult = (Omit & { value: string | null innerText: string | null + zone: EditorZone })[] export interface ISetControlValueOption {