|
@@ -1,13 +1,20 @@
|
|
|
import store from "../store";
|
|
import store from "../store";
|
|
|
import Cache from '../utils/cache';
|
|
import Cache from '../utils/cache';
|
|
|
// #ifdef H5 || APP-PLUS
|
|
// #ifdef H5 || APP-PLUS
|
|
|
-import { isWeixin } from "../utils";
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ isWeixin
|
|
|
|
|
+} from "../utils";
|
|
|
import auth from './wechat';
|
|
import auth from './wechat';
|
|
|
// #endif
|
|
// #endif
|
|
|
|
|
|
|
|
-import { LOGIN_STATUS, USER_INFO, EXPIRES_TIME, STATE_R_KEY} from './../config/cache';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ LOGIN_STATUS,
|
|
|
|
|
+ USER_INFO,
|
|
|
|
|
+ EXPIRES_TIME,
|
|
|
|
|
+ STATE_R_KEY
|
|
|
|
|
+} from './../config/cache';
|
|
|
|
|
|
|
|
-function prePage(){
|
|
|
|
|
|
|
+function prePage() {
|
|
|
let pages = getCurrentPages();
|
|
let pages = getCurrentPages();
|
|
|
let prePage = pages[pages.length - 2];
|
|
let prePage = pages[pages.length - 2];
|
|
|
// #ifdef H5
|
|
// #ifdef H5
|
|
@@ -19,58 +26,57 @@ function prePage(){
|
|
|
export function toLogin(push, pathLogin) {
|
|
export function toLogin(push, pathLogin) {
|
|
|
// store.commit("LOGOUT");
|
|
// store.commit("LOGOUT");
|
|
|
let path = prePage();
|
|
let path = prePage();
|
|
|
- if(path){
|
|
|
|
|
|
|
+ if (path) {
|
|
|
path = path.router;
|
|
path = path.router;
|
|
|
- if(path == undefined){
|
|
|
|
|
|
|
+ if (path == undefined) {
|
|
|
path = location.pathname;
|
|
path = location.pathname;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- // #ifdef H5
|
|
|
|
|
- else{
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ // #ifdef H5
|
|
|
|
|
+ else {
|
|
|
path = location.pathname;
|
|
path = location.pathname;
|
|
|
- }
|
|
|
|
|
- // #endif
|
|
|
|
|
-
|
|
|
|
|
- if(!pathLogin)
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ if (!pathLogin)
|
|
|
pathLogin = '/page/users/login/index'
|
|
pathLogin = '/page/users/login/index'
|
|
|
- Cache.set('login_back_url',path);
|
|
|
|
|
|
|
+ Cache.set('login_back_url', path);
|
|
|
// #ifdef H5 || APP-PLUS
|
|
// #ifdef H5 || APP-PLUS
|
|
|
if (isWeixin()) {
|
|
if (isWeixin()) {
|
|
|
auth.oAuth();
|
|
auth.oAuth();
|
|
|
} else {
|
|
} else {
|
|
|
if (path !== pathLogin) {
|
|
if (path !== pathLogin) {
|
|
|
- push ? uni.navigateTo({
|
|
|
|
|
- url:'/pages/users/login/index'
|
|
|
|
|
- }) : uni.reLaunch({
|
|
|
|
|
- url: '/pages/users/login/index'
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ push ? uni.navigateTo({
|
|
|
|
|
+ url: '/pages/users/login/index'
|
|
|
|
|
+ }) : uni.reLaunch({
|
|
|
|
|
+ url: '/pages/users/login/index'
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// #endif
|
|
// #endif
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// #ifdef MP
|
|
// #ifdef MP
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// #endif
|
|
// #endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-export function checkLogin()
|
|
|
|
|
-{
|
|
|
|
|
|
|
+export function checkLogin() {
|
|
|
let token = Cache.get(LOGIN_STATUS);
|
|
let token = Cache.get(LOGIN_STATUS);
|
|
|
let expiresTime = Cache.get(EXPIRES_TIME);
|
|
let expiresTime = Cache.get(EXPIRES_TIME);
|
|
|
let newTime = Math.round(new Date() / 1000);
|
|
let newTime = Math.round(new Date() / 1000);
|
|
|
- if (expiresTime < newTime || !token){
|
|
|
|
|
|
|
+ if (expiresTime < newTime || !token) {
|
|
|
Cache.clear(LOGIN_STATUS);
|
|
Cache.clear(LOGIN_STATUS);
|
|
|
Cache.clear(EXPIRES_TIME);
|
|
Cache.clear(EXPIRES_TIME);
|
|
|
Cache.clear(USER_INFO);
|
|
Cache.clear(USER_INFO);
|
|
|
Cache.clear(STATE_R_KEY);
|
|
Cache.clear(STATE_R_KEY);
|
|
|
return false;
|
|
return false;
|
|
|
- }else{
|
|
|
|
|
- store.commit('UPDATE_LOGIN',token);
|
|
|
|
|
- let userInfo = Cache.get(USER_INFO,true);
|
|
|
|
|
- if(userInfo){
|
|
|
|
|
- store.commit('UPDATE_USERINFO',userInfo);
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ store.commit('UPDATE_LOGIN', token);
|
|
|
|
|
+ let userInfo = Cache.get(USER_INFO, true);
|
|
|
|
|
+ if (userInfo) {
|
|
|
|
|
+ store.commit('UPDATE_USERINFO', userInfo);
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|