2 lines
7.7 KiB
JavaScript
2 lines
7.7 KiB
JavaScript
import{o as H,ap as J,E as a,d2 as C,n as P,aq as Q,q as v,r as p,v as c,D as r,bh as X,s as n,L as d,T as h,O as B,K as Y,P as w,w as Z,ae as ee,u as L,cP as N,d3 as O,bB as le,bg as te,p as oe,M as y,d4 as k,d5 as T,d6 as E,d7 as ae,f as V,d8 as A}from"./.pnpm-BGZW0UGg.js";import{u as ne,r as se,_ as ie}from"./index-CeIwrh_6.js";const ce={class:"patient-test"},re={key:0,class:"init-section"},ue={key:1,class:"status"},fe={class:"flex items-center"},ve={class:"mt-2"},de={key:0},ge={key:0,class:"call-actions mt-4"},pe={key:2,id:"call-container",class:"call-container phone-call-shell"},me={key:3,class:"waiting-container"},Ie={key:4,class:"phone-call-kit-host phone-call-kit-host--offscreen","aria-hidden":"true"},_e=H({__name:"patient-call",setup(Ce){const z=ne(),S=oe(()=>z.userInfo),U=y(!1),m=y(!1),D=y(""),t=y(!1),s=y(!1),f=y(null),g=y(null);let I=null;J(()=>{M()});function b(l){try{const e=k.getData(T.CALL,E.CALL_STATUS),u=k.getData(T.CALL,E.CALL_ROLE),i=!!k.getData(T.CALL,E.IS_GROUP),_=t.value;if(e==="calling"&&u===ae.CALLEE){t.value=!0,f.value={isGroup:i,from:l},_||(a.info("检测到待接听的来电,请点击接听"),V({title:"来电提醒",message:"有待接听的视频通话",type:"warning",duration:0,position:"top-right"})),s.value=!1;return}if(e==="connected"){t.value=!1,f.value=null,s.value=!0;return}e==="idle"&&(t.value||s.value)&&(t.value=!1,s.value=!1,f.value=null)}catch(e){console.warn("syncIncomingFromTUIStore:",l,e)}}function x(){b("watch")}function G(){I&&(I(),I=null);const l={[E.CALL_STATUS]:x,[E.CALL_ROLE]:x};try{k.watch(T.CALL,l),I=()=>{try{k.unwatch(T.CALL,l)}catch{}}}catch(e){console.warn("TUIStore.watch 失败:",e)}}const R=()=>{g.value&&clearInterval(g.value);let l=0;const e=90;g.value=setInterval(()=>{l+=1,b("poll"),l>=e&&g.value&&(clearInterval(g.value),g.value=null)},500)},F=({oldStatus:l,newStatus:e})=>{console.log("========================================"),console.log("=== 通话状态变化回调触发 ==="),console.log("oldStatus:",l),console.log("newStatus:",e),console.log("STATUS 常量:",A),console.log("========================================"),e===A.BE_INVITED&&(console.log(">>> 收到来电邀请"),t.value=!0,f.value={oldStatus:l,newStatus:e},V({title:"来电提醒",message:"收到视频通话请求",type:"info",duration:0,position:"top-right"}),a.success("收到来电,请点击接听按钮")),(e===A.CALLING_C2C_VIDEO||e===A.CALLING_GROUP_VIDEO)&&(console.log(">>> 通话已接通"),a.success("通话已接通"),t.value=!1,s.value=!0),e===A.IDLE&&(t.value||s.value)&&(console.log(">>> 通话已结束"),t.value=!1,s.value=!1,f.value=null,a.info("通话已结束"))},M=async()=>{try{U.value=!0;const l=S.value.id;if(!l)throw new Error("未获取到当前用户ID,请重新登录");console.log("=== 开始初始化医疗助理端 ==="),console.log("当前用户ID:",l),a.info("正在获取签名...");const e=await se.get({url:"/tcm.diagnosis/getDoctorSignature",params:{patient_id:l}});if(!e)throw new Error("获取签名失败");const{sdkAppId:u,userId:i,userSig:_}=e;if(D.value=i,console.log("医疗助理签名获取成功:",{userId:i,sdkAppId:u,userSigLength:_.length}),console.log("完整签名信息:",e),a.info("正在初始化通话组件..."),console.log("=== 开始调用 TUICallKitServer.init ==="),!C||typeof C.init!="function")throw new Error("TUICallKitServer 未正确加载,请刷新页面重试");try{await C.init({userID:i,userSig:_,SDKAppID:Number(u)})}catch(o){console.warn("TUICallKitServer.init 出现错误,但继续执行:",o)}console.log("=== TUICallKitServer.init 完成 ===");const K={statusChanged:F,onError:o=>{console.error("=== TUICallKit 错误回调 ===",o),a.error(`通话错误: ${(o==null?void 0:o.message)||"未知错误"}`)},onInvited:o=>{console.log("=== 收到邀请回调 (onInvited) ===",o),a.info("收到通话邀请 (onInvited)")},afterCalling:()=>{console.log("=== afterCalling 回调 ===")}};try{C.setCallback(K)}catch(o){console.warn("设置回调时出现错误,但继续执行:",o)}console.log("回调设置完成"),a.info("等待初始化完成..."),await new Promise(o=>setTimeout(o,2e3)),m.value=!0,await P(),await new Promise(o=>setTimeout(o,300)),G(),b("post-init"),R(),a.success("医疗助理端初始化成功,等待来电..."),console.log("=== 医疗助理端初始化完成 ==="),console.log("userId:",i),console.log("等待来电中..."),console.log("请在医生端发起群组通话,目标用户ID应该是:",i)}catch(l){console.error("=== 初始化失败 ===",l),a.error(l.message||"初始化失败")}finally{U.value=!1}};async function q(){var l;await P(),await new Promise(e=>setTimeout(e,400));try{const e=C;if(typeof e.closeMicrophone=="function")return await e.closeMicrophone(),!0;const u=(l=e.getTUICallEngineInstance)==null?void 0:l.call(e);if(u&&typeof u.closeMicrophone=="function")return await u.closeMicrophone(),!0}catch(e){console.warn("接听后关闭麦克风失败(可在通话条手动关麦):",e)}return!1}const j=async()=>{try{console.log("接听来电"),await C.accept(),a.success("已接听通话"),t.value=!1,s.value=!0,await q()&&a.info("已关闭本地麦克风")}catch(l){console.error("接听失败:",l),a.error(l.message||"接听失败")}},W=async()=>{try{console.log("拒绝来电"),await C.reject(),a.info("已拒绝通话"),t.value=!1,f.value=null}catch(l){console.error("拒绝失败:",l),a.error(l.message||"拒绝失败")}},$=()=>{m.value=!1,D.value="",t.value=!1,s.value=!1,f.value=null};return Q(()=>{g.value&&(clearInterval(g.value),g.value=null),I&&(I(),I=null),m.value&&(t.value=!1,s.value=!1,f.value=null)}),(l,e)=>{const u=X,i=Y,_=Z,K=le,o=te;return v(),p("div",ce,[c(o,null,{header:r(()=>[...e[0]||(e[0]=[n("div",{class:"card-header"},[n("span",null,"医疗助理端 - 接听来电")],-1)])]),default:r(()=>[m.value?w("",!0):(v(),p("div",re,[c(u,{type:"info",closable:!1,class:"mb-4"},{default:r(()=>[n("p",null,[e[1]||(e[1]=n("strong",null,"当前登录用户:",-1)),d(" "+h(S.value.nickname||S.value.name||"未知"),1)]),n("p",null,[e[2]||(e[2]=n("strong",null,"用户ID:",-1)),d(" "+h(S.value.id||"未获取"),1)]),e[3]||(e[3]=n("p",null,[n("strong",null,"状态:"),d(" 正在初始化...")],-1))]),_:1}),U.value?w("",!0):(v(),B(i,{key:0,type:"primary",onClick:M,loading:U.value,size:"large"},{default:r(()=>[...e[4]||(e[4]=[d(" 重新初始化 ",-1)])]),_:1},8,["loading"]))])),m.value?(v(),p("div",ue,[c(u,{type:t.value?"warning":"success",closable:!1},{title:r(()=>[n("div",fe,[c(_,{class:ee(["mr-2",{"animate-pulse":t.value}])},{default:r(()=>[c(L(N))]),_:1},8,["class"]),n("span",null,h(t.value?"收到来电!":"医疗助理端已初始化,等待来电..."),1)])]),default:r(()=>[n("div",ve,[n("p",null,[e[5]||(e[5]=n("strong",null,"医疗助理ID:",-1)),d(" "+h(D.value),1)]),n("p",null,[e[6]||(e[6]=n("strong",null,"状态:",-1)),d(" "+h(t.value?"来电中":"在线"),1)]),t.value&&f.value?(v(),p("p",de,[e[7]||(e[7]=n("strong",null,"通话类型:",-1)),d(" "+h(f.value.isGroup?"群组视频通话":"视频通话"),1)])):w("",!0)])]),_:1},8,["type"]),t.value?(v(),p("div",ge,[c(i,{type:"success",size:"large",onClick:j,icon:L(N)},{default:r(()=>[...e[8]||(e[8]=[d(" 接听 ",-1)])]),_:1},8,["icon"]),c(i,{type:"danger",size:"large",onClick:W},{default:r(()=>[...e[9]||(e[9]=[d(" 拒绝 ",-1)])]),_:1})])):(v(),B(i,{key:1,type:"danger",onClick:$,class:"mt-4"},{default:r(()=>[...e[10]||(e[10]=[d(" 重置 ",-1)])]),_:1}))])):w("",!0),t.value||s.value?(v(),p("div",pe,[c(L(O),{class:"TUICallKit-mobile"})])):m.value?(v(),p("div",me,[c(K,{description:"等待来电中..."},{image:r(()=>[c(_,{size:80,color:"#909399"},{default:r(()=>[c(L(N))]),_:1})]),_:1})])):w("",!0),m.value&&!t.value&&!s.value?(v(),p("div",Ie,[c(L(O),{class:"TUICallKit-mobile"})])):w("",!0)]),_:1})])}}}),we=ie(_e,[["__scopeId","data-v-b7605c86"]]);export{we as default};
|