diff --git a/docs/en/guide/command-execute.md b/docs/en/guide/command-execute.md index c85a78cad..4d6148a45 100644 --- a/docs/en/guide/command-execute.md +++ b/docs/en/guide/command-execute.md @@ -892,6 +892,16 @@ Usage: instance.command.executeSetControlExtension(payload: ISetControlExtensionOption) ``` +## executeSetControlProperties + +Feature: Set control properties + +Usage: + +```javascript +instance.command.executeSetControlProperties(payload: ISetControlProperties) +``` + ## executeSetControlHighlight Feature: Set control highlight (by keyword) diff --git a/docs/guide/command-execute.md b/docs/guide/command-execute.md index 946507223..20547dcf2 100644 --- a/docs/guide/command-execute.md +++ b/docs/guide/command-execute.md @@ -892,6 +892,16 @@ instance.command.executeSetControlValue(payload: ISetControlValueOption) instance.command.executeSetControlExtension(payload: ISetControlExtensionOption) ``` +## executeSetControlProperties + +功能:设置控件属性 + +用法: + +```javascript +instance.command.executeSetControlProperties(payload: ISetControlProperties) +``` + ## executeSetControlHighlight 功能:设置控件高亮(根据关键词) diff --git a/src/editor/core/command/Command.ts b/src/editor/core/command/Command.ts index 3a495d051..972ae4a75 100644 --- a/src/editor/core/command/Command.ts +++ b/src/editor/core/command/Command.ts @@ -88,6 +88,7 @@ export class Command { public executeSetZone: CommandAdapt['setZone'] public executeSetControlValue: CommandAdapt['setControlValue'] public executeSetControlExtension: CommandAdapt['setControlExtension'] + public executeSetControlProperties: CommandAdapt['setControlProperties'] public executeSetControlHighlight: CommandAdapt['setControlHighlight'] public getCatalog: CommandAdapt['getCatalog'] public getImage: CommandAdapt['getImage'] @@ -222,6 +223,7 @@ export class Command { // 控件 this.executeSetControlValue = adapt.setControlValue.bind(adapt) this.executeSetControlExtension = adapt.setControlExtension.bind(adapt) + this.executeSetControlProperties = adapt.setControlProperties.bind(adapt) this.executeSetControlHighlight = adapt.setControlHighlight.bind(adapt) this.getControlValue = adapt.getControlValue.bind(adapt) } diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 5b9b909e9..35e3cba86 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -24,6 +24,7 @@ import { IGetControlValueResult, ISetControlExtensionOption, ISetControlHighlightOption, + ISetControlProperties, ISetControlValueOption } from '../../interface/Control' import { @@ -2288,6 +2289,12 @@ export class CommandAdapt { this.draw.getControl().setExtensionByConceptId(payload) } + public setControlProperties(payload: ISetControlProperties) { + const isReadonly = this.draw.isReadonly() + if (isReadonly) return + this.draw.getControl().setPropertiesByConceptId(payload) + } + public setControlHighlight(payload: ISetControlHighlightOption) { this.draw.getControl().setHighlightList(payload) } diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index c8e8fbe45..e1e808b50 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -13,9 +13,10 @@ import { IGetControlValueOption, IGetControlValueResult, ISetControlExtensionOption, + ISetControlProperties, ISetControlValueOption } from '../../../interface/Control' -import { IEditorOption } from '../../../interface/Editor' +import { IEditorData, IEditorOption } from '../../../interface/Editor' import { IElement, IElementPosition } from '../../../interface/Element' import { EventBusMap } from '../../../interface/EventBus' import { IRange } from '../../../interface/Range' @@ -702,4 +703,53 @@ export class Control { setExtension(elementList) } } + + public setPropertiesByConceptId(payload: ISetControlProperties) { + const isReadonly = this.draw.isReadonly() + if (isReadonly) return + const { conceptId, properties } = payload + let isExistUpdate = false + const pageComponentData: IEditorData = { + header: this.draw.getHeaderElementList(), + main: this.draw.getOriginalMainElementList(), + footer: this.draw.getFooterElementList() + } + for (const key in pageComponentData) { + const elementList = pageComponentData[key]! + let i = 0 + while (i < elementList.length) { + const element = elementList[i] + i++ + if (element?.control?.conceptId !== conceptId) continue + isExistUpdate = true + element.control = { + ...element.control, + ...properties, + value: element.control.value + } + // 修改后控件结束索引 + let newEndIndex = i + while (newEndIndex < elementList.length) { + const nextElement = elementList[newEndIndex] + if (nextElement.controlId !== element.controlId) break + newEndIndex++ + } + i = newEndIndex + } + } + if (!isExistUpdate) return + // 强制更新 + for (const key in pageComponentData) { + const pageComponentKey = key + const elementList = zipElementList(pageComponentData[pageComponentKey]!) + pageComponentData[pageComponentKey] = elementList + formatElementList(elementList, { + editorOptions: this.options + }) + } + this.draw.setEditorData(pageComponentData) + this.draw.render({ + isSetCursor: false + }) + } } diff --git a/src/editor/interface/Control.ts b/src/editor/interface/Control.ts index 0041e9223..afdfd7b94 100644 --- a/src/editor/interface/Control.ts +++ b/src/editor/interface/Control.ts @@ -121,3 +121,8 @@ export interface ISetControlExtensionOption { } export type ISetControlHighlightOption = IControlHighlight[] + +export type ISetControlProperties = { + conceptId: string + properties: Partial> +}