評論

插件信息

先完成產品編輯器與許可證配置,再註冊評論外掛,並載入通用 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-TW'import { LocaleType, mergeLocales } from '@univerjs/core'import SharedLocale from '@univerjs/thread-comment-ui/locale/zh-TW'import '@univerjs/thread-comment-ui/lib/index.css'import '@univerjs-pro/boards-thread-comment-ui/lib/index.css'univerAPI.loadLocales(LocaleType.ZH_TW, 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.