login.js 3.5 KB

1
  1. "use strict";var e=require("../../common/vendor.js"),c=require("../../api/user.js");require("../../common/request.js");const d=()=>"../components/wxAuth.js",h={components:{wxAuth:d},data(){return{wxShow:!1,isAgreement:!1,code:null}},computed:{},onLoad(n){e.index.$on("refreshLogin",()=>{e.index.navigateBack({delta:1})}),this.getCode()},onUnload(){},mounted(){},methods:{updateUser(){this.wxShow=!1,e.index.$emit("refreshLogin"),e.index.$emit("refreshIM")},wxAuthOpen(){this.wxShow=!0;var n=this;setTimeout(function(){n.$refs.wxauth.getUserInfo()})},wxAuthClose(){this.wxShow=!1},wxLogin(n){var s=this;if(!this.isAgreement)return e.index.showToast({icon:"none",title:"\u8BF7\u5148\u540C\u610F\u534F\u8BAE\u540E\u518D\u767B\u5F55"}),!1;e.index.showLoading({title:"\u5904\u7406\u4E2D..."}),s.$getProvider().then(i=>{console.log("\u5F53\u524D\u7684\u73AF\u5883\u5546",i),i||reject(),e.index.login({provider:i,success:async a=>{console.log(111),console.log(n),console.log(a)}})}).catch(i=>{e.index.showToast({icon:"none",title:i})})},handleAgree(){this.isAgreement||e.index.showToast({icon:"none",title:"\u8BF7\u5148\u540C\u610F\u534F\u8BAE\u540E\u518D\u767B\u5F55"})},openContent(n){console.log(n),e.index.navigateTo({url:"/pages_user/agreement?type="+n})},handleAgreement(){this.isAgreement=!this.isAgreement},getCode(){var n=this;n.$getProvider().then(s=>{s||reject(),e.index.login({provider:s,success:async i=>{n.code=i.code}})}).catch(s=>{})},phoneLogin(n){var s=this;e.index.showLoading({title:"\u5904\u7406\u4E2D"}),console.log(n),n.detail.errMsg=="getPhoneNumber:ok"?this.$getProvider().then(i=>{console.log("\u5F53\u524D\u7684\u73AF\u5883\u5546",i),i||reject(),e.index.login({provider:i,success:async a=>{console.log(a);let r=a.code;var t=e.index.getStorageSync("tuiUserId");c.wxLogin({encryptedData:n.detail.encryptedData,iv:n.detail.iv,code:r,tuiUserId:t}).then(o=>{e.index.hideLoading(),o.code==200?(e.index.showToast({icon:"none",title:"\u767B\u5F55\u6210\u529F"}),e.index.setStorageSync("AppToken",o.token),e.index.setStorageSync("userId",o.user.userId),e.index.setStorageSync("avatar",o.user.avatar),e.index.setStorageSync("nickName",o.user.nickName),o.user.isWeixinAuth==0?s.wxAuthOpen():(e.index.$emit("refreshLogin"),e.index.$emit("refreshIM"))):e.index.showToast({icon:"none",title:"\u6388\u6743\u767B\u5F55\u5931\u8D25,\u8BF7\u91CD\u65B0\u767B\u5F55"})}).catch(o=>{console.log(o),e.index.hideLoading(),e.index.showToast({icon:"none",title:"\u6388\u6743\u767B\u5F55\u5931\u8D25,\u8BF7\u91CD\u65B0\u767B\u5F55"})})}})}).catch(i=>{}):e.index.showToast({title:"\u5DF2\u62D2\u7EDD\u6388\u6743",icon:"none",duration:2e3})},back(){e.index.reLaunch({url:"/pages/index/index",animationType:"pop-in",animationDuration:100})}}};if(!Array){const n=e.resolveComponent("wx-auth"),s=e.resolveComponent("u-popup");(n+s)()}const u=()=>"../../uni_modules/uview-plus/components/u-popup/u-popup.js";Math||u();function l(n,s,i,a,r,t){return e.e({a:e.o((...o)=>t.phoneLogin&&t.phoneLogin(...o)),b:r.isAgreement==!1},r.isAgreement==!1?{c:e.o(o=>t.handleAgree())}:{},{d:e.o((...o)=>t.back&&t.back(...o)),e:r.isAgreement,f:e.o(o=>t.handleAgreement()),g:e.o(o=>t.handleAgreement()),h:e.o(o=>t.openContent("userRegister")),i:e.o(o=>t.openContent("userPrivacy")),j:e.sr("wxauth","30a821bf-1,30a821bf-0"),k:e.o(o=>t.updateUser()),l:e.o(t.wxAuthClose),m:e.o(t.wxAuthOpen),n:e.p({bgColor:"#f6f6f6",safeAreaInsetBottom:!1,round:15,mode:"bottom",show:r.wxShow})})}var g=e._export_sfc(h,[["render",l],["__file","D:/work/his_user_app/pages/auth/login.vue"]]);wx.createPage(g);