h5WxLogin.js 1.4 KB

1
  1. "use strict";const n=require("../../common/vendor.js"),a=require("../../api/login.js"),s=require("../../common/assets.js"),d=()=>String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i))==="micromessenger",l={data(){return{code:null}},onLoad(e){this.getWechatCode()},onUnload(){},mounted(){},methods:{loginByMp(){if(this.code==null)return;n.index.showLoading({title:"处理中..."});let e=this;var o={code:this.code};a.loginByWeChat(o).then(t=>{n.index.hideLoading(),t.code==200?(n.index.setStorageSync("AppToken",t.token),n.index.setStorageSync("userInfo",JSON.stringify(t.user)),n.index.$emit("refreshIM"),e.goToLanch()):n.index.showToast({title:t.msg,icon:"none"})},t=>{})},getWechatCode(){if(d){let e="wx9ea36eecd281bcd3",o=this.getUrlCode().code,t=window.location.href;o==null||o===""?window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+e+"&redirect_uri="+encodeURIComponent(t)+"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect":this.code=o}},getUrlCode(){var e=location.search,o=new Object;if(e.indexOf("?")!=-1)for(var t=e.substr(1),i=t.split("&"),r=0;r<i.length;r++)o[i[r].split("=")[0]]=i[r].split("=")[1];return console.log(o),o},goToLanch(){let e=n.index.getStorageSync("beforLoginPage");console.log("beforLoginUrl:"+e),n.index.reLaunch({url:e})}}};function g(e,o,t,i,r,c){return{a:s._imports_0$2,b:n.o(u=>c.loginByMp())}}const h=n._export_sfc(l,[["render",g]]);wx.createPage(h);