本页由脚本自动生成,请勿手动编辑。如需补充说明,请使用
::: tip块。
Defined in: commands/batch-command.d.ts:4
Extends
Constructors
Constructor
new BatchCommand(
host,
commands?,
description?): BatchCommand;Defined in: commands/batch-command.d.ts:7
Parameters
| Parameter | Type |
|---|---|
host | EditorHost |
commands? | ICommand[] |
description? | string |
Returns
BatchCommand
Overrides
Properties
timestamp
timestamp: number;Defined in: commands/base-command.d.ts:5
Inherited from
description?
optional description?: string;Defined in: commands/base-command.d.ts:6
Inherited from
name
name: string;Defined in: commands/batch-command.d.ts:5
Overrides
Methods
redo()
redo(): void;Defined in: commands/base-command.d.ts:11
Returns
void
Inherited from
mergeWith()?
optional mergeWith(command): ICommand;Defined in: commands/base-command.d.ts:13
Parameters
| Parameter | Type |
|---|---|
command | ICommand |
Returns
Inherited from
execute()
execute(): void;Defined in: commands/batch-command.d.ts:8
Returns
void
Overrides
undo()
undo(): void;Defined in: commands/batch-command.d.ts:9
Returns
void
Overrides
addCommand()
addCommand(command): void;Defined in: commands/batch-command.d.ts:10
Parameters
| Parameter | Type |
|---|---|
command | ICommand |
Returns
void
addCommands()
addCommands(commands): void;Defined in: commands/batch-command.d.ts:11
Parameters
| Parameter | Type |
|---|---|
commands | ICommand[] |
Returns
void
getCommands()
getCommands(): ICommand[];Defined in: commands/batch-command.d.ts:12
Returns
ICommand[]
isEmpty()
isEmpty(): boolean;Defined in: commands/batch-command.d.ts:13
Returns
boolean
getDescription()
getDescription(): string;Defined in: commands/batch-command.d.ts:14
Returns
string
canMergeWith()
canMergeWith(command): boolean;Defined in: commands/batch-command.d.ts:15
Parameters
| Parameter | Type |
|---|---|
command | ICommand |
Returns
boolean
Overrides
使用示例
批量添加元素
import { BatchCommand, AddElementCommand } from 'vkedit'
const batch = new BatchCommand()
batch.add(new AddElementCommand({ type: 'rect', x: 0, y: 0, width: 50, height: 30 }))
batch.add(new AddElementCommand({ type: 'rect', x: 60, y: 0, width: 50, height: 30 }))
batch.add(new AddElementCommand({ type: 'rect', x: 120, y: 0, width: 50, height: 30 }))
// 一次执行,一次撤销
host.executeCommand(batch)批量操作场景
- 导入 JSON 时批量添加元素
- 拖拽创建多个元素
- 一键对齐多个元素
- 模板加载时初始化画布
撤销顺序
BatchCommand 撤销时按添加顺序的逆序回滚每个子命令。确保子命令之间无依赖冲突(如先删除后添加同一元素)。