fix: checkbox cannot be selected #382

pr675
Hufe921 2 years ago
parent bdb981d242
commit 3fb8435706

@ -703,6 +703,10 @@ export class Draw {
return this.listParticle return this.listParticle
} }
public getCheckboxParticle(): CheckboxParticle {
return this.checkboxParticle
}
public getControl(): Control { public getControl(): Control {
return this.control return this.control
} }

@ -1,15 +1,33 @@
import { DeepRequired } from '../../../interface/Common' import { DeepRequired } from '../../../interface/Common'
import { IEditorOption } from '../../../interface/Editor' import { IEditorOption } from '../../../interface/Editor'
import { IElement } from '../../../interface/Element'
import { IRowElement } from '../../../interface/Row' import { IRowElement } from '../../../interface/Row'
import { Draw } from '../Draw' import { Draw } from '../Draw'
export class CheckboxParticle { export class CheckboxParticle {
private draw: Draw
private options: DeepRequired<IEditorOption> private options: DeepRequired<IEditorOption>
constructor(draw: Draw) { constructor(draw: Draw) {
this.draw = draw
this.options = draw.getOptions() this.options = draw.getOptions()
} }
public setSelect(element: IElement) {
const { checkbox } = element
if (checkbox) {
checkbox.value = !checkbox.value
} else {
element.checkbox = {
value: true
}
}
this.draw.render({
isCompute: false,
isSetCursor: false
})
}
public render( public render(
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
element: IRowElement, element: IRowElement,

@ -68,18 +68,23 @@ export function mousedown(evt: MouseEvent, host: CanvasEvent) {
const isSetCheckbox = isDirectHitCheckbox && !isReadonly const isSetCheckbox = isDirectHitCheckbox && !isReadonly
if (isSetCheckbox) { if (isSetCheckbox) {
const { checkbox, control } = curElement const { checkbox, control } = curElement
const codes = control?.code?.split(',') || [] // 复选框不在控件内独立控制
if (checkbox?.value) { if (!control) {
const codeIndex = codes.findIndex(c => c === checkbox.code) draw.getCheckboxParticle().setSelect(curElement)
codes.splice(codeIndex, 1)
} else { } else {
if (checkbox?.code) { const codes = control?.code?.split(',') || []
codes.push(checkbox.code) if (checkbox?.value) {
const codeIndex = codes.findIndex(c => c === checkbox.code)
codes.splice(codeIndex, 1)
} else {
if (checkbox?.code) {
codes.push(checkbox.code)
}
}
const activeControl = draw.getControl().getActiveControl()
if (activeControl instanceof CheckboxControl) {
activeControl.setSelect(codes)
} }
}
const activeControl = draw.getControl().getActiveControl()
if (activeControl instanceof CheckboxControl) {
activeControl.setSelect(codes)
} }
} else { } else {
draw.render({ draw.render({

@ -749,6 +749,9 @@ window.onload = function () {
instance.command.executeInsertElementList([ instance.command.executeInsertElementList([
{ {
type: ElementType.CHECKBOX, type: ElementType.CHECKBOX,
checkbox: {
value: false
},
value: '' value: ''
} }
]) ])

Loading…
Cancel
Save