wujie应用联调

This commit is contained in:
董宏凯 committed 2026-06-11 17:11:28 +08:00
1 parent 0784f30e23
commit f3ca996116
35 files changed
+1590 -334

No files matched your search

+45
View File
@@ -31,11 +31,29 @@ export interface WujieProps {
/** 嵌入问答:DeerFlow 本地用户名登录。 */
username?: string;
userName?: string;
/** 用户名+密码登录的共享口令(后端开启 username_login.require_password 时校验)。 */
password?: string;
/** 圆桌规划嵌入:任务名称(注入 Step 1 首条用户消息)。 */
taskTitle?: string;
/** 圆桌规划嵌入:任务描述(注入 Step 1 首条用户消息)。 */
taskGoal?: string;
/** 圆桌规划嵌入:指定业务链条 id(直传,跳过业务映射表)。 */
chainId?: string;
/** 圆桌规划嵌入:业务码(可选回退;后端业务映射表查 chainId)。 */
businessCode?: string;
[key: string]: unknown;
}
/** 无界跨实例事件总线(子→父 / 父→子 通信)。 */
interface WujieBus {
$emit?: (event: string, ...args: unknown[]) => void;
$on?: (event: string, handler: (...args: unknown[]) => void) => void;
$off?: (event: string, handler: (...args: unknown[]) => void) => void;
}
interface WujieRuntime {
props?: WujieProps;
bus?: WujieBus;
[key: string]: unknown;
}
@@ -59,6 +77,33 @@ export function readWujieProps(): WujieProps {
return window.$wujie?.props ?? {};
}
/**
* 子→父:通过无界事件总线广播一个事件。父页面用 `bus.$on(event, handler)` 监听。
* 非无界环境 / 总线缺失时静默忽略(返回 false),可安全无条件调用。
*/
export function emitWujieEvent(event: string, payload?: unknown): boolean {
if (typeof window === "undefined") return false;
const emit = window.$wujie?.bus?.$emit;
if (typeof emit !== "function") return false;
emit(event, payload);
return true;
}
/**
* 父→子:订阅无界事件总线上的一个事件。返回取消订阅函数(在 effect cleanup 里调用)。
* 非无界环境 / 总线缺失时返回 no-op,可安全无条件调用。
*/
export function onWujieEvent(
event: string,
handler: (...args: unknown[]) => void,
): () => void {
if (typeof window === "undefined") return () => {};
const bus = window.$wujie?.bus;
if (typeof bus?.$on !== "function") return () => {};
bus.$on(event, handler);
return () => bus.$off?.(event, handler);
}
/**
* 全局读取无界父级注入的 props 的 hook。
*