diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index d4946ac..fe0223a 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -2323,6 +2323,10 @@ export class Draw { } // 信息变动回调 nextTick(() => { + // 重新唤起弹窗类控件 + if (isCompute && this.control.getActiveControl()) { + this.control.reAwakeControl() + } // 表格工具重新渲染 if ( isCompute && diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index 40d9150..78d854e 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -12,6 +12,7 @@ import { IControlRuleOption, IGetControlValueOption, IGetControlValueResult, + IRepaintControlOption, ISetControlExtensionOption, ISetControlProperties, ISetControlValueOption @@ -284,20 +285,41 @@ export class Control { } } - public repaintControl(curIndex?: number) { + public repaintControl(options: IRepaintControlOption = {}) { + const { curIndex, isCompute = true, isSubmitHistory = true } = options + // 重新渲染 if (curIndex === undefined) { this.range.clearRange() this.draw.render({ + isCompute, + isSubmitHistory, isSetCursor: false }) } else { this.range.setRange(curIndex, curIndex) this.draw.render({ - curIndex + curIndex, + isCompute, + isSubmitHistory }) } } + public reAwakeControl() { + if (!this.activeControl) return + const elementList = this.getElementList() + const range = this.getRange() + const element = elementList[range.startIndex] + this.activeControl.setElement(element) + if ( + this.activeControl instanceof SelectControl && + this.activeControl.getIsPopup() + ) { + this.activeControl.destroy() + this.activeControl.awake() + } + } + public moveCursor(position: IControlInitOption): IMoveCursorResult { const { index, trIndex, tdIndex, tdValueIndex } = position let elementList = this.draw.getOriginalElementList() diff --git a/src/editor/core/draw/control/checkbox/CheckboxControl.ts b/src/editor/core/draw/control/checkbox/CheckboxControl.ts index 23bdcc6..75850dd 100644 --- a/src/editor/core/draw/control/checkbox/CheckboxControl.ts +++ b/src/editor/core/draw/control/checkbox/CheckboxControl.ts @@ -17,6 +17,10 @@ export class CheckboxControl implements IControlInstance { this.control = control } + public setElement(element: IElement) { + this.element = element + } + public getElement(): IElement { return this.element } diff --git a/src/editor/core/draw/control/select/SelectControl.ts b/src/editor/core/draw/control/select/SelectControl.ts index 0ea4043..d2bba27 100644 --- a/src/editor/core/draw/control/select/SelectControl.ts +++ b/src/editor/core/draw/control/select/SelectControl.ts @@ -33,10 +33,18 @@ export class SelectControl implements IControlInstance { this.selectDom = null } + public setElement(element: IElement) { + this.element = element + } + public getElement(): IElement { return this.element } + public getIsPopup(): boolean { + return this.isPopup + } + public getCode(): string | null { return this.element.control?.code || null } @@ -153,8 +161,9 @@ export class SelectControl implements IControlInstance { context: IControlContext = {}, options: IControlRuleOption = {} ): number { + const { isIgnoreDisabledRule = false, isAddPlaceholder = true } = options // 校验是否可以设置 - if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) { + if (!isIgnoreDisabledRule && this.control.getIsDisabledControl()) { return -1 } const elementList = context.elementList || this.control.getElementList() @@ -193,7 +202,9 @@ export class SelectControl implements IControlInstance { const draw = this.control.getDraw() draw.spliceElementList(elementList, leftIndex + 1, rightIndex - leftIndex) // 增加占位符 - this.control.addPlaceholder(preIndex, context) + if (isAddPlaceholder) { + this.control.addPlaceholder(preIndex, context) + } this.element.control!.code = null return preIndex } @@ -207,23 +218,39 @@ export class SelectControl implements IControlInstance { if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) { return } + const elementList = context.elementList || this.control.getElementList() + const range = context.range || this.control.getRange() const control = this.element.control! + const oldCode = control.code + // 选项相同时无需重复渲染 + if (code === oldCode) { + this.control.repaintControl({ + curIndex: range.startIndex, + isCompute: false, + isSubmitHistory: false + }) + this.destroy() + return + } const valueSets = control.valueSets if (!Array.isArray(valueSets) || !valueSets.length) return // 转换code const valueSet = valueSets.find(v => v.code === code) if (!valueSet) return - const elementList = context.elementList || this.control.getElementList() - const range = context.range || this.control.getRange() // 样式赋值元素-默认值的第一个字符样式,否则取默认样式 const valueElement = this.getValue(context)[0] const styleElement = valueElement ? pickObject(valueElement, EDITOR_ELEMENT_STYLE_ATTR) : pickObject(elementList[range.startIndex], CONTROL_STYLE_ATTR) // 清空选项 - const prefixIndex = this.clearSelect(context) + const prefixIndex = this.clearSelect(context, { + isAddPlaceholder: false + }) if (!~prefixIndex) return - this.control.removePlaceholder(prefixIndex, context) + // 当前无值时清空占位符 + if (!oldCode) { + this.control.removePlaceholder(prefixIndex, context) + } // 属性赋值元素-默认为前缀属性 const propertyElement = omitObject( elementList[prefixIndex], @@ -244,11 +271,13 @@ export class SelectControl implements IControlInstance { draw.spliceElementList(elementList, start + i, 0, newElement) } // 设置状态 - this.element.control!.code = code + control.code = code // 重新渲染控件 if (!context.range) { const newIndex = start + data.length - 1 - this.control.repaintControl(newIndex) + this.control.repaintControl({ + curIndex: newIndex + }) this.destroy() } } diff --git a/src/editor/core/draw/control/text/TextControl.ts b/src/editor/core/draw/control/text/TextControl.ts index 836fdfc..46941b4 100644 --- a/src/editor/core/draw/control/text/TextControl.ts +++ b/src/editor/core/draw/control/text/TextControl.ts @@ -23,6 +23,10 @@ export class TextControl implements IControlInstance { this.control = control } + public setElement(element: IElement) { + this.element = element + } + public getElement(): IElement { return this.element } diff --git a/src/editor/interface/Control.ts b/src/editor/interface/Control.ts index 430475a..2468f9c 100644 --- a/src/editor/interface/Control.ts +++ b/src/editor/interface/Control.ts @@ -1,6 +1,7 @@ import { ControlType, ControlIndentation } from '../dataset/enum/Control' import { EditorZone } from '../dataset/enum/Editor' import { ICheckbox } from './Checkbox' +import { IDrawOption } from './Draw' import { IElement } from './Element' import { IRadio } from './Radio' import { IRange } from './Range' @@ -97,18 +98,15 @@ export interface IControlInitResult { } export interface IControlInstance { + setElement(element: IElement): void getElement(): IElement - getValue(): IElement[] - setValue( data: IElement[], context?: IControlContext, options?: IControlRuleOption ): number - keydown(evt: KeyboardEvent): number | null - cut(): number } @@ -119,6 +117,7 @@ export interface IControlContext { export interface IControlRuleOption { isIgnoreDisabledRule?: boolean // 忽略禁用校验规则 + isAddPlaceholder?: boolean // 是否添加占位符 } export interface IGetControlValueOption { @@ -147,3 +146,8 @@ export type ISetControlProperties = { conceptId: string properties: Partial> } + +export type IRepaintControlOption = Pick< + IDrawOption, + 'curIndex' | 'isCompute' | 'isSubmitHistory' +>