import { TencentQianWebViewConfig } from '../model/TencentQianWebViewConfig';
import { OnSignResult, OnSdkEvent } from '../model/SignCallback';
import { SignResult } from '../model/SignResult';
/**
* 携带的容器入参集合。
*/
export interface IntentBridgePayload {
url: string;
config: TencentQianWebViewConfig;
onSignResult: OnSignResult;
onSdkEvent?: OnSdkEvent;
}
/**
* 全局单例,暂存 `TencentQianWebView.open()` 调用时的 callback / config / url。
*
* 容器页面 `aboutToAppear` 阶段从中拉取参数;二次 open 时旧 payload 会先收到
* `SignResult.EMPTY` 再被覆盖,避免上一次回调丢失。
*/
export class IntentBridge {
private static current: IntentBridgePayload | null = null;
/**
* 设置当前要进入容器页面的 payload。
*
* 如果已有未消费的 payload,先用 `SignResult.EMPTY` 通知旧 callback,再覆盖。
*/
public static set(payload: IntentBridgePayload): void {
const previous: IntentBridgePayload | null = IntentBridge.current;
if (previous !== null) {
try {
previous.onSignResult(SignResult.EMPTY);
} catch (_e) {
// 不影响主流程
}
}
IntentBridge.current = payload;
}
/**
* 取出 payload(消费式)。容器页面拿到后,本桥保留引用直到容器主动 clear,
* 以便后续在同一个容器实例中多次取用。
*/
public static peek(): IntentBridgePayload | null {
return IntentBridge.current;
}
/**
* 清空当前 payload。容器页面 `onPageHide`/`onBackPress` 完成后调用,释放引用。
*/
public static clear(): void {
IntentBridge.current = null;
}
// ArkTS 类禁止实例化
private constructor() {}
}
|