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,21 +31,38 @@ Page({ ...@@ -24,21 +31,38 @@ 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)
app.globalData.hasLogin = true; },
wx.navigateBack({ fail: () => {
delta: 1 util.showErrorToast('微信登录失败');
})
}).catch((err) => {
app.globalData.hasLogin = false;
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
})
}).catch((err) => {
app.globalData.hasLogin = false;
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 (e.detail.userInfo == undefined) { if (this.data.canIUseGetUserProfile) {
app.globalData.hasLogin = false; wx.getUserProfile({
util.showErrorToast('微信登录失败'); desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
return; 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.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
{ {
"description": "项目配置文件。", "description": "项目配置文件。",
"setting": { "setting": {
"urlCheck": false, "urlCheck": false,
"es6": true, "es6": true,
"postcss": true, "postcss": true,
"minified": true, "minified": true,
"newFeature": true, "newFeature": true,
"uglifyFileName": true "uglifyFileName": true,
}, "checkInvalidKey": true,
"compileType": "miniprogram", "checkSiteMap": true,
"libVersion": "2.4.0", "uploadWithSourceMap": true,
"appid": "wxa5b486c6b918ecfb", "useMultiFrameRuntime": true,
"projectname": "Renard", "useApiHook": true,
"simulatorType": "wechat", "useApiHostProcess": true,
"simulatorPluginLibVersion": {}, "babelSetting": {
"condition": { "ignore": [],
"search": { "disablePlugins": [],
"current": -1, "outputPath": ""
"list": [] },
}, "useIsolateContext": true,
"conversation": { "useCompilerModule": true,
"current": -1, "userConfirmedUseCompilerModuleSwitch": false,
"list": [] "userConfirmedBundleSwitch": false,
}, "packNpmManually": false,
"plugin": { "packNpmRelationList": [],
"current": -1, "minifyWXSS": true
"list": [] },
}, "compileType": "miniprogram",
"game": { "libVersion": "2.4.0",
"list": [] "appid": "wxa5b486c6b918ecfb",
}, "projectname": "Renard",
"miniprogram": { "simulatorType": "wechat",
"current": 34, "simulatorPluginLibVersion": {},
"list": [ "condition": {
{ "search": {
"id": -1, "list": []
"name": "首页", },
"pathName": "pages/index/index", "conversation": {
"query": "" "list": []
}, },
{ "plugin": {
"id": -1, "list": []
"name": "专题", },
"pathName": "pages/topic/topic", "game": {
"query": "" "list": []
}, },
{ "miniprogram": {
"id": -1, "list": [
"name": "专题详情", {
"pathName": "pages/topicDetail/topicDetail", "id": -1,
"query": "id=314" "name": "首页",
}, "pathName": "pages/index/index",
{ "query": ""
"id": -1, },
"name": "品牌", {
"pathName": "pages/brand/brand", "id": -1,
"query": "" "name": "专题",
}, "pathName": "pages/topic/topic",
{ "query": ""
"id": -1, },
"name": "品牌详情", {
"pathName": "pages/brandDetail/brandDetail", "id": -1,
"query": "id=1001000" "name": "专题详情",
}, "pathName": "pages/topicDetail/topicDetail",
{ "query": "id=314"
"id": -1, },
"name": "人气推荐", {
"pathName": "pages/hotGoods/hotGoods", "id": -1,
"query": "" "name": "品牌",
}, "pathName": "pages/brand/brand",
{ "query": ""
"id": -1, },
"name": "新品首发", {
"pathName": "pages/newGoods/newGoods", "id": -1,
"query": "" "name": "品牌详情",
}, "pathName": "pages/brandDetail/brandDetail",
{ "query": "id=1001000"
"id": -1, },
"name": "分类", {
"pathName": "pages/catalog/catalog", "id": -1,
"query": "" "name": "人气推荐",
}, "pathName": "pages/hotGoods/hotGoods",
{ "query": ""
"id": -1, },
"name": "分类详情", {
"pathName": "pages/category/category", "id": -1,
"query": "id=1008002" "name": "新品首发",
}, "pathName": "pages/newGoods/newGoods",
{ "query": ""
"id": -1, },
"name": "查找", {
"pathName": "pages/search/search", "id": -1,
"query": "" "name": "分类",
}, "pathName": "pages/catalog/catalog",
{ "query": ""
"id": -1, },
"name": "商品", {
"pathName": "pages/goods/goods", "id": -1,
"query": "id=1181000" "name": "分类详情",
}, "pathName": "pages/category/category",
{ "query": "id=1008002"
"id": -1, },
"name": "商品评论列表", {
"pathName": "pages/comment/comment", "id": -1,
"query": "valueId=1181000&type=0" "name": "查找",
}, "pathName": "pages/search/search",
{ "query": ""
"id": -1, },
"name": "购物车", {
"pathName": "pages/cart/cart", "id": -1,
"query": "" "name": "商品",
}, "pathName": "pages/goods/goods",
{ "query": "id=1181000"
"id": -1, },
"name": "下单", {
"pathName": "pages/shopping/checkout/checkout", "id": -1,
"query": "" "name": "商品评论列表",
}, "pathName": "pages/comment/comment",
{ "query": "valueId=1181000&type=0"
"id": -1, },
"name": "支付结果", {
"pathName": "pages/payResult/payResult", "id": -1,
"query": "" "name": "购物车",
}, "pathName": "pages/cart/cart",
{ "query": ""
"id": -1, },
"name": "我的", {
"pathName": "pages/ucenter/index/index", "id": -1,
"query": "" "name": "下单",
}, "pathName": "pages/shopping/checkout/checkout",
{ "query": ""
"id": -1, },
"name": "我的订单列表", {
"pathName": "pages/ucenter/order/order", "id": -1,
"query": "" "name": "支付结果",
}, "pathName": "pages/payResult/payResult",
{ "query": ""
"id": -1, },
"name": "我的订单详情", {
"pathName": "pages/ucenter/orderDetail/orderDetail", "id": -1,
"query": "id=1" "name": "我的",
}, "pathName": "pages/ucenter/index/index",
{ "query": ""
"id": 22, },
"name": "待评价的订单详情", {
"pathName": "pages/ucenter/orderDetail/orderDetail", "id": -1,
"query": "id=1" "name": "我的订单列表",
}, "pathName": "pages/ucenter/order/order",
{ "query": ""
"id": -1, },
"name": "购买商品评价", {
"pathName": "pages/commentPost/commentPost", "id": -1,
"query": "orderId=2&type=0&valueId=1116011" "name": "我的订单详情",
}, "pathName": "pages/ucenter/orderDetail/orderDetail",
{ "query": "id=1"
"id": -1, },
"name": "我的优惠券", {
"pathName": "pages/ucenter/coupon/coupon", "id": 22,
"query": "" "name": "待评价的订单详情",
}, "pathName": "pages/ucenter/orderDetail/orderDetail",
{ "query": "id=1"
"id": -1, },
"name": "我的收藏", {
"pathName": "pages/ucenter/collect/collect", "id": -1,
"query": "" "name": "购买商品评价",
}, "pathName": "pages/commentPost/commentPost",
{ "query": "orderId=2&type=0&valueId=1116011"
"id": -1, },
"name": "我的地址", {
"pathName": "pages/ucenter/address/address", "id": -1,
"query": "" "name": "我的优惠券",
}, "pathName": "pages/ucenter/coupon/coupon",
{ "query": ""
"id": -1, },
"name": "我的地址添加", {
"pathName": "pages/ucenter/addressAdd/addressAdd", "id": -1,
"query": "" "name": "我的收藏",
}, "pathName": "pages/ucenter/collect/collect",
{ "query": ""
"id": -1, },
"name": "登录", {
"pathName": "pages/auth/login/login", "id": -1,
"query": "" "name": "我的地址",
} "pathName": "pages/ucenter/address/address",
] "query": ""
} },
} {
"id": -1,
"name": "我的地址添加",
"pathName": "pages/ucenter/addressAdd/addressAdd",
"query": ""
},
{
"id": -1,
"name": "登录",
"pathName": "pages/auth/login/login",
"query": ""
}
]
}
}
} }
\ No newline at end of file
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