2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
|
|
import{r as e,d as a,a as t,b as l,c as s,o as n,e as i,f as o,g as c,w as u,h as r,i as d,v as m,j as A,k as p,n as v,t as f,l as g,m as h,p as I,F as y,s as C,q as b,u as k,x as R,y as Q,z as E,I as j,A as z,S as Z,B as w}from"./index-l07Qi7HW.js";import V from"./pages-config-config.Cz8Cvl85.js";import B from"./pages-profile-profile.BPoARpOQ.js";import{_ as G}from"./_plugin-vue_export-helper.BCo6x5W8.js";import"./scenario.DdRRs4cZ.js";import"./config-doctor.TgARj_nM.js";import"./chat.BVa8UJ4F.js";import"./navigation.C4wbrbVp.js";import"./pages-diagnosis-diagnosis.B6vW77us.js";import"./pages-treatment-treatment.BEP7wWAJ.js";import"./pages-assessment-assessment.CXwqU_Dk.js";import"./pages-home-home.T96f--U4.js";import"./pages-learning-assistant-learning-assistant.CkPahlHl.js";import"./pages-matching-matching.BBQIQDw4.js";import"./pages-cases-cases.DPF5hQUU.js";import"./pages-teaching-teaching.BU6p5d1L.js";class N extends Error{constructor(e,a,t){super(e),this.name="ApiRequestError",this.code=a,this.statusCode=t}}function O(a,t,l="POST"){return new Promise(((s,n)=>{e({url:`/server/api${a}`,method:l,timeout:1e4,header:{"Content-Type":"application/json"},data:t,success:e=>{if(e.statusCode>=200&&e.statusCode<300)return void s(e.data);const a=e.data,t="string"==typeof(null==a?void 0:a.code)?a.code:void 0;n(new N(function(e,a){if(e&&"object"==typeof e){const a=e,t=a.message||a.detail||a.error;if("string"==typeof t&&t.trim())return t}return a}(e.data,`请求失败(${e.statusCode})`),t,e.statusCode))},fail:e=>{n(new N(e.errMsg||"无法连接服务"))}})}))}function Y(e,a="login"){return O("/user/auth/send-code/",{phone:e,scene:a})}function D(e){return O("/user/auth/login-code/",e).then((e=>{if(function(e){if(!e||"object"!=typeof e)return!1;const a=e,t=a.tokens;return Boolean(a.tokens&&"string"==typeof(null==t?void 0:t.access)&&"string"==typeof(null==t?void 0:t.refresh))}(e))return e;throw new Error("登录接口返回数据格式异常")}))}const J=G(a({__name:"index",setup(e){const a=t([]),G=l({phone:"",code:"",institutionId:""}),J=t(""),F=t(!1),S=t(!1),T=t(!1),L=t(!1),U=t(0),W=t(""),x=t(!1),M=t(!1),H=t(!1),P=t(!1),X=t(!1),q=t(!1);let K=null,_=null;const $=s((()=>a.value.find((e=>e.id===G.institutionId)))),ee=s((()=>U.value>0)),ae=s((()=>T.value?"发送中...":ee.value?`${U.value}s`:"获取验证码"));function te(e){const a=[e.province,e.city].filter(Boolean).join(" · ");return{id:String(e.id),code:e.code,name:e.name,city:a||"其他",typeName:{hospital:"医院",college:"医学院校",school:"学校",clinic:"诊所"}[e.type]||"机构"}}async function le(){X.value=!0;try{const e=await O("/user/institution_list/",null,"GET");a.value=e.map(te)}catch(e){re(e instanceof Error?e.message:"机构列表加载失败"),a.value=[]}finally{X.value=!1,q.value=!0}}function se(){F.value=!F.value}async function ne(){if(!T.value&&!ee.value&&oe()){T.value=!0;try{let a;try{a=await Y(G.phone)}catch(e){if(!(e instanceof N&&"AUTH_PHONE_NOT_FOUND"===e.code))throw e;a=await Y(G.phone,"register")}re(a.message||"验证码已发送"),U.value=60,de(),K=setInterval((()=>{U.value-=1,U.value<=0&&de()}),1e3)}catch(e){re(e instanceof Error?e.message:"验证码发送失败")}finally{T.value=!1}}}function ie(){if(!L.value&&oe())if(G.code.trim())if($.value){if(!F.value)return re("请阅读并勾选用户协议"),S.value=!1,void b((()=>{S.value=!0,setTimeout((()=>{S.value=!1}),500)}));L.value=!0,D({phone:G.phone,code:G.code,institution_code:$.value.code,institution_name:$.value.name}).then((e=>{var a,t,l;const s=e.user||{},n={...s,id:s.id?String(s.id):"",phone:s.phone||G.phone,institutionId:(null==(a=$.value)?void 0:a.code)||"",institutionCode:(null==(t=$.value)?void 0:t.code)||"",institutionName:(null==(l=$.value)?void 0:l.name)||""};C("clinical-thinking-user",n),C("clinical-thinking-tokens",e.tokens),C("clinical-thinking-access-token",e.tokens.access),C("clinical-thinking-refresh-token",e.tokens.refresh),re(e.message||"正在进入系统..."),M.value=!0})).catch((e=>{re(e instanceof Error?e.message:"登录失败,请稍后重试")})).finally((()=>{L.value=
|