Commit 092c8af0 authored by linlinjava's avatar linlinjava
Browse files

chore[litemall-wx, renard-wx]]:登录接口调整

parent 4514653a
// 以下是业务服务器API地址 // 以下是业务服务器API地址
// 本机开发时使用 // 本机开发时使用
// var WxApiRoot = 'http://localhost:8080/wx/'; var WxApiRoot = 'http://localhost:8080/wx/';
// 局域网测试使用 // 局域网测试使用
var WxApiRoot = 'http://192.168.1.3:8080/wx/'; // var WxApiRoot = 'http://192.168.1.3:8080/wx/';
// 云平台部署时使用 // 云平台部署时使用
// var WxApiRoot = 'http://122.51.199.160:8080/wx/'; // var WxApiRoot = 'http://122.51.199.160:8080/wx/';
// 云平台上线时使用 // 云平台上线时使用
......
...@@ -4,10 +4,17 @@ var user = require('../../../utils/user.js'); ...@@ -4,10 +4,17 @@ var user = require('../../../utils/user.js');
var app = getApp(); var app = getApp();
Page({ Page({
data: {
canIUseGetUserProfile: false,
},
onLoad: function(options) { onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数 // 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成 // 页面渲染完成
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
}, },
onReady: function() { onReady: function() {
...@@ -24,11 +31,29 @@ Page({ ...@@ -24,11 +31,29 @@ Page({
}, },
wxLogin: function(e) { wxLogin: function(e) {
user.checkLogin().catch(() => { if (this.data.canIUseGetUserProfile) {
wx.getUserProfile({ wx.getUserProfile({
desc: '用于完善会员资料', desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => { success: (res) => {
user.loginByWeixin(res.userInfo).then(res => { this.doLogin(res.userInfo)
},
fail: () => {
util.showErrorToast('微信登录失败');
}
})
}
else {
if (e.detail.userInfo == undefined) {
app.globalData.hasLogin = false;
util.showErrorToast('微信登录失败');
return;
}
this.doLogin(e.detail.userInfo)
}
},
doLogin: function(userInfo) {
user.checkLogin().catch(() => {
user.loginByWeixin(userInfo).then(res => {
app.globalData.hasLogin = true; app.globalData.hasLogin = true;
wx.navigateBack({ wx.navigateBack({
delta: 1 delta: 1
...@@ -37,8 +62,7 @@ Page({ ...@@ -37,8 +62,7 @@ Page({
app.globalData.hasLogin = false; app.globalData.hasLogin = false;
util.showErrorToast('微信登录失败'); util.showErrorToast('微信登录失败');
}); });
}
})
}); });
}, },
accountLogin: function() { accountLogin: function() {
......
<view class="container"> <view class="container">
<view class="login-box"> <view class="login-box">
<button type="primary" open-type="getUserProfile" class="wx-login-btn" bindtap="wxLogin">微信直接登录</button> <button wx:if="{{canIUseGetUserProfile}}" type="primary" class="wx-login-btn" bindtap="wxLogin">微信直接登录</button>
<button wx:else type="primary" open-type="getUserProfile" class="wx-login-btn" open-type="getUserInfo" bindgetuserinfo="wxLogin">微信直接登录</button>
<button type="primary" class="account-login-btn" bindtap="accountLogin">账号登录</button> <button type="primary" class="account-login-btn" bindtap="accountLogin">账号登录</button>
</view> </view>
</view> </view>
\ No newline at end of file
...@@ -4,11 +4,17 @@ var user = require('../../../utils/user.js'); ...@@ -4,11 +4,17 @@ var user = require('../../../utils/user.js');
var app = getApp(); var app = getApp();
Page({ Page({
data: {}, data: {
canIUseGetUserProfile: false,
},
onLoad: function(options) { onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数 // 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成 // 页面渲染完成
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
}, },
onReady: function() { onReady: function() {
...@@ -25,17 +31,30 @@ Page({ ...@@ -25,17 +31,30 @@ Page({
}, },
wxLogin: function(e) { wxLogin: function(e) {
if (this.data.canIUseGetUserProfile) {
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
this.doLogin(res.userInfo)
},
fail: () => {
util.showErrorToast('微信登录失败');
}
})
}
else {
if (e.detail.userInfo == undefined) { if (e.detail.userInfo == undefined) {
app.globalData.hasLogin = false; app.globalData.hasLogin = false;
util.showErrorToast('微信登录失败'); util.showErrorToast('微信登录失败');
return; return;
} }
this.doLogin(e.detail.userInfo)
}
},
doLogin: function(userInfo) {
user.checkLogin().catch(() => { user.checkLogin().catch(() => {
user.loginByWeixin(userInfo).then(res => {
user.loginByWeixin(e.detail.userInfo).then(res => {
app.globalData.hasLogin = true; app.globalData.hasLogin = true;
wx.navigateBack({ wx.navigateBack({
delta: 1 delta: 1
}) })
......
<view class="container"> <view class="container">
<view class="form-box"> <view class="form-box">
<button type="primary" open-type="getUserInfo" class="login-btn" bindgetuserinfo="wxLogin">微信直接登录</button> <button wx:if="{{canIUseGetUserProfile}}" type="primary" class="login-btn" bindtap="wxLogin">微信直接登录</button>
<button wx:else type="primary" open-type="getUserInfo" class="login-btn" bindgetuserinfo="wxLogin">微信直接登录</button>
</view> </view>
</view> </view>
\ No newline at end of file
...@@ -6,7 +6,25 @@ ...@@ -6,7 +6,25 @@
"postcss": true, "postcss": true,
"minified": true, "minified": true,
"newFeature": true, "newFeature": true,
"uglifyFileName": true "uglifyFileName": true,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"useIsolateContext": true,
"useCompilerModule": true,
"userConfirmedUseCompilerModuleSwitch": false,
"userConfirmedBundleSwitch": false,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "2.4.0", "libVersion": "2.4.0",
...@@ -16,22 +34,18 @@ ...@@ -16,22 +34,18 @@
"simulatorPluginLibVersion": {}, "simulatorPluginLibVersion": {},
"condition": { "condition": {
"search": { "search": {
"current": -1,
"list": [] "list": []
}, },
"conversation": { "conversation": {
"current": -1,
"list": [] "list": []
}, },
"plugin": { "plugin": {
"current": -1,
"list": [] "list": []
}, },
"game": { "game": {
"list": [] "list": []
}, },
"miniprogram": { "miniprogram": {
"current": 34,
"list": [ "list": [
{ {
"id": -1, "id": -1,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment