登录:微信小程序,静默登录
parent
3c7db828db
commit
54c6e483a4
12
App.vue
12
App.vue
|
|
@ -122,16 +122,12 @@
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef MP
|
// #ifdef MP
|
||||||
// 小程序静默授权 TODO 芋艿:
|
// 小程序静默授权
|
||||||
if (!this.$store.getters.isLogin) {
|
if (!this.$store.getters.isLogin) {
|
||||||
let spread = that.globalData.spid ? that.globalData.spid : 0;
|
let spread = that.globalData.spid ? that.globalData.spid : 0;
|
||||||
Routine.getCode()
|
Routine.getCode().then(code => {
|
||||||
.then(code => {
|
Routine.authUserInfo(code, spread)
|
||||||
Routine.authUserInfo(code, {
|
.then(res => {})
|
||||||
'spread_spid': spread
|
|
||||||
}).then(res => {
|
|
||||||
// that.$store.commit('AuthorizeType', res.data.type);
|
|
||||||
})
|
|
||||||
}).catch(res => {
|
}).catch(res => {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -37,3 +37,14 @@ export function smsLogin(data) {
|
||||||
noAuth: true // TODO 芋艿:后续要做调整
|
noAuth: true // TODO 芋艿:后续要做调整
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 社交快捷登录
|
||||||
|
export function socialLogin(type, code, state) {
|
||||||
|
return request.post('app-api/member/auth/social-login', {
|
||||||
|
type,
|
||||||
|
code,
|
||||||
|
state
|
||||||
|
}, {
|
||||||
|
noAuth: true // TODO 芋艿:后续要做调整
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ module.exports = {
|
||||||
LOGIN_STATUS: 'LOGIN_STATUS_TOKEN',
|
LOGIN_STATUS: 'LOGIN_STATUS_TOKEN',
|
||||||
// uid
|
// uid
|
||||||
UID:'UID',
|
UID:'UID',
|
||||||
|
// openid
|
||||||
|
OPENID: 'OPENID',
|
||||||
//用户信息
|
//用户信息
|
||||||
USER_INFO: 'USER_INFO',
|
USER_INFO: 'USER_INFO',
|
||||||
//token 过期时间
|
//token 过期时间
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import store from '../store';
|
import store from '../store';
|
||||||
import { checkLogin } from './login';
|
import { checkLogin } from './login';
|
||||||
import { login } from '../api/public';
|
|
||||||
import Cache from '../utils/cache';
|
import Cache from '../utils/cache';
|
||||||
import { STATE_R_KEY, USER_INFO, EXPIRES_TIME, LOGIN_STATUS} from './../config/cache';
|
import { STATE_R_KEY, USER_INFO, OPENID} from './../config/cache';
|
||||||
|
import * as AuthApi from "@/api/member/auth";
|
||||||
|
import * as BrokerageAPI from '@/api/trade/brokerage.js'
|
||||||
|
|
||||||
class Routine
|
class Routine
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -68,7 +70,9 @@ class Routine
|
||||||
uni.login({
|
uni.login({
|
||||||
provider:provider,
|
provider:provider,
|
||||||
success(res) {
|
success(res) {
|
||||||
if (res.code) Cache.set(STATE_R_KEY, res.code ,10800);
|
if (res.code) {
|
||||||
|
Cache.set(STATE_R_KEY, res.code ,10800);
|
||||||
|
}
|
||||||
return resolve(res.code);
|
return resolve(res.code);
|
||||||
},
|
},
|
||||||
fail(){
|
fail(){
|
||||||
|
|
@ -118,16 +122,26 @@ class Routine
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 小程序登录
|
* 小程序登录
|
||||||
|
*
|
||||||
|
* @param code 授权码
|
||||||
|
* @param spread 推广员编号
|
||||||
*/
|
*/
|
||||||
authUserInfo(code,data)
|
authUserInfo(code, spread) {
|
||||||
{
|
|
||||||
return new Promise((resolve, reject)=>{
|
return new Promise((resolve, reject)=>{
|
||||||
login(code,data).then(res=>{
|
// 34 的原因,它是小程序登录的社交类型
|
||||||
if(res.data.type==='login'){
|
AuthApi.socialLogin(34, code, 'default').then(res => {
|
||||||
|
if (res.code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 设置访问令牌
|
||||||
store.commit('LOGIN', {
|
store.commit('LOGIN', {
|
||||||
token: res.data.token
|
token: res.data.accessToken
|
||||||
});
|
});
|
||||||
store.commit("SETUID", res.data.uid);
|
store.commit("SETUID", res.data.userId);
|
||||||
|
store.commit("OPENID", res.data.openid);
|
||||||
|
// 绑定推广员
|
||||||
|
if (spread > 0) {
|
||||||
|
BrokerageAPI.bindBrokerageUser(spread)
|
||||||
}
|
}
|
||||||
return resolve(res);
|
return resolve(res);
|
||||||
}).catch(res=>{
|
}).catch(res=>{
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@
|
||||||
"quickapp" : {},
|
"quickapp" : {},
|
||||||
/* 小程序特有相关 */
|
/* 小程序特有相关 */
|
||||||
"mp-weixin" : {
|
"mp-weixin" : {
|
||||||
"appid" : "wx62056c0d5e8db250",
|
"appid" : "wx63c280fe3248a3e7",
|
||||||
"setting" : {
|
"setting" : {
|
||||||
"urlCheck" : true,
|
"urlCheck" : true,
|
||||||
"minified" : true,
|
"minified" : true,
|
||||||
|
|
|
||||||
|
|
@ -57,13 +57,11 @@
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import sendVerifyCode from "@/mixins/SendVerifyCode";
|
import sendVerifyCode from "@/mixins/SendVerifyCode";
|
||||||
import { loginMobile } from "@/api/user";
|
|
||||||
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 { appAuth, appleLogin } from "@/api/public";
|
import { appAuth, appleLogin } from "@/api/public";
|
||||||
const BACK_URL = "login_back_url";
|
const BACK_URL = "login_back_url";
|
||||||
import * as BrokerageAPI from '@/api/trade/brokerage.js'
|
import * as BrokerageAPI from '@/api/trade/brokerage.js'
|
||||||
import {smsLogin} from "../../../api/member/auth";
|
|
||||||
export default {
|
export default {
|
||||||
name: "Login",
|
name: "Login",
|
||||||
mixins: [sendVerifyCode],
|
mixins: [sendVerifyCode],
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 2.3 KiB |
|
|
@ -2,6 +2,7 @@ import * as UserApi from '@/api/member/user.js';
|
||||||
import {
|
import {
|
||||||
LOGIN_STATUS,
|
LOGIN_STATUS,
|
||||||
UID,
|
UID,
|
||||||
|
OPENID,
|
||||||
PLATFORM
|
PLATFORM
|
||||||
} from '../../config/cache';
|
} from '../../config/cache';
|
||||||
import Cache from '../../utils/cache';
|
import Cache from '../../utils/cache';
|
||||||
|
|
@ -14,6 +15,7 @@ const state = {
|
||||||
backgroundColor: "#fff",
|
backgroundColor: "#fff",
|
||||||
userInfo: Cache.get(USER_INFO)?JSON.parse(Cache.get(USER_INFO)):null,
|
userInfo: Cache.get(USER_INFO)?JSON.parse(Cache.get(USER_INFO)):null,
|
||||||
uid: Cache.get(UID) || null,
|
uid: Cache.get(UID) || null,
|
||||||
|
openid: Cache.get() || null,
|
||||||
homeActive: false,
|
homeActive: false,
|
||||||
chatUrl: Cache.get('chatUrl') || '',
|
chatUrl: Cache.get('chatUrl') || '',
|
||||||
systemPlatform: Cache.get(PLATFORM)?Cache.get(PLATFORM):'',
|
systemPlatform: Cache.get(PLATFORM)?Cache.get(PLATFORM):'',
|
||||||
|
|
@ -29,6 +31,10 @@ const mutations = {
|
||||||
state.uid = val;
|
state.uid = val;
|
||||||
Cache.set(UID, val);
|
Cache.set(UID, val);
|
||||||
},
|
},
|
||||||
|
OPENID(state, val) {
|
||||||
|
state.openid = val;
|
||||||
|
Cache.set(OPENID, val);
|
||||||
|
},
|
||||||
UPDATE_LOGIN(state, token) {
|
UPDATE_LOGIN(state, token) {
|
||||||
state.token = token;
|
state.token = token;
|
||||||
},
|
},
|
||||||
|
|
@ -56,9 +62,6 @@ const mutations = {
|
||||||
SET_CHATURL(state, chatUrl){
|
SET_CHATURL(state, chatUrl){
|
||||||
state.chatUrl = chatUrl;
|
state.chatUrl = chatUrl;
|
||||||
},
|
},
|
||||||
// AuthorizeType(state, authorizeType){
|
|
||||||
// state.authorizeType = authorizeType;
|
|
||||||
// },
|
|
||||||
SYSTEM_PLATFORM(state, systemPlatform){
|
SYSTEM_PLATFORM(state, systemPlatform){
|
||||||
state.systemPlatform = systemPlatform;
|
state.systemPlatform = systemPlatform;
|
||||||
Cache.set(PLATFORM, systemPlatform);
|
Cache.set(PLATFORM, systemPlatform);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue