diff --git a/packages/@steedos-widgets/liveblocks/README.md b/packages/@steedos-widgets/liveblocks/README.md index 0ab98810c..c87a67fa0 100644 --- a/packages/@steedos-widgets/liveblocks/README.md +++ b/packages/@steedos-widgets/liveblocks/README.md @@ -28,6 +28,18 @@ yarn dev ``` +集成到Steedos记录详情页 + +```json +{ + "type": "rooms-comments", + "className": "flex flex-col m-3 gap-3", + "id": "u:bbb9a7d94945", + "roomId": "objects:${objectName}:{recordId}", + "baseUrl": "${context.rootUrl}" +} +``` + ## Steedos 加载资产包 diff --git a/packages/@steedos-widgets/liveblocks/src/components/Comments.tsx b/packages/@steedos-widgets/liveblocks/src/components/Comments.tsx index d6cc9c413..bdf341da1 100644 --- a/packages/@steedos-widgets/liveblocks/src/components/Comments.tsx +++ b/packages/@steedos-widgets/liveblocks/src/components/Comments.tsx @@ -39,10 +39,12 @@ export const AmisComments = (props: any) => { const [config, setConfig] = useState(configJSON); const [token, setToken] = useState(null); + const fixedBaseUrl = baseUrl || amisData.context?.rootUrl || `${window.location.protocol}//${window.location.host}` + console.log('liveblocks baseUrl:', fixedBaseUrl); + let onDataFilter = null; if (typeof dataFilter === 'string') { - onDataFilter = new Function('config', 'data', 'return (async () => { ' + dataFilter + ' })()') } @@ -69,9 +71,9 @@ export const AmisComments = (props: any) => { return ( { - const authEndpoint = `${baseUrl}/v2/c/auth`; + const authEndpoint = `${fixedBaseUrl}/v2/c/auth`; const headers = { "Content-Type": "application/json", }; @@ -96,7 +98,7 @@ export const AmisComments = (props: any) => { const searchParams = new URLSearchParams( userIds.map((userId) => ["userIds", userId]) ); - const response = await fetch(`${baseUrl}/v2/c/users?${searchParams}`, { + const response = await fetch(`${fixedBaseUrl}/v2/c/users?${searchParams}`, { headers: { "Authorization": `Bearer ${token}` } @@ -114,7 +116,7 @@ export const AmisComments = (props: any) => { // Find a list of users that match the current search term resolveMentionSuggestions={async ({ text = "" }) => { const response = await fetch( - `${baseUrl}/v2/c/users/search?keyword=${encodeURIComponent(text)}`, { + `${fixedBaseUrl}/v2/c/users/search?keyword=${encodeURIComponent(text)}`, { headers: { "Authorization": `Bearer ${token}` } diff --git a/packages/@steedos-widgets/liveblocks/src/metas/Comments.ts b/packages/@steedos-widgets/liveblocks/src/metas/Comments.ts index d1300c770..9c5ebf107 100644 --- a/packages/@steedos-widgets/liveblocks/src/metas/Comments.ts +++ b/packages/@steedos-widgets/liveblocks/src/metas/Comments.ts @@ -62,6 +62,18 @@ export default { }, panelTitle: "设置", panelControls: [ + { + type: "text", + name: "baseUrl", + label: "Base URL", + value: "m-2 flex flex-col gap-y-2" + }, + { + type: "text", + name: "roomId", + label: "Room Id", + value: "m-2 flex flex-col gap-y-2" + }, { type: "text", name: "className",