|
|
|
|
@ -8,6 +8,47 @@ import auth from './wechat';
|
|
|
|
|
|
|
|
|
|
import { LOGIN_STATUS, USER_INFO, EXPIRES_TIME, STATE_R_KEY, BACK_URL} from './../config/cache';
|
|
|
|
|
|
|
|
|
|
const LOGIN_PAGE_ROUTE = 'pages/users/login/index';
|
|
|
|
|
const WECHAT_LOGIN_PAGE_ROUTE = 'pages/users/wechat_login/index';
|
|
|
|
|
|
|
|
|
|
function normalizeRoute(route) {
|
|
|
|
|
return (route || '').replace(/^\//, '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPrevPageRoute() {
|
|
|
|
|
const pages = getCurrentPages();
|
|
|
|
|
if (pages.length < 2) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
return normalizeRoute(pages[pages.length - 2].route);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 登录页 ⇄ 微信登录页切换:上一页已是目标页则返回,避免反复 navigateTo 堆栈
|
|
|
|
|
*/
|
|
|
|
|
export function switchLoginPage(url) {
|
|
|
|
|
const targetRoute = normalizeRoute((url || '').split('?')[0].replace(/^\//, ''));
|
|
|
|
|
const prevRoute = getPrevPageRoute();
|
|
|
|
|
if (prevRoute && prevRoute === targetRoute && url.indexOf('?') === -1) {
|
|
|
|
|
uni.navigateBack();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uni.navigateTo({ url });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 微信授权后进入账号绑定页(replace 当前页,避免栈里叠多层登录相关页面)
|
|
|
|
|
*/
|
|
|
|
|
export function openLoginBindPage(authKey) {
|
|
|
|
|
const url = `/pages/users/login/index?bindWechat=1&authKey=${encodeURIComponent(authKey)}`;
|
|
|
|
|
const prevRoute = getPrevPageRoute();
|
|
|
|
|
if (prevRoute === LOGIN_PAGE_ROUTE) {
|
|
|
|
|
uni.redirectTo({ url });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uni.redirectTo({ url });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function prePage(){
|
|
|
|
|
let pages = getCurrentPages();
|
|
|
|
|
let prePage = pages[pages.length - 1];
|
|
|
|
|
|