|
|
|
@ -33,7 +33,7 @@
|
|
|
|
created() {
|
|
|
|
created() {
|
|
|
|
if (this.wcCode) {
|
|
|
|
if (this.wcCode) {
|
|
|
|
this.actionLogin(this.wcCode, '', 1);
|
|
|
|
this.actionLogin(this.wcCode, '', 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 验证是否需要登录
|
|
|
|
// 验证是否需要登录
|
|
|
|
if (this.type == 2) {
|
|
|
|
if (this.type == 2) {
|
|
|
|
this.isLogin()
|
|
|
|
this.isLogin()
|
|
|
|
@ -41,11 +41,13 @@
|
|
|
|
// #ifdef H5
|
|
|
|
// #ifdef H5
|
|
|
|
// 如果是支付宝h5自动完成登陆
|
|
|
|
// 如果是支付宝h5自动完成登陆
|
|
|
|
if (this.type == 0) {
|
|
|
|
if (this.type == 0) {
|
|
|
|
if (this.$utils.isInAliBrowser()) {
|
|
|
|
if (this.$utils.isInAliBrowser() || this.$utils.isInWeChatBrowser()) {
|
|
|
|
this.login()
|
|
|
|
this.login()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// #endif
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
async login({
|
|
|
|
async login({
|
|
|
|
@ -90,7 +92,6 @@
|
|
|
|
const res = await this.$api.common.aliH5();
|
|
|
|
const res = await this.$api.common.aliH5();
|
|
|
|
// 获取微信应用的 appid
|
|
|
|
// 获取微信应用的 appid
|
|
|
|
const appid = res.data.appid;
|
|
|
|
const appid = res.data.appid;
|
|
|
|
|
|
|
|
|
|
|
|
ap.getAuthCode({
|
|
|
|
ap.getAuthCode({
|
|
|
|
appId: appid,
|
|
|
|
appId: appid,
|
|
|
|
scopes: ['auth_base'],
|
|
|
|
scopes: ['auth_base'],
|
|
|
|
@ -110,15 +111,18 @@
|
|
|
|
} else if (this.$utils.isInWeChatBrowser()) {
|
|
|
|
} else if (this.$utils.isInWeChatBrowser()) {
|
|
|
|
// 微信h5登陆
|
|
|
|
// 微信h5登陆
|
|
|
|
// 从后端API获取微信H5相关信息
|
|
|
|
// 从后端API获取微信H5相关信息
|
|
|
|
const res = await this.$api.common.wechatH5();
|
|
|
|
const res = await this.$api.common.wechatPageH5();
|
|
|
|
// 获取微信应用的 appid
|
|
|
|
// 获取微信应用的 appid
|
|
|
|
const appid = res.data.appid;
|
|
|
|
const appid = res.data.appid;
|
|
|
|
|
|
|
|
const component_appid = res.data.component_appid
|
|
|
|
// 获取当前页面的重定向地址并进行编码
|
|
|
|
// 获取当前页面的重定向地址并进行编码
|
|
|
|
let redirect_uri = window.location.href;
|
|
|
|
let redirect_uri = window.location.href;
|
|
|
|
redirect_uri = encodeURIComponent(redirect_uri);
|
|
|
|
var fruits = redirect_uri.split("?");
|
|
|
|
|
|
|
|
// console.log(fruits, 'fruits')
|
|
|
|
|
|
|
|
redirect_uri = encodeURIComponent(fruits[0]);
|
|
|
|
// 构建微信授权链接,包含应用的appid、重定向地址等参数
|
|
|
|
// 构建微信授权链接,包含应用的appid、重定向地址等参数
|
|
|
|
const wxAuthUrl =
|
|
|
|
// const wxAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`;
|
|
|
|
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;
|
|
|
|
const wxAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=STATE&component_appid=${component_appid}#wechat_redirect`
|
|
|
|
// 通过重定向将用户导向微信授权页面
|
|
|
|
// 通过重定向将用户导向微信授权页面
|
|
|
|
window.location.href = wxAuthUrl;
|
|
|
|
window.location.href = wxAuthUrl;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
@ -153,7 +157,6 @@
|
|
|
|
user_info,
|
|
|
|
user_info,
|
|
|
|
store_id
|
|
|
|
store_id
|
|
|
|
} = res.data;
|
|
|
|
} = res.data;
|
|
|
|
|
|
|
|
|
|
|
|
uni.setStorageSync("token_" + store_id, token);
|
|
|
|
uni.setStorageSync("token_" + store_id, token);
|
|
|
|
uni.setStorageSync("user_info", user_info);
|
|
|
|
uni.setStorageSync("user_info", user_info);
|
|
|
|
if (this.type != 0) {
|
|
|
|
if (this.type != 0) {
|
|
|
|
@ -166,7 +169,6 @@
|
|
|
|
this.backPage()
|
|
|
|
this.backPage()
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uni.$u.toast(res.message);
|
|
|
|
uni.$u.toast(res.message);
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
uni.hideLoading();
|
|
|
|
uni.hideLoading();
|
|
|
|
|