From 7fba458d523ae06678557add90dc9d19a3cb02cb Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Fri, 27 Oct 2023 20:08:59 +0800 Subject: [PATCH] fix: set control value error in table #302 --- src/editor/core/draw/control/Control.ts | 43 +++++++++++++------ .../core/draw/control/select/SelectControl.ts | 4 +- .../core/draw/control/text/TextControl.ts | 2 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index 8dcbaf0..1f3ee55 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -301,8 +301,11 @@ export class Control { } } - public removeControl(startIndex: number): number | null { - const elementList = this.getElementList() + public removeControl( + startIndex: number, + context: IControlContext = {} + ): number | null { + const elementList = context.elementList || this.getElementList() const startElement = elementList[startIndex] const { deletable = true } = startElement.control! if (!deletable) return null @@ -343,8 +346,8 @@ export class Control { return leftIndex } - public removePlaceholder(startIndex: number) { - const elementList = this.getElementList() + public removePlaceholder(startIndex: number, context: IControlContext = {}) { + const elementList = context.elementList || this.getElementList() const startElement = elementList[startIndex] const nextElement = elementList[startIndex + 1] if ( @@ -364,8 +367,8 @@ export class Control { } } - public addPlaceholder(startIndex: number) { - const elementList = this.getElementList() + public addPlaceholder(startIndex: number, context: IControlContext = {}) { + const elementList = context.elementList || this.getElementList() const startElement = elementList[startIndex] const control = startElement.control! if (!control.placeholder) return @@ -471,16 +474,23 @@ export class Control { if (isReadonly) return let isExistSet = false const { conceptId, value } = payload - const data = [ - this.draw.getHeaderElementList(), - this.draw.getOriginalMainElementList(), - this.draw.getFooterElementList() - ] - for (const elementList of data) { + // 设置值 + const setValue = (elementList: IElement[]) => { 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] + setValue(td.value) + } + } + } if (element?.control?.conceptId !== conceptId) continue isExistSet = true const { type } = element.control! @@ -544,6 +554,15 @@ export class Control { i = newEndIndex } } + // 页眉、内容区、页脚同时处理 + const data = [ + this.draw.getHeaderElementList(), + this.draw.getOriginalMainElementList(), + this.draw.getFooterElementList() + ] + for (const elementList of data) { + setValue(elementList) + } if (isExistSet) { this.draw.render({ isSetCursor: false diff --git a/src/editor/core/draw/control/select/SelectControl.ts b/src/editor/core/draw/control/select/SelectControl.ts index 141d688..bd2e09a 100644 --- a/src/editor/core/draw/control/select/SelectControl.ts +++ b/src/editor/core/draw/control/select/SelectControl.ts @@ -175,7 +175,7 @@ export class SelectControl implements IControlInstance { const draw = this.control.getDraw() draw.spliceElementList(elementList, leftIndex + 1, rightIndex - leftIndex) // 增加占位符 - this.control.addPlaceholder(preIndex) + this.control.addPlaceholder(preIndex, context) this.element.control!.code = null return preIndex } @@ -195,7 +195,7 @@ export class SelectControl implements IControlInstance { ) // 清空选项 const prefixIndex = this.clearSelect(context) - this.control.removePlaceholder(prefixIndex) + this.control.removePlaceholder(prefixIndex, context) // 属性赋值元素-默认为前缀属性 const propertyElement = omitObject( elementList[prefixIndex], diff --git a/src/editor/core/draw/control/text/TextControl.ts b/src/editor/core/draw/control/text/TextControl.ts index 8e7ea0a..b5d349a 100644 --- a/src/editor/core/draw/control/text/TextControl.ts +++ b/src/editor/core/draw/control/text/TextControl.ts @@ -73,7 +73,7 @@ export class TextControl implements IControlInstance { draw.spliceElementList(elementList, startIndex + 1, endIndex - startIndex) } else { // 移除空白占位符 - this.control.removePlaceholder(startIndex) + this.control.removePlaceholder(startIndex, context) } // 插入 const startElement = elementList[startIndex]