fix: checkbox cannot be selected #382
This commit is contained in:
@@ -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,6 +68,10 @@ 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
|
||||||
|
// 复选框不在控件内独立控制
|
||||||
|
if (!control) {
|
||||||
|
draw.getCheckboxParticle().setSelect(curElement)
|
||||||
|
} else {
|
||||||
const codes = control?.code?.split(',') || []
|
const codes = control?.code?.split(',') || []
|
||||||
if (checkbox?.value) {
|
if (checkbox?.value) {
|
||||||
const codeIndex = codes.findIndex(c => c === checkbox.code)
|
const codeIndex = codes.findIndex(c => c === checkbox.code)
|
||||||
@@ -81,6 +85,7 @@ export function mousedown(evt: MouseEvent, host: CanvasEvent) {
|
|||||||
if (activeControl instanceof CheckboxControl) {
|
if (activeControl instanceof CheckboxControl) {
|
||||||
activeControl.setSelect(codes)
|
activeControl.setSelect(codes)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
draw.render({
|
draw.render({
|
||||||
curIndex,
|
curIndex,
|
||||||
|
|||||||
@@ -749,6 +749,9 @@ window.onload = function () {
|
|||||||
instance.command.executeInsertElementList([
|
instance.command.executeInsertElementList([
|
||||||
{
|
{
|
||||||
type: ElementType.CHECKBOX,
|
type: ElementType.CHECKBOX,
|
||||||
|
checkbox: {
|
||||||
|
value: false
|
||||||
|
},
|
||||||
value: ''
|
value: ''
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in New Issue
Block a user