Browse Source

Merge branch 'develop-medou' of ssh://47.106.79.88:10022/1hjz-3N/1hjz-mini

feature/v1.1.0
luobz 7 years ago
parent
commit
431c1e6e68
3 changed files with 44 additions and 22 deletions
  1. 21
      app.js
  2. 7
      pages/index/index.js
  3. 38
      pages/login/login.js

21
app.js

@ -10,25 +10,7 @@ App({
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
getApp().globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (getApp().userInfoReadyCallback) {
getApp().userInfoReadyCallback(res)
}
}
})
}
}
})
// 登录
wx.login({
success: res => {
@ -75,6 +57,7 @@ App({
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
console.log("userInfo" + res.userInfo)
// 可以将 res 发送给后台解码出 unionId
that.globalData.userInfo = res.userInfo;
// this.onLoginUser();

7
pages/index/index.js

@ -26,7 +26,7 @@ Page({
img1: '/images/title-icon.png',
cityId: 440100000,
typeNum: 10,
addrArray: { id: [440100000, 430426000], name: ['广州', '深圳', '上海', '长沙', '武汉', '杭州', '北京'] },
addrArray: { id: [440100000, 430426000], name: ['长沙', '深圳', '上海', '长沙', '武汉', '杭州', '北京'] },
addrIndex: 0,
},
/**
@ -48,7 +48,7 @@ Page({
url: app.gw.hostUrl + '/mall/wxa/activity/banner',
method: 'get',
data: {
merchantNo: 2
merchantNo: 'SH180331153109966163'
},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
@ -88,7 +88,8 @@ Page({
url: app.gw.hostUrl + '/mall/wxa/activity/list',
method: 'get',
data: {
selectedCityId: that.data.addrArray.id[that.data.addrIndex] == undefined ? 0 : that.data.addrArray.id[that.data.addrIndex],
merchantNo: 'SH180331153109966163',
// selectedCityId: that.data.addrArray.id[that.data.addrIndex] == undefined ? 0 : that.data.addrArray.id[that.data.addrIndex],
pageNum: that.data.pageNum,
pageSize: that.data.pageSize
},

38
pages/login/login.js

@ -138,6 +138,7 @@ Page({
success: res => {
// 可以将 res 发送给后台解码出 unionId
app.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (app.userInfoReadyCallback) {
@ -171,6 +172,8 @@ Page({
that.ohShitfadeOut();
return;
}
// 发送 res.code 到后台换取 openId, sessionKey, unionId
that.commitUserInfo(that.globalData.openid, res.encryptedData, res.iv);
app.globalData.sessionId = data.response.sessionId;
wx.setStorageSync('sessionId', data.response.sessionId);
console.log('sessionId : ' + data.response.sessionId);
@ -199,6 +202,41 @@ Page({
}
}
},
commitUserInfo: function (openid, encryptedData, iv) {
var that = this;
wx.request({
url: this.gw.hostUrl + '/mall/wxa/auth/userinfo',
method: 'POST',
data: {
openid: openid,
encryptedData: encryptedData,
iv: iv
},
header: {
'Content-Type': 'application/x-www-form-urlencoded',
},
success: function (res) {
//--init data
var data = res.data;
var status = data.code;
if (status != 0) {
wx.showToast({
title: data.msg,
icon: 'none',
duration: 3000
});
return false;
}
},
fail: function (e) {
wx.showToast({
title: '网络异常!err:authlogin',
icon: 'none',
duration: 2000
});
},
});
},
onLoad: function (options) {
if (app.globalData.userInfo) {
this.setData({

Loading…
Cancel
Save