Commit 6060b637 by 程默

登录逻辑修改

parent 7f315e02
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<!-- <div>{{testd}}</div> <!-- <div>{{testd}}</div>
<div>{{test_sessionId}}</div>--sessionId <div>{{test_sessionId}}</div>--sessionId
<div>{{unionId}}</div>--unionId <div>{{unionId}}</div>--unionId
<div>{{test_isHaveUnion}}</div>--isHaveUnion --> <div>{{test_isHaveUnion}}</div>--isHaveUnion-->
<!-- <div class="enterpriseLogin" @click="eLogin">账号登录</div> --> <!-- <div class="enterpriseLogin" @click="eLogin">账号登录</div> -->
</div> </div>
<div class="toCLogin1" v-if="isShowPhone"> <div class="toCLogin1" v-if="isShowPhone">
...@@ -74,96 +74,122 @@ export default { ...@@ -74,96 +74,122 @@ export default {
this.backParams = serialize(options.params); this.backParams = serialize(options.params);
} }
this.getshop(); this.getshop();
this.init();
}, },
methods: { methods: {
getshop() { getshop() {
shop.getShopInfo().then(res => { this.shopName = wx.getStorageSync("shopName");
if (res.data.code == 200) { this.logoUrl = wx.getStorageSync("logoUrl");
this.shopName = res.data.data.shopName; if (!(this.shopName && this.logoUrl)) {
this.logoUrl = process.env.IMG_DOMAIN + res.data.data.logoUrl; shop.getShopInfo().then(res => {
} else { if (res.data.code == 200) {
} this.shopName = res.data.data.shopName;
}); this.logoUrl = process.env.IMG_DOMAIN + res.data.data.logoUrl;
wx.setStorage({
key: "shopName",
data: res.data.data.shopName
});
wx.setStorage({
key: "logoUrl",
data: process.env.IMG_DOMAIN + res.data.data.logoUrl
});
}
});
}
}, },
init() { init() {
wx.login({ return new Promise((resolve, reject) => {
success: res => { wx.login({
if (res.code) { success: res => {
login if (res.code) {
.miniLogin({ code: res.code }) login
.then(res => { .miniLogin({ code: res.code })
// wx.showToast({ title: res.data.code, icon: "none" }); .then(res => {
if (res.data.code == 200) { if (res.data.code == 200) {
this.testd = JSON.stringify(res.data); resolve(res);
this.test_isHaveUnion = res.data.data.isHaveUnion;
console.log("login---", res.data);
wx.setStorage({
key: "openid",
data: res.data.data.openid
});
if (res.data.data.isHaveUnion == "true") {
//有账号
this.backParams += `&sessionid=${
res.data.data.sessionId
}&needCertified=${res.data.data.NEED_CERTIFIED}`;
this.NEED_CERTIFIED = res.data.data.NEED_CERTIFIED;
wx.setStorage({
key: "sessionid",
data: res.data.data.sessionId
});
this.isHaveUnion = true;
} else { } else {
//需要绑定 reject(res.data.msg);
this.isHaveUnion = false;
} }
this.appid = res.data.data.appid; })
this.session_key = res.data.data.session_key; .catch(err => {
this.openid = res.data.data.openid; reject(err);
this.isShow = true; });
}
this.test_sessionId = wx.getStorageSync("sessionid"); },
} else { fail: err => {
wx.showToast({ title: res.data.msg, icon: "none" }); reject(err);
}
})
.catch(err => {
wx.showToast({ title: err, icon: "none" });
});
} }
} });
}); });
}, },
getUserInfo: function(e) { getUserInfo: function(e) {
wx.showLoading({ wx.showLoading({
title: "加载中" title: "加载中"
}); });
if (e.target.errMsg == "getUserInfo:ok" && this.isShow) { if (e.target.errMsg == "getUserInfo:ok") {
wx.hideLoading(); this.init()
if (this.isHaveUnion) { .then(res => {
//是会员 直接登录 console.log("promise", res);
wx.reLaunch({ wx.hideLoading();
url: `../index/main?from=login&backpath=${ //存入openid
this.backPath wx.setStorage({
}&params=${encodeURIComponent(this.backParams)}` key: "openid",
data: res.data.data.openid
});
if (res.data.data.isHaveUnion == "true") {
//有账号
this.backParams += `&sessionid=${
res.data.data.sessionId
}&needCertified=${res.data.data.NEED_CERTIFIED}`;
this.NEED_CERTIFIED = res.data.data.NEED_CERTIFIED;
wx.setStorage({
key: "sessionid",
data: res.data.data.sessionId
});
this.isHaveUnion = true;
} else {
//需要绑定
this.isHaveUnion = false;
}
this.appid = res.data.data.appid;
this.session_key = res.data.data.session_key;
this.openid = res.data.data.openid;
this.isShow = true;
//checkLogin
this.checkLogin();
})
.catch(err => {
console.log("err", err);
wx.hideLoading();
wx.showToast({ title: err, icon: "none" });
}); });
} else { } else {
var data = wx_decode( wx.hideLoading();
this.appid, wx.showToast({ title: "获取用户信息失败", icon: "none" });
this.session_key, }
e.mp.detail.encryptedData, },
e.mp.detail.iv checkLogin() {
); if (this.isHaveUnion) {
this.unionId = data.unionId || ""; //是会员 直接登录
this.userInfo = JSON.parse(e.target.rawData); wx.reLaunch({
console.log(this.userInfo, "this.userInfo"); url: `../index/main?from=login&backpath=${
this.backPath
}&params=${encodeURIComponent(this.backParams)}`
});
} else {
var data = wx_decode(
this.appid,
this.session_key,
e.mp.detail.encryptedData,
e.mp.detail.iv
);
this.unionId = data.unionId || "";
this.userInfo = JSON.parse(e.target.rawData);
console.log(this.userInfo, "this.userInfo");
// return if (this.unionId) {
if (this.unionId) {
login login
.checkUnionid({ unionId: this.unionId, openId: this.openid }) .checkUnionid({ unionId: this.unionId, openId: this.openid })
.then(res => { .then(res => {
...@@ -191,13 +217,10 @@ export default { ...@@ -191,13 +217,10 @@ export default {
.catch(err => { .catch(err => {
wx.showToast({ title: err, icon: "none" }); wx.showToast({ title: err, icon: "none" });
}); });
} else { } else {
//不是会员需要绑定手机号 //不是会员需要绑定手机号
this.isShowPhone = true; this.isShowPhone = true;
}
} }
} else {
wx.hideLoading();
} }
}, },
getPhoneNumber(e) { getPhoneNumber(e) {
......
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