| 1 |
- import{_ as e,ad as i,aF as n,az as t,aG as a,aH as s,G as o,aI as r,aa as l,aC as c,r as u,b as d,d as f,p as g,w as h,H as p,i as y,o as m,f as v,e as b,k,t as L,v as _,F as w,y as C,C as N,R as x}from"./index-2PZN6pGH.js";const I=e({data:()=>({title:"login",providerList:[],phoneNumber:"",univerifyBtnLoading:!1}),computed:{...i(["hasLogin","isUniverifyLogin","univerifyErrorMsg"])},onLoad(){n({service:"oauth",success:e=>{this.providerList=e.provider.map((e=>{let i="";switch(e){case"weixin":i="微信登录";break;case"qq":i="QQ登录";break;case"sinaweibo":i="新浪微博登录";break;case"xiaomi":i="小米登录";break;case"alipay":i="支付宝登录";break;case"baidu":i="百度登录";break;case"jd":i="京东登录";break;case"toutiao":i="头条登录";break;case"apple":i="苹果登录";break;case"univerify":i="一键登录"}return{name:i,id:e}}))},fail:e=>{console.log("获取登录通道失败",e)}}),this.hasLogin&&this.isUniverifyLogin&&this.getPhoneNumber(t("univerifyInfo")).then((e=>{this.phoneNumber=e}))},methods:{...a(["login","setUniverifyLogin"]),...s(["getPhoneNumber"]),Toast(e,i=1e3){o(Object.assign({},e,{duration:i}))},tologin(e){"univerify"===e.id&&(this.univerifyBtnLoading=!0),r({provider:e.id,success:async i=>{console.log("login success:",i),this.Toast({title:"登录成功"}),this.login(e.id)},fail:e=>{if(console.log("login fail:",e),"30002"==e.code)return uni.closeAuthView(),void this.Toast({title:"其他登录方式"});1e3!=e.code?"30005"!=e.code?"30003"!=e.code&&l({showCancel:!1,title:"登录失败",content:JSON.stringify(e)}):l({showCancel:!1,title:"预登录失败",content:this.univerifyErrorMsg||e.errMsg}):l({title:"登录失败",content:`${e.errMsg}\n,错误码:${e.code}`,confirmText:"开通指南",cancelText:"确定",success:e=>{e.confirm&&setTimeout((()=>{plus.runtime.openWeb("https://ask.dcloud.net.cn/article/37965")}),500)}})},complete:()=>{this.univerifyBtnLoading=!1}})},loginByUniverify(e,i){this.setUniverifyLogin(!0),uni.closeAuthView();const n={provider:e,...i.authResult};this.getPhoneNumber(n).then((e=>{this.phoneNumber=e,c("univerifyInfo",n)})).catch((e=>{l({showCancel:!1,title:"手机号获取失败",content:`${e.errMsg}\n,错误码:${e.code}`}),console.error(i)}))},async loginByApple(e,i){let n,t;try{t=await uni.getUserInfo({provider:e})}catch(a){n=a}if(n){let e=n.errMsg;~e.indexOf("uni.login")&&(e="请在登录页面完成登录操作"),l({title:"获取用户信息失败",content:"错误原因"+e,showCancel:!1})}console.warn("此处使用uni-id处理苹果登录,详情参考: https://uniapp.dcloud.net.cn/uniCloud/uni-id"),u({url:"https://97fca9f2-41f6-449f-a35e-3f135d4c3875.bspapp.com/http/user-center",method:"POST",data:{action:"loginByApple",params:t.userInfo},success:e=>{console.log("uniId login success",e),0!==e.data.code?l({showCancel:!1,content:`苹果登录失败: ${JSON.stringify(e.data.msg)}`}):(c("openid",e.data.openid),c("apple_nickname",e.data.userInfo.nickname))},fail:e=>{l({content:`苹果登录失败: ${JSON.stringify(e)}`,showCancel:!1})}})}}},[["render",function(e,i,n,t,a,s){const o=d(f("page-head"),p),r=N,l=y,c=x;return m(),g(l,null,{default:h((()=>[v(o,{title:a.title},null,8,["title"]),v(l,{class:"uni-padding-wrap"},{default:h((()=>[v(l,{style:{background:"#FFF",padding:"40rpx"}},{default:h((()=>[!0===e.hasLogin?(m(),b(w,{key:0},[v(l,{class:"uni-h3 uni-center uni-common-mt"},{default:h((()=>[k("已登录 "),e.isUniverifyLogin?(m(),g(r,{key:0,style:{"font-size":"0.8em"}},{default:h((()=>[a.phoneNumber.length?(m(),b("i",{key:1},"("+L(a.phoneNumber)+")",1)):(m(),b("i",{key:0,class:"uni-icon_toast uni-loading"}))])),_:1})):_("",!0)])),_:1}),v(l,{class:"uni-hello-text uni-center"},{default:h((()=>[v(r,null,{default:h((()=>[k("每个账号仅需登录 1 次,\\n后续每次进入页面即可自动拉取用户信息。")])),_:1})])),_:1})],64)):_("",!0),!1===e.hasLogin?(m(),b(w,{key:1},[v(l,{class:"uni-h3 uni-center uni-common-mt"},{default:h((()=>[k("未登录")])),_:1}),v(l,{class:"uni-hello-text uni-center"},{default:h((()=>[k(" 请点击按钮登录 ")])),_:1})],64)):_("",!0)])),_:1}),v(l,{class:"uni-btn-v uni- uni-common-mt"},{default:h((()=>[(m(!0),b(w,null,C(a.providerList,((e,i)=>(m(),g(c,{type:"primary",class:"page-body-button",onClick:i=>s.tologin(e),loading:"univerify"===e.id&&a.univerifyBtnLoading,key:i},{default:h((()=>[k(L(e.name),1)])),_:2},1032,["onClick","loading"])))),128))])),_:1})])),_:1})])),_:1})}],["__scopeId","data-v-7d511e1e"]]);export{I as default};
|