fix: wake up pop-up controls #580

pr675
Hufe921 2 years ago
parent 24aa33a4f1
commit 28f6bdbb41

@ -2323,6 +2323,10 @@ export class Draw {
} }
// 信息变动回调 // 信息变动回调
nextTick(() => { nextTick(() => {
// 重新唤起弹窗类控件
if (isCompute && this.control.getActiveControl()) {
this.control.reAwakeControl()
}
// 表格工具重新渲染 // 表格工具重新渲染
if ( if (
isCompute && isCompute &&

@ -12,6 +12,7 @@ import {
IControlRuleOption, IControlRuleOption,
IGetControlValueOption, IGetControlValueOption,
IGetControlValueResult, IGetControlValueResult,
IRepaintControlOption,
ISetControlExtensionOption, ISetControlExtensionOption,
ISetControlProperties, ISetControlProperties,
ISetControlValueOption 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) { if (curIndex === undefined) {
this.range.clearRange() this.range.clearRange()
this.draw.render({ this.draw.render({
isCompute,
isSubmitHistory,
isSetCursor: false isSetCursor: false
}) })
} else { } else {
this.range.setRange(curIndex, curIndex) this.range.setRange(curIndex, curIndex)
this.draw.render({ 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 { public moveCursor(position: IControlInitOption): IMoveCursorResult {
const { index, trIndex, tdIndex, tdValueIndex } = position const { index, trIndex, tdIndex, tdValueIndex } = position
let elementList = this.draw.getOriginalElementList() let elementList = this.draw.getOriginalElementList()

@ -17,6 +17,10 @@ export class CheckboxControl implements IControlInstance {
this.control = control this.control = control
} }
public setElement(element: IElement) {
this.element = element
}
public getElement(): IElement { public getElement(): IElement {
return this.element return this.element
} }

@ -33,10 +33,18 @@ export class SelectControl implements IControlInstance {
this.selectDom = null this.selectDom = null
} }
public setElement(element: IElement) {
this.element = element
}
public getElement(): IElement { public getElement(): IElement {
return this.element return this.element
} }
public getIsPopup(): boolean {
return this.isPopup
}
public getCode(): string | null { public getCode(): string | null {
return this.element.control?.code || null return this.element.control?.code || null
} }
@ -153,8 +161,9 @@ export class SelectControl implements IControlInstance {
context: IControlContext = {}, context: IControlContext = {},
options: IControlRuleOption = {} options: IControlRuleOption = {}
): number { ): number {
const { isIgnoreDisabledRule = false, isAddPlaceholder = true } = options
// 校验是否可以设置 // 校验是否可以设置
if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) { if (!isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
return -1 return -1
} }
const elementList = context.elementList || this.control.getElementList() const elementList = context.elementList || this.control.getElementList()
@ -193,7 +202,9 @@ export class SelectControl implements IControlInstance {
const draw = this.control.getDraw() const draw = this.control.getDraw()
draw.spliceElementList(elementList, leftIndex + 1, rightIndex - leftIndex) draw.spliceElementList(elementList, leftIndex + 1, rightIndex - leftIndex)
// 增加占位符 // 增加占位符
this.control.addPlaceholder(preIndex, context) if (isAddPlaceholder) {
this.control.addPlaceholder(preIndex, context)
}
this.element.control!.code = null this.element.control!.code = null
return preIndex return preIndex
} }
@ -207,23 +218,39 @@ export class SelectControl implements IControlInstance {
if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) { if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
return return
} }
const elementList = context.elementList || this.control.getElementList()
const range = context.range || this.control.getRange()
const control = this.element.control! 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 const valueSets = control.valueSets
if (!Array.isArray(valueSets) || !valueSets.length) return if (!Array.isArray(valueSets) || !valueSets.length) return
// 转换code // 转换code
const valueSet = valueSets.find(v => v.code === code) const valueSet = valueSets.find(v => v.code === code)
if (!valueSet) return if (!valueSet) return
const elementList = context.elementList || this.control.getElementList()
const range = context.range || this.control.getRange()
// 样式赋值元素-默认值的第一个字符样式,否则取默认样式 // 样式赋值元素-默认值的第一个字符样式,否则取默认样式
const valueElement = this.getValue(context)[0] const valueElement = this.getValue(context)[0]
const styleElement = valueElement const styleElement = valueElement
? pickObject(valueElement, EDITOR_ELEMENT_STYLE_ATTR) ? pickObject(valueElement, EDITOR_ELEMENT_STYLE_ATTR)
: pickObject(elementList[range.startIndex], CONTROL_STYLE_ATTR) : pickObject(elementList[range.startIndex], CONTROL_STYLE_ATTR)
// 清空选项 // 清空选项
const prefixIndex = this.clearSelect(context) const prefixIndex = this.clearSelect(context, {
isAddPlaceholder: false
})
if (!~prefixIndex) return if (!~prefixIndex) return
this.control.removePlaceholder(prefixIndex, context) // 当前无值时清空占位符
if (!oldCode) {
this.control.removePlaceholder(prefixIndex, context)
}
// 属性赋值元素-默认为前缀属性 // 属性赋值元素-默认为前缀属性
const propertyElement = omitObject( const propertyElement = omitObject(
elementList[prefixIndex], elementList[prefixIndex],
@ -244,11 +271,13 @@ export class SelectControl implements IControlInstance {
draw.spliceElementList(elementList, start + i, 0, newElement) draw.spliceElementList(elementList, start + i, 0, newElement)
} }
// 设置状态 // 设置状态
this.element.control!.code = code control.code = code
// 重新渲染控件 // 重新渲染控件
if (!context.range) { if (!context.range) {
const newIndex = start + data.length - 1 const newIndex = start + data.length - 1
this.control.repaintControl(newIndex) this.control.repaintControl({
curIndex: newIndex
})
this.destroy() this.destroy()
} }
} }

@ -23,6 +23,10 @@ export class TextControl implements IControlInstance {
this.control = control this.control = control
} }
public setElement(element: IElement) {
this.element = element
}
public getElement(): IElement { public getElement(): IElement {
return this.element return this.element
} }

@ -1,6 +1,7 @@
import { ControlType, ControlIndentation } from '../dataset/enum/Control' import { ControlType, ControlIndentation } from '../dataset/enum/Control'
import { EditorZone } from '../dataset/enum/Editor' import { EditorZone } from '../dataset/enum/Editor'
import { ICheckbox } from './Checkbox' import { ICheckbox } from './Checkbox'
import { IDrawOption } from './Draw'
import { IElement } from './Element' import { IElement } from './Element'
import { IRadio } from './Radio' import { IRadio } from './Radio'
import { IRange } from './Range' import { IRange } from './Range'
@ -97,18 +98,15 @@ export interface IControlInitResult {
} }
export interface IControlInstance { export interface IControlInstance {
setElement(element: IElement): void
getElement(): IElement getElement(): IElement
getValue(): IElement[] getValue(): IElement[]
setValue( setValue(
data: IElement[], data: IElement[],
context?: IControlContext, context?: IControlContext,
options?: IControlRuleOption options?: IControlRuleOption
): number ): number
keydown(evt: KeyboardEvent): number | null keydown(evt: KeyboardEvent): number | null
cut(): number cut(): number
} }
@ -119,6 +117,7 @@ export interface IControlContext {
export interface IControlRuleOption { export interface IControlRuleOption {
isIgnoreDisabledRule?: boolean // 忽略禁用校验规则 isIgnoreDisabledRule?: boolean // 忽略禁用校验规则
isAddPlaceholder?: boolean // 是否添加占位符
} }
export interface IGetControlValueOption { export interface IGetControlValueOption {
@ -147,3 +146,8 @@ export type ISetControlProperties = {
conceptId: string conceptId: string
properties: Partial<Omit<IControl, 'value'>> properties: Partial<Omit<IControl, 'value'>>
} }
export type IRepaintControlOption = Pick<
IDrawOption,
'curIndex' | 'isCompute' | 'isSubmitHistory'
>

Loading…
Cancel
Save