10/10
1. 设备管理界面完成 2. 用户管理界面完成 3. 会话列表完成
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import type { LoadingInstance } from 'element-plus';
|
||||
import type {LoadingInstance} from 'element-plus';
|
||||
import axiosModule from 'axios';
|
||||
import { HttpStatus } from '@/enums/RespEnum';
|
||||
import { getLanguage } from '@/lang';
|
||||
import {HttpStatus} from '@/enums/RespEnum';
|
||||
import {getLanguage} from '@/lang';
|
||||
import cache from '@/plugins/cache';
|
||||
import router from '@/router';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import { getToken } from '@/utils/auth';
|
||||
import { decryptBase64, decryptWithAes, encryptBase64, encryptWithAes, generateAesKey } from '@/utils/crypto';
|
||||
import { errorCode } from '@/utils/errorCode';
|
||||
import { decrypt, encrypt } from '@/utils/jsencrypt';
|
||||
import { blobValidate, tansParams } from '@/utils/ruoyi';
|
||||
import { saveBlob } from '@/utils/save';
|
||||
import {useUserStore} from '@/store/modules/user';
|
||||
import {getToken} from '@/utils/auth';
|
||||
import {decryptBase64, decryptWithAes, encryptBase64, encryptWithAes, generateAesKey} from '@/utils/crypto';
|
||||
import {errorCode} from '@/utils/errorCode';
|
||||
import {decrypt, encrypt} from '@/utils/jsencrypt';
|
||||
import {blobValidate, tansParams} from '@/utils/ruoyi';
|
||||
import {saveBlob} from '@/utils/save';
|
||||
|
||||
/** axios 1.13 + TS6:默认导出在类型上会被解析为不可调用的 export= 形态 */
|
||||
const axios = axiosModule as any;
|
||||
@@ -18,7 +18,7 @@ const axios = axiosModule as any;
|
||||
const encryptHeader = 'encrypt-key';
|
||||
let downloadLoadingInstance: LoadingInstance | undefined;
|
||||
// 是否显示重新登录
|
||||
export const isRelogin = { show: false };
|
||||
export const isRelogin = {show: false};
|
||||
|
||||
function createHandledError(message: string) {
|
||||
const error = new Error(message) as Error & { isHandled?: boolean };
|
||||
@@ -205,44 +205,44 @@ service.interceptors.response.use(
|
||||
if (code === 401) {
|
||||
// prettier-ignore
|
||||
if (!isRelogin.show) {
|
||||
isRelogin.show = true;
|
||||
ElMessageBox.confirm(
|
||||
"登录状态已过期,您可以继续留在该页面,或者重新登录",
|
||||
"系统提示",
|
||||
{
|
||||
confirmButtonText: "重新登录",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
},
|
||||
)
|
||||
.then(() => {
|
||||
isRelogin.show = false;
|
||||
useUserStore()
|
||||
.logout()
|
||||
.then(() => {
|
||||
router.replace({
|
||||
path: "/login",
|
||||
query: {
|
||||
redirect: encodeURIComponent(
|
||||
router.currentRoute.value.fullPath || "/",
|
||||
),
|
||||
},
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
isRelogin.show = false;
|
||||
});
|
||||
}
|
||||
isRelogin.show = true;
|
||||
ElMessageBox.confirm(
|
||||
"登录状态已过期,您可以继续留在该页面,或者重新登录",
|
||||
"系统提示",
|
||||
{
|
||||
confirmButtonText: "重新登录",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
},
|
||||
)
|
||||
.then(() => {
|
||||
isRelogin.show = false;
|
||||
useUserStore()
|
||||
.logout()
|
||||
.then(() => {
|
||||
router.replace({
|
||||
path: "/login",
|
||||
query: {
|
||||
redirect: encodeURIComponent(
|
||||
router.currentRoute.value.fullPath || "/",
|
||||
),
|
||||
},
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
isRelogin.show = false;
|
||||
});
|
||||
}
|
||||
return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
|
||||
} else if (code === HttpStatus.SERVER_ERROR) {
|
||||
ElMessage({ message: msg, type: 'error' });
|
||||
ElMessage({message: msg, type: 'error'});
|
||||
return Promise.reject(createHandledError(msg));
|
||||
} else if (code === HttpStatus.WARN) {
|
||||
ElMessage({ message: msg, type: 'warning' });
|
||||
ElMessage({message: msg, type: 'warning'});
|
||||
return Promise.reject(createHandledError(msg));
|
||||
} else if (code !== HttpStatus.SUCCESS) {
|
||||
ElNotification.error({ title: msg });
|
||||
ElNotification.error({title: msg});
|
||||
return Promise.reject(createHandledError(msg));
|
||||
} else {
|
||||
return Promise.resolve(res.data);
|
||||
@@ -250,11 +250,12 @@ service.interceptors.response.use(
|
||||
},
|
||||
async (error: any) => {
|
||||
const message = (await extractErrorMessage(error)) || errorCode['default'];
|
||||
ElMessage({ message: message, type: 'error', duration: 5 * 1000 });
|
||||
ElMessage({message: message, type: 'error', duration: 5 * 1000});
|
||||
error.isHandled = true;
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 通用下载方法
|
||||
export function download(url: string, params: any, fileName: string) {
|
||||
downloadLoadingInstance = ElLoading.service({
|
||||
@@ -263,34 +264,35 @@ export function download(url: string, params: any, fileName: string) {
|
||||
});
|
||||
// prettier-ignore
|
||||
return service
|
||||
.post(url, params, {
|
||||
transformRequest: [
|
||||
(params: any) => {
|
||||
return tansParams(params);
|
||||
},
|
||||
],
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
responseType: "blob",
|
||||
})
|
||||
.then(async (resp: any) => {
|
||||
const isLogin = blobValidate(resp);
|
||||
if (isLogin) {
|
||||
const blob = new Blob([resp]);
|
||||
saveBlob(blob, fileName);
|
||||
} else {
|
||||
const blob = new Blob([resp]);
|
||||
const resText = await blob.text();
|
||||
const rspObj = JSON.parse(resText);
|
||||
const errMsg =
|
||||
errorCode[rspObj.code] || rspObj.msg || errorCode["default"];
|
||||
ElMessage.error(errMsg);
|
||||
}
|
||||
downloadLoadingInstance?.close();
|
||||
})
|
||||
.catch((r: any) => {
|
||||
console.error(r);
|
||||
downloadLoadingInstance?.close();
|
||||
});
|
||||
.post(url, params, {
|
||||
transformRequest: [
|
||||
(params: any) => {
|
||||
return tansParams(params);
|
||||
},
|
||||
],
|
||||
headers: {"Content-Type": "application/x-www-form-urlencoded"},
|
||||
responseType: "blob",
|
||||
})
|
||||
.then(async (resp: any) => {
|
||||
const isLogin = blobValidate(resp);
|
||||
if (isLogin) {
|
||||
const blob = new Blob([resp]);
|
||||
saveBlob(blob, fileName);
|
||||
} else {
|
||||
const blob = new Blob([resp]);
|
||||
const resText = await blob.text();
|
||||
const rspObj = JSON.parse(resText);
|
||||
const errMsg =
|
||||
errorCode[rspObj.code] || rspObj.msg || errorCode["default"];
|
||||
ElMessage.error(errMsg);
|
||||
}
|
||||
downloadLoadingInstance?.close();
|
||||
})
|
||||
.catch((r: any) => {
|
||||
console.error(r);
|
||||
downloadLoadingInstance?.close();
|
||||
});
|
||||
}
|
||||
|
||||
// 导出 axios 实例
|
||||
export default service;
|
||||
|
||||
Reference in New Issue
Block a user