Commit a2bf4ca5 authored by Mac's avatar Mac

首页的静默登录

parent 19e3acd9
...@@ -211,31 +211,48 @@ export default { ...@@ -211,31 +211,48 @@ export default {
withShareTicket: true, withShareTicket: true,
menus: ["shareAppMessage", "shareTimeline"], menus: ["shareAppMessage", "shareTimeline"],
}); });
if (uni.getStorageSync("mall_UserInfo")) {
let uid = uni.getStorageSync("mall_UserInfo").UserId; that.u = uni.getStorageSync("mall_UserInfo")
wx.getUserInfo({ wx.getUserInfo({
success: function (res) { success: function (res) {
let msg = {
Id: uid, if (uni.getStorageSync("mall_UserInfo")) {
AliasName: res.userInfo.nickName, let uid = uni.getStorageSync("mall_UserInfo").UserId;
Photo: res.userInfo.avatarUrl, let msg = {
}; Id: uid,
that.updateuserinfo(msg); AliasName: res.userInfo.nickName,
Photo: res.userInfo.avatarUrl,
};
that.updateuserinfo(msg);
}else{
//静默登录操作
uni.login({
provider: 'weixin',
success: info => {
let obj ={
Name: res.userInfo.nickName,
Photo: res.userInfo.avatarUrl,
code: info.code
}
that.getCode(obj)
},
fail: () => {
uni.showToast({ title: '微信登录授权失败', icon: 'none' });
if (!that.u) {
that.u = {
nickName: "未登录",
avatarUrl: ""
};
that.showAuth = true;
}
}
});
}
}, },
}); });
}
this.u = uni.getStorageSync("mall_UserInfo");
if (!this.u) {
this.u = {
nickName: "未登录",
avatarUrl: ""
};
this.showAuth = true;
} else{
}
// #endif // #endif
this.init(); this.init();
let set = uni.getStorageSync("basedata") let set = uni.getStorageSync("basedata")
...@@ -317,6 +334,65 @@ export default { ...@@ -317,6 +334,65 @@ export default {
}, },
methods: { methods: {
//调用获取code
getCode(obj) {
var that = this;
//这里请求接口
that.request2(
{
url: '/api/mall/GetWeChatOpenId',
data: {
Code: obj.code
}
},
res => {
if (res.resultCode == 1) {
obj.OpenId = res.data;
that.getLogin(obj);
}
}
);
},
getLogin(obj) {
var that = this;
let pid = uni.getStorageSync("pid")?uni.getStorageSync("pid").pid:0;
let SmallShopId = uni.getStorageSync("SmallShopId")?uni.getStorageSync("SmallShopId").SmallShopId:0;
that.request2(
{
url: '/api/AppletLogin/Login',
data: {
Source: 1,
OpenId: obj.OpenId,
Name: obj.Name,
Photo: obj.Photo,
Moblie: '',
SuperiorId: pid,
SmallShopId:SmallShopId,
}
},
res => {
if (res.resultCode == 1) {
uni.setStorageSync('mall_UserInfo', res.data);
if(res.couponResultCode==1){
that.showCoupons = true;
that.couponMessage = res.couponMessage;
}
that.u = res.data
uni.removeStorageSync('pid');
uni.removeStorageSync('SmallShopId');
}else{
if (!that.u) {
that.u = {
nickName: "未登录",
avatarUrl: ""
};
that.showAuth = true;
}
}
}
);
},
updateuserinfo(msg) { updateuserinfo(msg) {
this.request2( this.request2(
{ {
......
Markdown is supported
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