feat:checkbox control set select

pr675
Hufe921 4 years ago
parent 4d48eb2cde
commit 1315ce070b

@ -2,6 +2,7 @@ import { ControlComponent, ControlType } from '../../../dataset/enum/Control'
import { ElementType } from '../../../dataset/enum/Element'
import { IControl, IControlInitOption, IControlInstance, IControlOption } from '../../../interface/Control'
import { IElement, IElementPosition } from '../../../interface/Element'
import { IRange } from '../../../interface/Range'
import { deepClone } from '../../../utils'
import { pickElementAttr, zipElementList } from '../../../utils/element'
import { Listener } from '../../listener/Listener'
@ -67,7 +68,7 @@ export class Control {
return this.draw.getPageNo() * (height + pageGap)
}
public getRange() {
public getRange(): IRange {
return this.range.getRange()
}

@ -65,6 +65,51 @@ export class CheckboxControl implements IControlInstance {
return endIndex
}
public setSelect() {
const { control } = this.element
const elementList = this.control.getElementList()
const { startIndex } = this.control.getRange()
const startElement = elementList[startIndex]
const data: string[] = []
// 向左查找
let preIndex = startIndex
while (preIndex > 0) {
const preElement = elementList[preIndex]
if (
preElement.controlId !== startElement.controlId ||
preElement.controlComponent === ControlComponent.PREFIX
) {
break
}
if (preElement.controlComponent === ControlComponent.CHECKBOX) {
const checkbox = preElement.checkbox
if (checkbox && checkbox.value && checkbox.code) {
data.unshift(checkbox.code)
}
}
preIndex--
}
// 向右查找
let nextIndex = startIndex + 1
while (nextIndex < elementList.length) {
const nextElement = elementList[nextIndex]
if (
nextElement.controlId !== startElement.controlId ||
nextElement.controlComponent === ControlComponent.POSTFIX
) {
break
}
if (nextElement.controlComponent === ControlComponent.CHECKBOX) {
const checkbox = nextElement.checkbox
if (checkbox && checkbox.value && checkbox.code) {
data.push(checkbox.code)
}
}
nextIndex++
}
control!.code = data.join(',')
}
public keydown(evt: KeyboardEvent): number {
const range = this.control.getRange()
// 收缩边界到Value内

@ -18,6 +18,7 @@ import { Position } from '../position/Position'
import { RangeManager } from '../range/RangeManager'
import { LETTER_REG, NUMBER_LIKE_REG } from '../../dataset/constant/Regular'
import { Control } from '../draw/control/Control'
import { CheckboxControl } from '../draw/control/checkbox/CheckboxControl'
export class CanvasEvent {
@ -236,6 +237,10 @@ export class CanvasEvent {
value: true
}
}
const activeControl = this.control.getActiveControl()
if (activeControl instanceof CheckboxControl) {
activeControl.setSelect()
}
}
this.draw.render({
curIndex,

@ -1,6 +1,7 @@
export interface ICheckbox {
disabled?: boolean;
value: boolean | null;
code?: string;
disabled?: boolean;
}
export interface ICheckboxOption {

@ -114,6 +114,7 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme
control: el.control,
controlComponent: ControlComponent.CHECKBOX,
checkbox: {
code: valueSet.code,
value: codeList.includes(valueSet.code)
}
})

Loading…
Cancel
Save