Commit d5ee4979 by luoqi

fix(embed): postMessage 信封补 type:"action" 字段,对齐与宿主约定的契约

契约:{ source:"pac", type:"action", action, payload:{patientId} };此前代码漏了 type。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
parent 2ab6aa38
Pipeline #3354 failed in 0 seconds
......@@ -4,7 +4,9 @@ import { toast } from 'sonner';
import { useAuthStore } from '@/stores/auth-store';
/**
* PAC → 宿主 的动作事件(postMessage)。单向,信封只含 source / action / payload。
* PAC → 宿主 的动作事件(postMessage)。单向,信封:source / type / action / payload。
* { source: 'pac', type: 'action', action, payload: { patientId } }
* (与对接方约定的契约一致 —— type 固定 'action',宿主据 type+source 过滤本类消息。)
*
* 用于"宿主动作是弹窗/组件、没有独立 URL"的场景:PAC 只喊一声 + 带 patientId,
* 宿主父页监听后弹自己的组件。targetOrigin 走 host 配置 actionUrls.HOST_ORIGIN(不允许 '*')。
......@@ -24,7 +26,7 @@ export function postToHost(action: HostAction, patientId: string): boolean {
toast('未配置宿主 Origin', { description: '请在宿主管理页配置 actionUrls.HOST_ORIGIN' });
return false;
}
// 信封:source + action + payload(无 version / doctorId / meta)
window.parent.postMessage({ source: 'pac', action, payload: { patientId } }, origin);
// 信封:source + type + action + payload(契约约定;无 version / doctorId / meta)
window.parent.postMessage({ source: 'pac', type: 'action', action, payload: { patientId } }, origin);
return true;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment