Skip to content

Commit

Permalink
feat: add executeSetControlProperties api #391
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Jan 28, 2024
1 parent 2fc16de commit 3ffb6b9
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/en/guide/command-execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions docs/guide/command-execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,16 @@ instance.command.executeSetControlValue(payload: ISetControlValueOption)
instance.command.executeSetControlExtension(payload: ISetControlExtensionOption)
```

## executeSetControlProperties

功能:设置控件属性

用法:

```javascript
instance.command.executeSetControlProperties(payload: ISetControlProperties)
```

## executeSetControlHighlight

功能:设置控件高亮(根据关键词)
Expand Down
2 changes: 2 additions & 0 deletions src/editor/core/command/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions src/editor/core/command/CommandAdapt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
IGetControlValueResult,
ISetControlExtensionOption,
ISetControlHighlightOption,
ISetControlProperties,
ISetControlValueOption
} from '../../interface/Control'
import {
Expand Down Expand Up @@ -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)
}
Expand Down
52 changes: 51 additions & 1 deletion src/editor/core/draw/control/Control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
})
}
}
5 changes: 5 additions & 0 deletions src/editor/interface/Control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,8 @@ export interface ISetControlExtensionOption {
}

export type ISetControlHighlightOption = IControlHighlight[]

export type ISetControlProperties = {
conceptId: string
properties: Partial<Omit<IControl, 'value'>>
}

0 comments on commit 3ffb6b9

Please sign in to comment.