feat:add control change callback

pr675
Hufe921 4 years ago
parent ce8fbd0b91
commit b5b2c8ff6b

@ -1,7 +1,10 @@
import { ControlComponent, ControlType } from '../../../dataset/enum/Control' import { ControlComponent, ControlType } from '../../../dataset/enum/Control'
import { ElementType } from '../../../dataset/enum/Element' import { ElementType } from '../../../dataset/enum/Element'
import { IControlInitOption, IControlInstance, IControlOption } from '../../../interface/Control' import { IControl, IControlInitOption, IControlInstance, IControlOption } from '../../../interface/Control'
import { IElement, IElementPosition } from '../../../interface/Element' import { IElement, IElementPosition } from '../../../interface/Element'
import { deepClone } from '../../../utils'
import { pickElementAttr, zipElementList } from '../../../utils/element'
import { Listener } from '../../listener/Listener'
import { RangeManager } from '../../range/RangeManager' import { RangeManager } from '../../range/RangeManager'
import { Draw } from '../Draw' import { Draw } from '../Draw'
import { SelectControl } from './select/SelectControl' import { SelectControl } from './select/SelectControl'
@ -15,12 +18,14 @@ export class Control {
private draw: Draw private draw: Draw
private range: RangeManager private range: RangeManager
private listener: Listener
private options: IControlOption private options: IControlOption
private activeControl: IControlInstance | null private activeControl: IControlInstance | null
constructor(draw: Draw) { constructor(draw: Draw) {
this.draw = draw this.draw = draw
this.range = draw.getRange() this.range = draw.getRange()
this.listener = draw.getListener()
this.options = draw.getOptions().control this.options = draw.getOptions().control
this.activeControl = null this.activeControl = null
} }
@ -97,6 +102,19 @@ export class Control {
this.activeControl = selectControl this.activeControl = selectControl
selectControl.awake() selectControl.awake()
} }
// 激活控件回调
setTimeout(() => {
if (this.listener.controlChange) {
let payload: IControl
const value = this.activeControl?.getValue()
if (value && value.length) {
payload = zipElementList(value)[0].control!
} else {
payload = pickElementAttr(deepClone(element)).control!
}
this.listener.controlChange(payload)
}
})
} }
public destroyControl() { public destroyControl() {
@ -105,6 +123,12 @@ export class Control {
this.activeControl.destroy() this.activeControl.destroy()
} }
this.activeControl = null this.activeControl = null
// 销毁控件回调
setTimeout(() => {
if (this.listener.controlChange) {
this.listener.controlChange(null)
}
})
} }
} }

@ -1,5 +1,6 @@
import { import {
IContentChange, IContentChange,
IControlChange,
IIntersectionPageNoChange, IIntersectionPageNoChange,
IPageScaleChange, IPageScaleChange,
IPageSizeChange, IPageSizeChange,
@ -17,6 +18,7 @@ export class Listener {
public pageScaleChange: IPageScaleChange | null public pageScaleChange: IPageScaleChange | null
public saved: ISaved | null public saved: ISaved | null
public contentChange: IContentChange | null public contentChange: IContentChange | null
public controlChange: IControlChange | null
constructor() { constructor() {
this.rangeStyleChange = null this.rangeStyleChange = null
@ -26,6 +28,7 @@ export class Listener {
this.pageScaleChange = null this.pageScaleChange = null
this.saved = null this.saved = null
this.contentChange = null this.contentChange = null
this.controlChange = null
} }
} }

@ -1,5 +1,6 @@
import { ElementType } from '..' import { ElementType } from '..'
import { RowFlex } from '../dataset/enum/Row' import { RowFlex } from '../dataset/enum/Row'
import { IControl } from './Control'
import { IEditorResult } from './Editor' import { IEditorResult } from './Editor'
export interface IRangeStyle { export interface IRangeStyle {
@ -32,3 +33,5 @@ export type IPageScaleChange = (payload: number) => void
export type ISaved = (payload: IEditorResult) => void export type ISaved = (payload: IEditorResult) => void
export type IContentChange = () => void export type IContentChange = () => void
export type IControlChange = (payload: IControl | null) => void
Loading…
Cancel
Save