|
@@ -1,8 +1,8 @@
|
|
|
import { getUserInfo, setWxAuthUserInfo, getThirdInfo, createAccount, changePhone } from '@/api/user.js';
|
|
|
import store from '@/store';
|
|
|
import config from '@/config';
|
|
|
-import { login, getCompanyByPhone, refreshToken } from '@/api/user.js';
|
|
|
-import { getAppId, getTimeStamp } from '@/utils/index';
|
|
|
+import { login, getCompanyByPhone, refreshToken, getUserControlSpace } from '@/api/user.js';
|
|
|
+import utils from '@/common/utils.js';
|
|
|
|
|
|
// 检查登录
|
|
|
function checkLogin(needGetetUserInfo = true) {
|
|
@@ -96,7 +96,8 @@ function wxLogin(type) {
|
|
|
wx.login({
|
|
|
success(wxLoginRes) {
|
|
|
const jsCode = wxLoginRes.code;
|
|
|
- const appId = getAppId();
|
|
|
+ console.log(utils)
|
|
|
+ const appId = utils.getAppId();
|
|
|
if (jsCode) {
|
|
|
let params = {
|
|
|
"appId": appId,
|
|
@@ -153,6 +154,12 @@ function wxLogin(type) {
|
|
|
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
|
|
|
+ }
|
|
|
let params = {
|
|
|
phone: userPhone
|
|
|
}
|
|
@@ -209,23 +216,75 @@ function refreshTokenPage() {
|
|
|
})
|
|
|
|
|
|
}
|
|
|
-// 检查是否登录过以及过期
|
|
|
+
|
|
|
+// 刷新首页
|
|
|
+function refreshHome() {
|
|
|
+ // wx.redirectTo({ url: '/pages/index' });
|
|
|
+}
|
|
|
+// 检查用户是否有空间控制权限
|
|
|
+function checkUserControl() {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let userInfo = store.state.user.userInfo;
|
|
|
+ if (userInfo && userInfo.userId) {
|
|
|
+ let params = {
|
|
|
+ "criteria": {
|
|
|
+ "projectId": userInfo.projectId,
|
|
|
+ "companyId": userInfo.companyId,
|
|
|
+ "userCode": userInfo.userId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ getUserControlSpace(params).then(res => {
|
|
|
+ // console.log("返回用户权限数据")
|
|
|
+ // console.log(res)
|
|
|
+ if (res.result == 'success') {
|
|
|
+ let data = res.data || {}
|
|
|
+ if (data && JSON.stringify(data) != '{}') {
|
|
|
+ if (data.isControlSpace !== 1) {
|
|
|
+ resolve(data)
|
|
|
+ } else {
|
|
|
+ reject("租户下无可控空间");
|
|
|
+ refreshHome();
|
|
|
+ }
|
|
|
+
|
|
|
+ } else { // 如果无权限和楼层数据返回跳转到首页,不让点击
|
|
|
+ reject("获取租户权限接口失败");
|
|
|
+ refreshHome();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ reject("获取租户权限接口失败");
|
|
|
+ refreshHome();
|
|
|
+ }
|
|
|
+ }).catch((error) => { // 如果无权限和楼层数据返回跳转到首页,不让点击
|
|
|
+ reject("获取租户权限接口失败");
|
|
|
+ refreshHome();
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ reject("用户未登录");
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 登录续约逻辑-待处理
|
|
|
function checkLoginNew() {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
let token = store.state.user.token;
|
|
|
if (!token) {
|
|
|
- return wxLogin();
|
|
|
+ wxLogin().then((res) => {
|
|
|
+ resolve(res)
|
|
|
+ });
|
|
|
} else {
|
|
|
let flag = checkTokenIsValid()
|
|
|
if (flag == 1) {
|
|
|
- return refreshTokenPage(); // 续约
|
|
|
+ refreshTokenPage().then(res => {
|
|
|
+ resolve(res)
|
|
|
+ }); // 续约
|
|
|
} else if (flag == 2) { // 重新登录
|
|
|
- return wxLogin();
|
|
|
+ wxLogin().then((res) => {
|
|
|
+ resolve(res)
|
|
|
+ });
|
|
|
} else if (flag == 3) { // 后续补定时器定时续约逻辑
|
|
|
resolve({
|
|
|
- data: {
|
|
|
- isActivated: 1
|
|
|
- }
|
|
|
+ isActivated: 1
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -238,7 +297,7 @@ function checkTokenIsValid() {
|
|
|
let tokenInfo = store.state.user.tokenInfo;
|
|
|
let expireTime = tokenInfo.expireTime;
|
|
|
let refreshToken = tokenInfo.refreshToken;
|
|
|
- let nowtime = getTimeStamp();
|
|
|
+ let nowtime = utils.getTimeStamp();
|
|
|
if (expireTime && expireTime < nowtime && refreshToken >= nowtime) { // 过期可续约
|
|
|
flag = 1
|
|
|
} else if (expireTime && expireTime >= nowtime) { // 没过期
|
|
@@ -251,8 +310,6 @@ function checkTokenIsValid() {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// 本地保存用户头像
|
|
|
function setAvatar(avatar) {
|
|
|
wx.setStorageSync('avatarBase64', avatar);
|
|
@@ -276,5 +333,6 @@ export {
|
|
|
checkLoginNew,
|
|
|
checkTokenIsValid,
|
|
|
getCompanyDataByPhone,
|
|
|
+ checkUserControl,
|
|
|
setUserInfoByAuth
|
|
|
}
|