fix: set control value error in table #302
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user