|
@@ -3,18 +3,7 @@ import store from '@/store';
|
|
|
import config from '@/config';
|
|
|
import { login, getCompanyByPhone, refreshToken, getUserControlSpace } from '@/api/user.js';
|
|
|
import utils from '@/common/utils.js';
|
|
|
-
|
|
|
-
|
|
|
-function checkLogin(needGetetUserInfo = true) {
|
|
|
- let token = store.state.user.token;
|
|
|
- if (!token) {
|
|
|
- return wxLogin(needGetetUserInfo);
|
|
|
- } else {
|
|
|
- return Promise.resolve();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
function checkHasUserInfo() {
|
|
|
let userInfo = store.state.user.userInfo;
|
|
|
if (userInfo && JSON.stringify(userInfo) !== '{}') {
|
|
@@ -23,72 +12,10 @@ function checkHasUserInfo() {
|
|
|
|
|
|
|
|
|
|
|
|
- wxLogin();
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function setUserInfoByAuth() {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- wx.getUserProfile({
|
|
|
- desc: '用于完善用户信息',
|
|
|
- success: res => {
|
|
|
- let detail = res;
|
|
|
- wx.login({
|
|
|
- success: loginRes => {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- },
|
|
|
- fail: res => {
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- fail: res => {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
function wxLogin(type) {
|
|
|
|
|
@@ -117,7 +44,7 @@ function wxLogin(type) {
|
|
|
store.commit('setTokenInfo', tokenInfo);
|
|
|
if (data.isActivated && data.isActivated == 1) {
|
|
|
store.commit('setUserInfo', data.tokenUser);
|
|
|
- store.commit('setProjectId', data.tokenUser.projectId);
|
|
|
+
|
|
|
} else {
|
|
|
if (!type) {
|
|
|
wx.redirectTo({ url: '/pages/index' });
|
|
@@ -155,8 +82,6 @@ function getCompanyDataByPhone() {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
let userPhone = wx.getStorageSync('userPhone');
|
|
|
let userInfo = store.state.user.userInfo;
|
|
|
-
|
|
|
- console.log("userInfo==",userInfo)
|
|
|
if (!userPhone) {
|
|
|
userPhone = userInfo.phone
|
|
|
}
|
|
@@ -210,11 +135,8 @@ function refreshTokenPage() {
|
|
|
resolve("续约失败")
|
|
|
store.commit('setToken', '')
|
|
|
wx.redirectTo({ url: '/pages/index' });
|
|
|
-
|
|
|
-
|
|
|
})
|
|
|
})
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -265,24 +187,34 @@ function checkUserControl() {
|
|
|
}
|
|
|
|
|
|
|
|
|
-function checkLoginNew() {
|
|
|
+function checkLoginNew(type) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
let token = store.state.user.token;
|
|
|
if (!token) {
|
|
|
wxLogin().then((res) => {
|
|
|
resolve(res)
|
|
|
+ }).catch((error) => {
|
|
|
+ reject("登录失败!");
|
|
|
});
|
|
|
} else {
|
|
|
- let flag = checkTokenIsValid()
|
|
|
+ let flag = checkTokenIsValid();
|
|
|
if (flag == 1) {
|
|
|
refreshTokenPage().then(res => {
|
|
|
resolve(res)
|
|
|
+ }).catch(() => {
|
|
|
+ reject("续约失败!");
|
|
|
});
|
|
|
} else if (flag == 2) {
|
|
|
wxLogin().then((res) => {
|
|
|
resolve(res)
|
|
|
});
|
|
|
- } else if (flag == 3) {
|
|
|
+ } else if (flag == 3) {
|
|
|
+ if (type !== 1) {
|
|
|
+ let timeout = setTimeout(() => {
|
|
|
+ clearTimeout(timeout)
|
|
|
+ checkLoginNew();
|
|
|
+ }, 300000)
|
|
|
+ }
|
|
|
resolve({
|
|
|
isActivated: 1
|
|
|
})
|
|
@@ -300,7 +232,7 @@ function checkTokenIsValid() {
|
|
|
let nowtime = utils.getTimeStamp();
|
|
|
if (expireTime && expireTime < nowtime && refreshToken >= nowtime) {
|
|
|
flag = 1
|
|
|
- } else if (expireTime && expireTime >= nowtime) {
|
|
|
+ } else if (expireTime && expireTime >= (nowtime - 120000)) {
|
|
|
flag = 3
|
|
|
}
|
|
|
else {
|
|
@@ -334,5 +266,5 @@ export {
|
|
|
checkTokenIsValid,
|
|
|
getCompanyDataByPhone,
|
|
|
checkUserControl,
|
|
|
- setUserInfoByAuth
|
|
|
+ checkLoginStatus
|
|
|
}
|