Tab 工作区
import { RenderTabbedWorkspace, RenderText, TabbedDocumentManager } from 'ds-ui'
Tab 工作区用于承载多个可切换业务页面。每个 tab 都应该有独立内容、独立页面上下文和独立生命周期。
核心对象
RenderTabbedWorkspace:负责显示 tab 和当前内容。TabbedDocumentManager:负责打开、激活、更新、关闭文档。TabbedDocumentDefinition:描述一个要打开的文档。
打开文档
const manager = new TabbedDocumentManager()const workspace = new RenderTabbedWorkspace({ manager }) manager.openDocument({ tabId: 'patients', title: '患者列表', content: new RenderText('患者列表页面'), contextValues: { pageName: 'patients', }, disposeContextOnClose: true,})
当 disposeContextOnClose 为 true 时,tab 关闭时会释放该 tab 的上下文。
生命周期
tab 内容如果实现了相关生命周期接口,可以接收:
- 文档激活。
- 文档失活。
- 文档关闭前确认。
- 文档上下文附加和解除。
业务页面可以利用这些时机刷新命令状态、暂停定时器、处理脏数据确认。
脏状态
文档有未保存修改时,应更新 dirty 状态并在关闭前确认。
const manager = new TabbedDocumentManager() manager.openDocument({ tabId: 'order-1', title: '医嘱 1', content: new RenderText('医嘱编辑'), dirty: true, beforeClose: () => true,})
使用建议
- tabId 必须稳定,避免同一业务对象重复打开多个 tab。
- 页面级命令和上下文跟随 tab 生命周期,不放到全局。
- 关闭 tab 时释放上下文、业务 controller、订阅和缓存。
- 如果支持浮动 tab,浮动窗口仍然应该携带原 tab 的上下文。