评论

插件信息

先完成产品编辑器与许可证配置,再注册评论插件,并加载通用 UI 与产品 UI 的样式和语言资源。评论资源由产品插件自身管理,因此恢复快照前必须先注册该插件。

Shell
pnpm add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/boards-thread-comment @univerjs-pro/boards-thread-comment-ui
TypeScript
import { UniverBoardsThreadCommentPlugin } from '@univerjs-pro/boards-thread-comment'import { UniverBoardsThreadCommentUIPlugin } from '@univerjs-pro/boards-thread-comment-ui'import ProductLocale from '@univerjs-pro/boards-thread-comment-ui/locale/zh-CN'import { LocaleType, mergeLocales } from '@univerjs/core'import SharedLocale from '@univerjs/thread-comment-ui/locale/zh-CN'import '@univerjs/thread-comment-ui/lib/index.css'import '@univerjs-pro/boards-thread-comment-ui/lib/index.css'univerAPI.loadLocales(LocaleType.ZH_CN, mergeLocales(SharedLocale, ProductLocale))univer.registerPlugin(UniverBoardsThreadCommentPlugin)univer.registerPlugin(UniverBoardsThreadCommentUIPlugin)

移动端适配

先完成移动端编辑器的配置。在本页介绍的插件模式初始化代码中,将下表的桌面端注册替换为同一个包导出的移动端插件,并且必须在打开文档前完成替换。模型插件、样式、语言包与 Facade 导入都要保留,两个版本不能同时注册。

来源包桌面端注册移动端注册
@univerjs-pro/boards-thread-comment-uiUniverBoardsThreadCommentUIPluginUniverBoardsThreadCommentMobileUIPlugin

评论 Facade

调用这些方法之前,需要同时导入通用评论 Facade 与产品 Facade。产品侧方法负责建立稳定锚点,回复、修改、解决与删除评论由通用 API 处理。getComments() 读取本地状态;listCommentsAsync() 通过已配置的数据源同步已知线程,不会发现服务端的全部线程。

TypeScript
import '@univerjs/thread-comment/facade'import '@univerjs-pro/boards-thread-comment/facade'const board = univerAPI.getActiveBoard()if (board) {  await board.createPositionCommentAsync({ x: 320, y: 180 }, 'Review this area.')  console.log(await board.listCommentsAsync())}
TypeScript
import '@univerjs/thread-comment/facade'const [thread] = univerAPI.getComments({ resolved: false })if (thread) {  await univerAPI.replyCommentAsync({    unitId: thread.unitId,    subUnitId: thread.subUnitId,    threadId: thread.threadId,    content: 'Reviewed.',  })}

共享讨论

共享讨论需要先通过 Server SDK 接入 Comment Service 与 Endpoint,并在协同与许可证配置完成后注册 @univerjs-pro/thread-comment-datasource 中的 UniverThreadCommentDataSourcePlugin。内置数据源会请求 /universer-api/comment/unit/{unitId}/... 与 /universer-api/user/list,这些路由需要由应用对外暴露。评论的读写权限需要在服务端单独控制,文档编辑权限不覆盖该权限。

你觉得这篇文档如何?

© 2026 DreamNum Co., Ltd.