WXL
15 小时以前 05c363fdd7ab04e3bd9a753e2c5d5bfff04d681c
1
"use strict";const e=require("../../common/vendor.js"),o=require("../../common/assets.js"),n=require("../../stores/user.js"),t=require("../../utils/auth.js"),s=require("../../utils/crypto.js");if(!Array){(e.resolveComponent("uni-load-more")+e.resolveComponent("uni-icons"))()}Math||((()=>"../../node-modules/@dcloudio/uni-ui/lib/uni-load-more/uni-load-more.js")+(()=>"../../node-modules/@dcloudio/uni-ui/lib/uni-icons/uni-icons.js"))();const i={__name:"Login",setup(i){let a=!1,r=!1;const d=e.ref(""),l=e.ref(""),c=e.ref(!1),u=e.ref(""),g=["/pages/index/index","/pages/appointment/index","/pages/consultation/index","/pages/my/index"];e.onLoad(async o=>{console.log("登录页onLoad,原始参数:",o);const n={...e.index.getLaunchOptionsSync().query||{},...o};console.log("合并后参数:",n),n.redirect&&(u.value=decodeURIComponent(n.redirect));const s=n.code;if(s){console.log("检测到免登码,开始解析:",s),e.index.showLoading({title:"解析免登信息...",mask:!0});try{const o=await e.index.$uapi.get("/GiLink/getCode",{code:s});if(e.index.hideLoading(),console.log(o.data),o.data.passWord=o.data.userPhone,!o.data||!o.data.userName||!o.data.passWord)throw new Error("解析免登码失败");let n=JSON.parse(o.data.extContent);console.log(o.data.userName);const i=o.data.userName,a=o.data.passWord,r={id:n.infoId,type:n.type,status:n.status,fcid:n.id};console.log("解析结果:",{userName:i,otherParams:r}),t.getToken()&&e.index.removeStorageSync("token"),await p(i,a,r)}catch(i){e.index.hideLoading(),console.error("免登码解析失败:",i),e.index.showToast({title:"免登录失败,请手动登录",icon:"none"})}}else t.getToken()?setTimeout(()=>m(),100):(d.value="",l.value="")}),e.onShow(()=>{r&&(r=!1)});const p=async(o,s,i={})=>{var d;if(!a){a=!0,console.log("开始SSO免登:",{userName:o,pageParams:i}),e.index.showLoading({title:"自动登录中...",mask:!0});try{const a=await e.index.$uapi.post("/getToken",{userName:o,passWord:s});if(e.index.hideLoading(),!(null==(d=a.data)?void 0:d.token))throw new Error("获取token失败");t.setToken(a.data.token);const l=n.useUserStore(),c=await e.index.$uapi.get("/getInfo");c&&c.user&&(l.setUserInfo(c.user),c.roles&&l.setroleKey(c.roles));let g=u.value;if(!g){const o=e.index.getLaunchOptionsSync().path;o&&!o.includes("login/Login")&&(g="/"+o)}g||(g="/pages/index/index"),r=!0,await h(g,i)}catch(l){e.index.hideLoading(),console.error("SSO免登失败:",l),e.index.showToast({title:l.message||"自动登录失败,请手动登录",icon:"none",duration:3e3}),e.index.removeStorageSync("token")}finally{a=!1}}},x=async()=>{try{if(!d.value||!l.value)return void e.index.showToast({title:"请输入账号密码",icon:"none"});e.index.showLoading({title:"登录中...",mask:!0});const o=n.useUserStore(),i=s.encrypt(l.value),a=s.encrypt(d.value),r=await e.index.$uapi.post("/login",{username:a,password:i});if(!r||!r.token)throw new Error("登录失败");t.setToken(r.token);const c=await e.index.$uapi.get("/getInfo");c&&c.user&&(o.setUserInfo(c.user),c.roles&&o.setroleKey(c.roles)),e.index.hideLoading(),await m()}catch(o){e.index.hideLoading(),console.error("登录失败:",o),e.index.showToast({title:o.message||"登录失败",icon:"none",duration:3e3})}},m=()=>u.value?h(u.value,{}):(console.log("没有目标页面,跳转首页"),e.index.switchTab({url:"/pages/index/index"}),Promise.resolve(!0)),h=(o,n={})=>new Promise(t=>{if(!o)return console.log("目标页为空,跳转首页"),e.index.switchTab({url:"/pages/index/index"}),void t(!0);let s=o;const i=Object.keys(n).filter(e=>void 0!==n[e]&&null!==n[e]);if(i.length>0){const e=i.map(e=>`${e}=${encodeURIComponent(n[e])}`).join("&");s+=(s.includes("?")?"&":"?")+e+"&sso=1"}console.log("最终跳转目标URL:",s);const a=s.split("?")[0],r=g.includes(a);setTimeout(()=>{r?e.index.switchTab({url:a,success:()=>t(!0),fail:o=>{console.error("switchTab失败:",o),e.index.switchTab({url:"/pages/index/index"}),t(!1)}}):e.index.redirectTo({url:s,success:()=>t(!0),fail:o=>{console.error("redirectTo失败:",o),e.index.switchTab({url:"/pages/index/index"}),t(!1)}})},300)});return(n,t)=>e.e({a:e.unref(a)},e.unref(a)?{b:e.p({status:"loading","content-text":{contentdown:"自动登录中..."}})}:{},{c:o._imports_0,d:e.p({type:"contact",size:"24",color:"#409EFF"}),e:d.value,f:e.o(e=>d.value=e.detail.value),g:e.p({type:"locked",size:"24",color:"#409EFF"}),h:!c.value,i:l.value,j:e.o(e=>l.value=e.detail.value),k:e.o(e=>c.value=!c.value),l:e.p({type:c.value?"eye":"eye-slash",size:"22",color:"#999"}),m:d.value&&l.value?1:"",n:e.o(x),o:e.gei(n,"")})}},a=e._export_sfc(i,[["__scopeId","data-v-5d8fc369"]]);wx.createPage(a);