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