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

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

parent 4514653a
// 以下是业务服务器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/';
// 云平台上线时使用
......
......@@ -4,10 +4,17 @@ var user = require('../../../utils/user.js');
var app = getApp();
Page({
data: {
canIUseGetUserProfile: false,
},
onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
onReady: function() {
......@@ -24,11 +31,29 @@ Page({
},
wxLogin: function(e) {
user.checkLogin().catch(() => {
if (this.data.canIUseGetUserProfile) {
wx.getUserProfile({
desc: '用于完善会员资料',
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
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;
wx.navigateBack({
delta: 1
......@@ -37,8 +62,7 @@ Page({
app.globalData.hasLogin = false;
util.showErrorToast('微信登录失败');
});
}
})
});
},
accountLogin: function() {
......
<view class="container">
<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>
</view>
</view>
\ No newline at end of file
......@@ -4,11 +4,17 @@ var user = require('../../../utils/user.js');
var app = getApp();
Page({
data: {},
data: {
canIUseGetUserProfile: false,
},
onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
onReady: function() {
......@@ -25,17 +31,30 @@ Page({
},
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) {
app.globalData.hasLogin = false;
util.showErrorToast('微信登录失败');
return;
}
this.doLogin(e.detail.userInfo)
}
},
doLogin: function(userInfo) {
user.checkLogin().catch(() => {
user.loginByWeixin(e.detail.userInfo).then(res => {
user.loginByWeixin(userInfo).then(res => {
app.globalData.hasLogin = true;
wx.navigateBack({
delta: 1
})
......
<view class="container">
<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>
\ No newline at end of file
......@@ -6,7 +6,25 @@
"postcss": true,
"minified": 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",
"libVersion": "2.4.0",
......@@ -16,22 +34,18 @@
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"plugin": {
"current": -1,
"list": []
},
"game": {
"list": []
},
"miniprogram": {
"current": 34,
"list": [
{
"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