登录逻辑+注册有礼

This commit is contained in:
2024-03-13 22:43:59 +08:00
parent c17b70af2d
commit 0602dc6c72
18 changed files with 289 additions and 44 deletions

View File

@@ -1,15 +1,30 @@
const TokenKey = 'admin-token';
const TokenKey = 'access-token';
const CompanyIdKey = 'companyId';
const TokenPrefix = 'Bearer ';
function isLogin() {
return !!uni.getStorageSync(TokenKey);
}
function getToken() {
return uni.getStorageSync(TokenKey);
}
function setToken(token: string) {
uni.setStorageSync(TokenKey, token);
}
function getCompanyId() {
return uni.getStorageSync(CompanyIdKey);
}
function setCompanyId(companyId: string) {
uni.setStorageSync(CompanyIdKey, companyId);
}
function clearToken() {
uni.removeStorageSync(TokenKey);
uni.removeStorageSync(CompanyIdKey);
}
export { TokenPrefix, isLogin, getToken, setToken, clearToken };
export { TokenPrefix, isLogin, getToken, setToken, getCompanyId, setCompanyId, clearToken };

View File

@@ -4,7 +4,7 @@ import type {
HttpResponse
} from 'uview-plus/libs/luch-request';
import { showMessage } from './status';
import { getToken } from '@/utils/auth';
import { getCompanyId, getToken } from '@/utils/auth';
import useUserStore from '@/store/modules/user';
// 是否正在刷新token的标记
@@ -26,8 +26,7 @@ function requestInterceptors() {
const token = getToken();
if(token && config.header) {
config.header.token = token;
config.header.Authorization = token;
config.header.companyid = '1471673498334113794';
config.header.companyid = getCompanyId();
}
return config;
},