Home > DMT_Workspace > toggleToWorkspace
DMT_Workspace.toggleToWorkspace() method
切换到工作区
签名
typescript
function toggleToWorkspace(workspaceUuid?: string): Promise<boolean>;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
workspaceUuid | string | (可选) 工作区 UUID,如若不指定,则将切换到个人工作区 |
返回值
Promise<boolean>
切换操作是否成功
示例
javascript
// 1. 记录切换前的工作区(演示结束后切回,恢复现场)
const before = await eda.dmt_Workspace.getCurrentWorkspaceInfo();
// 2. 获取所有工作区,选一个非当前的作为切换目标;只有当前一个时切换自身
const workspaces = await eda.dmt_Workspace.getAllWorkspacesInfo();
const target = workspaces.find(ws => ws.uuid !== before.uuid) || before;
// 3. 切换到目标工作区
const toggled = await eda.dmt_Workspace.toggleToWorkspace(target.uuid);
console.log('切换是否成功:', toggled);
// 4. 回读当前工作区,确认已切换到目标
const now = await eda.dmt_Workspace.getCurrentWorkspaceInfo();
console.log('切换后工作区:', now.name, 'uuid:', now.uuid);
// 5. 切回原工作区,恢复现场
const restored = await eda.dmt_Workspace.toggleToWorkspace(before.uuid);
console.log('切回是否成功:', restored);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18