feat: add executeSetControlProperties api #391

pr675
Hufe921 2 years ago
parent 2fc16de4e1
commit 3ffb6b94b5

@ -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)

@ -892,6 +892,16 @@ instance.command.executeSetControlValue(payload: ISetControlValueOption)
instance.command.executeSetControlExtension(payload: ISetControlExtensionOption)
```
## executeSetControlProperties
功能:设置控件属性
用法:
```javascript
instance.command.executeSetControlProperties(payload: ISetControlProperties)
```
## executeSetControlHighlight
功能:设置控件高亮(根据关键词)

@ -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)
}

@ -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)
}

@ -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[<keyof IEditorData>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 = <keyof IEditorData>key
const elementList = zipElementList(pageComponentData[pageComponentKey]!)
pageComponentData[pageComponentKey] = elementList
formatElementList(elementList, {
editorOptions: this.options
})
}
this.draw.setEditorData(pageComponentData)
this.draw.render({
isSetCursor: false
})
}
}

@ -121,3 +121,8 @@ export interface ISetControlExtensionOption {
}
export type ISetControlHighlightOption = IControlHighlight[]
export type ISetControlProperties = {
conceptId: string
properties: Partial<Omit<IControl, 'value'>>
}

Loading…
Cancel
Save