Skip to content

本页由脚本自动生成,请勿手动编辑。如需补充说明,请使用 ::: tip 块。

Defined in: commands/batch-command.d.ts:4

Extends

Constructors

Constructor

ts
new BatchCommand(
   host, 
   commands?, 
   description?): BatchCommand;

Defined in: commands/batch-command.d.ts:7

Parameters

ParameterType
hostEditorHost
commands?ICommand[]
description?string

Returns

BatchCommand

Overrides

BaseCommand.constructor

Properties

timestamp

ts
timestamp: number;

Defined in: commands/base-command.d.ts:5

Inherited from

BaseCommand.timestamp


description?

ts
optional description?: string;

Defined in: commands/base-command.d.ts:6

Inherited from

BaseCommand.description


name

ts
name: string;

Defined in: commands/batch-command.d.ts:5

Overrides

BaseCommand.name

Methods

redo()

ts
redo(): void;

Defined in: commands/base-command.d.ts:11

Returns

void

Inherited from

BaseCommand.redo


mergeWith()?

ts
optional mergeWith(command): ICommand;

Defined in: commands/base-command.d.ts:13

Parameters

ParameterType
commandICommand

Returns

ICommand

Inherited from

BaseCommand.mergeWith


execute()

ts
execute(): void;

Defined in: commands/batch-command.d.ts:8

Returns

void

Overrides

BaseCommand.execute


undo()

ts
undo(): void;

Defined in: commands/batch-command.d.ts:9

Returns

void

Overrides

BaseCommand.undo


addCommand()

ts
addCommand(command): void;

Defined in: commands/batch-command.d.ts:10

Parameters

ParameterType
commandICommand

Returns

void


addCommands()

ts
addCommands(commands): void;

Defined in: commands/batch-command.d.ts:11

Parameters

ParameterType
commandsICommand[]

Returns

void


getCommands()

ts
getCommands(): ICommand[];

Defined in: commands/batch-command.d.ts:12

Returns

ICommand[]


isEmpty()

ts
isEmpty(): boolean;

Defined in: commands/batch-command.d.ts:13

Returns

boolean


getDescription()

ts
getDescription(): string;

Defined in: commands/batch-command.d.ts:14

Returns

string


canMergeWith()

ts
canMergeWith(command): boolean;

Defined in: commands/batch-command.d.ts:15

Parameters

ParameterType
commandICommand

Returns

boolean

Overrides

BaseCommand.canMergeWith


使用示例

批量添加元素

typescript
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 撤销时按添加顺序的逆序回滚每个子命令。确保子命令之间无依赖冲突(如先删除后添加同一元素)。

基于 MIT 许可发布