// pages/login/index.js const app = getApp(); const $$ = require('../../utils/util'); // 登录 function loginApi(submitData) { return $$.request({ url: 'paAccount/empower', type: 'post', submitData, service: 'cust', noToken: true }); } Page({ /** * 页面的初始数据 */ data: { imgUrl: $$.url.img, // icon图片地址 }, // 登录,获取用户信息 async handleGetUserInfo() { $$.showLoading(); wx.getUserProfile({ desc: '完善用户信息', complete(res) { if (res.errMsg === 'getUserProfile:ok') { wx.login({ async success(res2) { if (res2.code) { const accountInfo = wx.getAccountInfoSync(); const submitData = { appid: accountInfo.miniProgram.appId, code: res2.code, avatar: res?.userInfo.avatarUrl, encryptedData: res.encryptedData, ivStr: res.iv, }; const res3 = await loginApi(submitData); $$.hideLoading(); if (res3.type) { wx.setStorage({ key: 'userInfo', data: res3.data }); app.globalData.token = res3.data.token; $$.showToast({ title: '登录成功', icon: 'success' }); await $$.sleep(); wx.reLaunch({ url: '../../pages/homePage/index', }); } } else { $$.hideLoading(); $$.showToast('登录失败,请稍后重试'); } }, }); } else { $$.hideLoading(); $$.showToast({ title: '抱歉!授权失败' }); } }, }); }, // 返回首页 handleGoToHomePage() { wx.reLaunch({ url: '../../pages/homePage/index', }); }, });