fix: wake up pop-up controls #580

pr675
Hufe921 2 years ago
parent 24aa33a4f1
commit 28f6bdbb41

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

@ -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()

@ -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
}

@ -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()
}
}

@ -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
}

@ -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<Omit<IControl, 'value'>>
}
export type IRepaintControlOption = Pick<
IDrawOption,
'curIndex' | 'isCompute' | 'isSubmitHistory'
>

Loading…
Cancel
Save