评论

插件信息

评论插件应在品类编辑器和许可证配置完成后注册,同时加载通用和品类 UI 的样式与语言资源。评论资源由对应的品类插件管理,因此恢复快照前必须先注册该插件。

Shell
pnpm add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-ui
TypeScript
import { UniverSlidesThreadCommentPlugin } from '@univerjs-pro/slides-thread-comment'import { UniverSlidesThreadCommentUIPlugin } from '@univerjs-pro/slides-thread-comment-ui'import ProductLocale from '@univerjs-pro/slides-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/slides-thread-comment-ui/lib/index.css'univerAPI.loadLocales(LocaleType.ZH_CN, mergeLocales(SharedLocale, ProductLocale))univer.registerPlugin(UniverSlidesThreadCommentPlugin)univer.registerPlugin(UniverSlidesThreadCommentUIPlugin)

移动端适配

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

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

评论 Facade

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

TypeScript
import '@univerjs/thread-comment/facade'import '@univerjs-pro/slides-thread-comment/facade'const element = univerAPI.getActivePresentation()?.getSlideByIndex(0)?.getElements()[0]if (element) {  await element.createCommentAsync('Please review this element.')  console.log(await element.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.