// pages/login_page/index.js const { request, serverName } = require('../../utils/services'); const { newRequestFns, newServerName } = require('../../utils/newServices.js'); // const WxParse = require('../../../common/component/wxParse/wxParse.js'); const { Toast, } = require('../../utils/util.js'); const app = getApp(); Page({ /** * 页面的初始数据 */ data: { login_img: "../../imgs/testImg/needLogin.jpg", login_logo: "../../imgs/testImg/logo.png" }, _getUserInfoToLogin: function(e) { console.log(e); Toast.showToast2('loading'); if (e.detail.encryptedData) { // 可以将 res 发送给后台解码出 unionId // app.globalData.userInfo = res.userInfo; // app.globalData.encryptedData = res.encryptedData; // app.globalData.iv = res.iv; let { encryptedData, iv, userInfo } = e.detail; app.globalData.userInfo = userInfo; wx.setStorageSync("userInfo", userInfo) wx.login({ success: res => { let { code } = res; if (code) { wx.request({ url: newServerName + '/wx/user/getLoginSessionKey', data: { encryptedData, iv, code, }, header: { 'content-type': 'application/x-www-form-urlencoded' }, method: 'post', // dataType: 'json', // responseType: 'text', success: res => { if (res.data.code > -1) { let { loginSessionKey } = res.data.data; wx.setStorageSync('token', loginSessionKey) Toast.showToast('tip', '登录成功', success => { wx.navigateBack({ }) }); } else { Toast.showToast('warn', '登录失败,请重试'); } }, fail: res => { Toast.showToast('warn', '登录失败,请重试'); }, complete: res => { Toast.hideLoading(); }, }) } } }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })