feat:登录
This commit is contained in:
1 parent
0088fe3509
commit
8cfe87e31e
8 files changed
+5048
-3914
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import * as CryptoJS from "crypto-js";
|
||||
|
||||
/**
|
||||
*加密处理
|
||||
*/
|
||||
export function encryption(src: string, keyWord: string) {
|
||||
const key = CryptoJS.enc.Utf8.parse(keyWord);
|
||||
// 加密
|
||||
var encrypted = CryptoJS.AES.encrypt(src, key, {
|
||||
iv: key,
|
||||
mode: CryptoJS.mode.CFB,
|
||||
padding: CryptoJS.pad.NoPadding,
|
||||
});
|
||||
return encrypted.toString();
|
||||
}
|
||||
+36
-19
@@ -30,15 +30,16 @@ function closeLoading() {
|
||||
if (LoadingInstance.count > 0) LoadingInstance.count--;
|
||||
if (LoadingInstance.count === 0) uni.hideLoading();
|
||||
}
|
||||
|
||||
const http = new Request({
|
||||
baseURL: __APP_SERVICE__,
|
||||
baseURL: import.meta.env.VITE_API_URL,
|
||||
timeout: 8000,
|
||||
method: "GET",
|
||||
header: {
|
||||
Accept: "*/*",
|
||||
"Content-Type": "application/json;charset=UTF-8",
|
||||
Authorization: "",
|
||||
"tenant-id": "",
|
||||
"TENANT-ID": "",
|
||||
},
|
||||
withCredentials: true,
|
||||
custom: options,
|
||||
@@ -49,16 +50,14 @@ http.interceptors.request.use(
|
||||
const tokenKey = constant.storageConstant.TOKEN;
|
||||
const tokenStorage = uni.getStorageSync(tokenKey);
|
||||
const config_header: any = config?.header;
|
||||
|
||||
// 添加终端类型
|
||||
const isToc = import.meta.env.VITE_IS_TOC;
|
||||
if (isToc === "true") {
|
||||
config_header["CLIENT-TOC"] = "Y";
|
||||
}
|
||||
|
||||
config_header["tenant-id"] = "1";
|
||||
if (tokenStorage && tokenStorage.accessToken && config_header) {
|
||||
config_header.Authorization = tokenStorage.accessToken;
|
||||
config_header["TENANT-ID"] = "1";
|
||||
if (tokenStorage && tokenStorage.access_token && config_header) {
|
||||
config_header.Authorization = tokenStorage.access_token;
|
||||
}
|
||||
if (config.custom && config.custom.showLoading) {
|
||||
LoadingInstance.count++;
|
||||
@@ -80,9 +79,23 @@ http.interceptors.request.use(
|
||||
|
||||
http.interceptors.response.use(
|
||||
async (response) => {
|
||||
response.config && response.config.custom && response.config.custom.showLoading && closeLoading();
|
||||
response.config &&
|
||||
response.config.custom &&
|
||||
response.config.custom.showLoading &&
|
||||
closeLoading();
|
||||
if (response.config.url === "/auth/oauth2/token") {
|
||||
return Promise.resolve({
|
||||
code: 0,
|
||||
data: response.data,
|
||||
msg: null,
|
||||
});
|
||||
}
|
||||
if (response.data.code !== 0) {
|
||||
if (response.config && response.config.custom && response.config.custom.showError) {
|
||||
if (
|
||||
response.config &&
|
||||
response.config.custom &&
|
||||
response.config.custom.showError
|
||||
) {
|
||||
switch (response.data.code) {
|
||||
case 401:
|
||||
setTimeout(() => {
|
||||
@@ -118,16 +131,20 @@ http.interceptors.response.use(
|
||||
}
|
||||
const tokenKey = constant.storageConstant.TOKEN;
|
||||
const tokenStorage = uni.getStorageSync(tokenKey);
|
||||
if (!isEmpty(tokenStorage) && response.config.url != "/sys/auth/refresh-token") {
|
||||
const { refreshToken, expiresTime } = tokenStorage;
|
||||
const now = new Date().getTime();
|
||||
const remain = expiresTime - now;
|
||||
if (remain <= 1000 * 60 * 20) {
|
||||
const _pa = { refreshToken: refreshToken };
|
||||
const refreshData = await userApi.refreshToken(_pa);
|
||||
console.log(refreshData, "refreshData");
|
||||
if (!isEmpty(refreshData.data)) {
|
||||
uni.setStorageSync(tokenKey, refreshData.data);
|
||||
if (
|
||||
!isEmpty(tokenStorage) &&
|
||||
response.config.url != "/sys/auth/refresh-token"
|
||||
) {
|
||||
const { refresh_token, expiresTime } = tokenStorage;
|
||||
if (!isEmpty(refresh_token) && !isEmpty(expiresTime)) {
|
||||
const now = new Date().getTime();
|
||||
const remain = expiresTime - now;
|
||||
if (remain <= 1000 * 60 * 20) {
|
||||
const _pa = { refreshToken: refresh_token };
|
||||
const refreshData = await userApi.refreshToken(_pa);
|
||||
if (!isEmpty(refreshData.data)) {
|
||||
uni.setStorageSync(tokenKey, refreshData.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-10
@@ -52,8 +52,13 @@ export enum LinkTypeEnum {
|
||||
"CUSTOM_LINK" = "custom",
|
||||
}
|
||||
|
||||
export function navigateTo(link: Link, navigateType: "navigateTo" | "reLaunch" | "switchTab" = "navigateTo") {
|
||||
const url = link.query ? `${link.path}?${objectToQuery(link.query)}` : link.path;
|
||||
export function navigateTo(
|
||||
link: Link,
|
||||
navigateType: "navigateTo" | "reLaunch" | "switchTab" = "navigateTo"
|
||||
) {
|
||||
const url = link.query
|
||||
? `${link.path}?${objectToQuery(link.query)}`
|
||||
: link.path;
|
||||
navigateType == "navigateTo" && uni.navigateTo({ url });
|
||||
navigateType == "reLaunch" && uni.reLaunch({ url });
|
||||
navigateType == "switchTab" && uni.switchTab({ url });
|
||||
@@ -193,11 +198,3 @@ export function encryption(src: string, keyWord: string) {
|
||||
});
|
||||
return encrypted.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*加密处理
|
||||
*/
|
||||
export function encryptionBase64(rawStr: string) {
|
||||
let wordArray = CryptoJS.enc.Utf8.parse(rawStr);
|
||||
return CryptoJS.enc.Base64.stringify(wordArray);
|
||||
}
|
||||
Reference in new issue
Block a user