20 lines
844 B
TypeScript
20 lines
844 B
TypeScript
type OutgoingCallGuard = (callType: number) => Promise<void>
|
|
|
|
// 通话 SDK 为全局单例;使用当前窗口的校验器,避免首个组件闭包保留旧患者类型。
|
|
let activeGuard: OutgoingCallGuard | undefined
|
|
|
|
export function registerAppointmentCallGuard(guard: OutgoingCallGuard): () => void {
|
|
activeGuard = guard
|
|
return () => {
|
|
if (activeGuard === guard) activeGuard = undefined
|
|
}
|
|
}
|
|
|
|
export async function checkAppointmentOutgoingCall(params: unknown): Promise<void> {
|
|
const guard = activeGuard
|
|
if (!guard) throw new Error('请先打开本次挂号的聊天窗口')
|
|
const type = params && typeof params === 'object' && 'type' in params ? Number(params.type) : 2
|
|
await guard(type === 1 ? 1 : 2)
|
|
if (activeGuard !== guard) throw new Error('当前问诊已切换,请重新发起通话')
|
|
}
|