登录:完善微信公众号的登录逻辑
parent
4e40a69f61
commit
7e7248ef97
1
App.vue
1
App.vue
|
@ -82,7 +82,6 @@
|
||||||
let urlData = location.pathname + location.search;
|
let urlData = location.pathname + location.search;
|
||||||
if (!that.$store.getters.isLogin && Auth.isWeixin()) {
|
if (!that.$store.getters.isLogin && Auth.isWeixin()) {
|
||||||
const { code, state } = option.query;
|
const { code, state } = option.query;
|
||||||
debugger
|
|
||||||
if (code && code !== uni.getStorageSync('snsapiCode')
|
if (code && code !== uni.getStorageSync('snsapiCode')
|
||||||
&& location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
|
&& location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
|
||||||
// 存储静默授权code
|
// 存储静默授权code
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
import {mapGetters} from "vuex";
|
import {mapGetters} from "vuex";
|
||||||
import * as AuthApi from "@/api/member/auth";
|
import * as AuthApi from "@/api/member/auth";
|
||||||
import * as UserApi from "@/api/member/user";
|
import * as UserApi from "@/api/member/user";
|
||||||
import { getUserInfo, } from "@/api/user";
|
import * as BrokerageAPI from '@/api/trade/brokerage.js'
|
||||||
import { iosBinding } from '@/api/public';
|
import { iosBinding } from '@/api/public';
|
||||||
const BACK_URL = "login_back_url";
|
const BACK_URL = "login_back_url";
|
||||||
export default {
|
export default {
|
||||||
|
@ -97,7 +97,6 @@
|
||||||
},
|
},
|
||||||
// 登录
|
// 登录
|
||||||
loginBtn() {
|
loginBtn() {
|
||||||
let that = this
|
|
||||||
if (!this.account) {
|
if (!this.account) {
|
||||||
return this.$util.Tips({
|
return this.$util.Tips({
|
||||||
title: '请填写手机号码'
|
title: '请填写手机号码'
|
||||||
|
@ -122,20 +121,20 @@
|
||||||
if (!this.userInfo.phone && this.isLogin) {
|
if (!this.userInfo.phone && this.isLogin) {
|
||||||
// TODO 芋艿:不晓得它要搞啥哈???
|
// TODO 芋艿:不晓得它要搞啥哈???
|
||||||
iosBinding({
|
iosBinding({
|
||||||
captcha: that.codeNum,
|
captcha: this.codeNum,
|
||||||
phone: that.account
|
phone: this.account
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
that.$util.Tips({
|
this.$util.Tips({
|
||||||
title: '绑定手机号成功',
|
title: '绑定手机号成功',
|
||||||
icon: 'success'
|
icon: 'success'
|
||||||
}, {
|
}, {
|
||||||
tab: 3
|
tab: 3
|
||||||
})
|
})
|
||||||
that.isApp = 1;
|
this.isApp = 1;
|
||||||
that.getUserInfo();
|
this.getUserInfo();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
that.$util.Tips({
|
this.$util.Tips({
|
||||||
title: error
|
title: error
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -143,20 +142,20 @@
|
||||||
AuthApi.smsLogin({
|
AuthApi.smsLogin({
|
||||||
mobile: this.account,
|
mobile: this.account,
|
||||||
code: this.codeNum,
|
code: this.codeNum,
|
||||||
socialType: 31, // TODO 芋艿:先写死,不确定会不会有其它社交方式;
|
socialType: 31,
|
||||||
socialCode: this.socialCode,
|
socialCode: this.socialCode,
|
||||||
socialState: this.socialState
|
socialState: this.socialState
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
// TODO 芋艿:refreshToken 机制
|
// TODO 芋艿:refreshToken 机制
|
||||||
let data = res.data;
|
let data = res.data;
|
||||||
that.$store.commit('LOGIN', {
|
this.$store.commit("LOGIN", {
|
||||||
token: data.accessToken
|
'token': res.data.accessToken
|
||||||
});
|
});
|
||||||
that.$store.commit("SETUID", res.data.uid);
|
this.getUserInfo(data);
|
||||||
that.getUserInfo();
|
this.bindBrokerUser();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
that.$util.Tips({
|
this.$util.Tips({
|
||||||
title: error
|
title: error
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -165,25 +164,33 @@
|
||||||
/**
|
/**
|
||||||
* 获取个人用户信息
|
* 获取个人用户信息
|
||||||
*/
|
*/
|
||||||
getUserInfo: function() {
|
getUserInfo: function(data) {
|
||||||
let that = this;
|
this.$store.commit("SETUID", data.userId);
|
||||||
getUserInfo().then(res => {
|
this.$store.commit("OPENID", data.openid);
|
||||||
|
UserApi.getUserInfo().then(res => {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
that.$store.commit("UPDATE_USERINFO", res.data);
|
this.$store.commit("UPDATE_USERINFO", res.data);
|
||||||
// #ifdef MP
|
// 调回登录前页面
|
||||||
that.$util.Tips({
|
// #ifdef MP
|
||||||
|
this.$util.Tips({
|
||||||
title: '登录成功',
|
title: '登录成功',
|
||||||
icon: 'success'
|
icon: 'success'
|
||||||
}, {
|
}, {
|
||||||
tab: 3
|
tab: 3
|
||||||
})
|
})
|
||||||
that.close()
|
this.close()
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
that.$emit('wechatPhone', true)
|
this.$emit('wechatPhone', true)
|
||||||
// #endif
|
// #endif
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
bindBrokerUser() {
|
||||||
|
const spread = this.$Cache.get("spread");
|
||||||
|
if (spread > 0) {
|
||||||
|
BrokerageAPI.bindBrokerageUser(spread)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -34,20 +34,16 @@ export function _toLogin(push, pathLogin) {
|
||||||
if (isWeixin()) {
|
if (isWeixin()) {
|
||||||
let urlData = location.pathname + location.search
|
let urlData = location.pathname + location.search
|
||||||
if (!Cache.has('snsapiKey')) {
|
if (!Cache.has('snsapiKey')) {
|
||||||
// TODO 芋艿:先临时禁用掉,改成普通登录页
|
auth.oAuth('snsapi_base', urlData);
|
||||||
// auth.oAuth('snsapi_base', urlData);
|
|
||||||
uni.navigateTo({
|
|
||||||
url: '/pages/users/login/index'
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
if (['/pages/user/index'].indexOf(login_back_url) == -1) {
|
if (['/pages/user/index'].indexOf(login_back_url) === -1) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/users/wechat_login/index'
|
url: '/pages/users/wechat_login/index'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (['/pages/user/index'].indexOf(login_back_url) == -1) {
|
if (['/pages/user/index'].indexOf(login_back_url) === -1) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/users/login/index'
|
url: '/pages/users/login/index'
|
||||||
})
|
})
|
||||||
|
@ -55,11 +51,10 @@ export function _toLogin(push, pathLogin) {
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
if (['pages/user/index','/pages/user/index'].indexOf(login_back_url) == -1) {
|
if (['pages/user/index','/pages/user/index'].indexOf(login_back_url) === -1) {
|
||||||
// #ifdef MP
|
// #ifdef MP
|
||||||
// TODO 芋艿:先临时禁用掉,改成普通登录页
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/users/login/index'
|
url: '/pages/users/wechat_login/index'
|
||||||
})
|
})
|
||||||
// #endif
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ class AuthWechat {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { code } = parseQuery();
|
const { code } = parseQuery();
|
||||||
if (!code || code == uni.getStorageSync('snsapiCode')){
|
if (!code || code === uni.getStorageSync('snsapiCode')){
|
||||||
return this.toAuth(snsapiBase,url);
|
return this.toAuth(snsapiBase,url);
|
||||||
} else{
|
} else{
|
||||||
if(Cache.has('snsapiKey'))
|
if(Cache.has('snsapiKey'))
|
||||||
|
|
|
@ -398,16 +398,7 @@
|
||||||
backUrl = '/pages/index/index';
|
backUrl = '/pages/index/index';
|
||||||
}
|
}
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: backUrl,
|
url: backUrl
|
||||||
success:function (res) {
|
|
||||||
console.log("success",res);
|
|
||||||
},
|
|
||||||
fail:function (res) {
|
|
||||||
console.log("fail",res);
|
|
||||||
},
|
|
||||||
complete:function (res) {
|
|
||||||
console.log("complete",res);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -39,13 +39,13 @@
|
||||||
<script>
|
<script>
|
||||||
const app = getApp();
|
const app = getApp();
|
||||||
let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
|
let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
|
||||||
import mobileLogin from '@/components/login_mobile/index.vue'
|
import * as UserApi from "@/api/member/user";
|
||||||
|
import mobileLogin from '@/components/login_mobile/index.vue'
|
||||||
import routinePhone from '@/components/login_mobile/routine_phone.vue'
|
import routinePhone from '@/components/login_mobile/routine_phone.vue'
|
||||||
import {
|
import {
|
||||||
getLogo,
|
getLogo,
|
||||||
getUserPhone
|
getUserPhone
|
||||||
} from '@/api/public';
|
} from '@/api/public';
|
||||||
import { getUserInfo } from '@/api/user.js'
|
|
||||||
import Routine from '@/libs/routine';
|
import Routine from '@/libs/routine';
|
||||||
import wechat from "@/libs/wechat";
|
import wechat from "@/libs/wechat";
|
||||||
export default {
|
export default {
|
||||||
|
@ -84,24 +84,17 @@
|
||||||
window.scrollTo(0, Math.max(scrollHeight - 1, 0));
|
window.scrollTo(0, Math.max(scrollHeight - 1, 0));
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
const { code, state, scope } = options;
|
const { code, state } = options;
|
||||||
this.options = options
|
this.options = options
|
||||||
// 获取确认授权code
|
// 获取确认授权code
|
||||||
this.code = code || ''
|
this.code = code || ''
|
||||||
if (code && this.options.scope !== 'snsapi_base') {
|
if (code && this.options.scope !== 'snsapi_base') {
|
||||||
let spread = app.globalData.spid ? app.globalData.spid : 0;
|
let spread = app.globalData.spid ? app.globalData.spid : 0;
|
||||||
// 公众号授权登录回调
|
// 公众号授权登录回调
|
||||||
wechat.auth(code, state).then(res => {
|
wechat.auth(code, state, spread).then(res => {
|
||||||
if (res.type === 'login') {
|
this.getUserInfo();
|
||||||
this.$store.commit('LOGIN', {
|
this.wechatPhone();
|
||||||
token: res.token
|
|
||||||
});
|
|
||||||
this.$store.commit("SETUID", res.uid);
|
|
||||||
this.getUserInfo();
|
|
||||||
this.wechatPhone();
|
|
||||||
}
|
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
debugger
|
|
||||||
// 异常的情况,说明可能是账号没登录,所以发起手机绑定
|
// 异常的情况,说明可能是账号没登录,所以发起手机绑定
|
||||||
this.socialCode = code;
|
this.socialCode = code;
|
||||||
this.socialState = state;
|
this.socialState = state;
|
||||||
|
@ -136,6 +129,19 @@
|
||||||
this.isPhoneBox = false
|
this.isPhoneBox = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getUserInfo() {
|
||||||
|
UserApi.getUserInfo().then(res => {
|
||||||
|
uni.hideLoading();
|
||||||
|
this.userInfo = res.data
|
||||||
|
this.$store.commit("UPDATE_USERINFO", res.data);
|
||||||
|
this.$util.Tips({
|
||||||
|
title: '登录成功',
|
||||||
|
icon: 'success'
|
||||||
|
}, {
|
||||||
|
tab: 3
|
||||||
|
})
|
||||||
|
});
|
||||||
|
},
|
||||||
// #ifdef MP
|
// #ifdef MP
|
||||||
// 小程序获取手机号码
|
// 小程序获取手机号码
|
||||||
getphonenumber(e) {
|
getphonenumber(e) {
|
||||||
|
@ -181,23 +187,6 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* 获取个人用户信息
|
|
||||||
*/
|
|
||||||
getUserInfo: function() {
|
|
||||||
let that = this;
|
|
||||||
getUserInfo().then(res => {
|
|
||||||
uni.hideLoading();
|
|
||||||
that.userInfo = res.data
|
|
||||||
that.$store.commit("UPDATE_USERINFO", res.data);
|
|
||||||
that.$util.Tips({
|
|
||||||
title: '登录成功',
|
|
||||||
icon: 'success'
|
|
||||||
}, {
|
|
||||||
tab: 3
|
|
||||||
})
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getUserProfile() {
|
getUserProfile() {
|
||||||
let self = this;
|
let self = this;
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
|
@ -272,9 +261,6 @@
|
||||||
if (!this.code && this.options.scope !== 'snsapi_base') {
|
if (!this.code && this.options.scope !== 'snsapi_base') {
|
||||||
this.$wechat.oAuth('snsapi_userinfo', '/pages/users/wechat_login/index');
|
this.$wechat.oAuth('snsapi_userinfo', '/pages/users/wechat_login/index');
|
||||||
} else {
|
} else {
|
||||||
// if (this.authKey) {
|
|
||||||
// this.isUp = true;
|
|
||||||
// }
|
|
||||||
this.isUp = true;
|
this.isUp = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue