feat(frontend): improve admin usability and light theme
This commit is contained in:
@@ -12,6 +12,14 @@ export interface HttpResponse<T = unknown> {
|
||||
}
|
||||
|
||||
let initialized = false;
|
||||
let sessionExpiredDialogVisible = false;
|
||||
|
||||
function networkErrorMessage(error: unknown) {
|
||||
if (!axios.isAxiosError<HttpResponse>(error)) return '网络请求失败,请稍后重试';
|
||||
if (!error.response) return '无法连接服务器,请检查网络后重试';
|
||||
if (error.response.status === 403) return '当前账号无权执行此操作';
|
||||
return error.response.data?.msg || `请求失败(${error.response.status})`;
|
||||
}
|
||||
|
||||
export function setupHttp() {
|
||||
if (initialized) {
|
||||
@@ -47,27 +55,35 @@ export function setupHttp() {
|
||||
[50008, 50012, 50014].includes(res.code) &&
|
||||
response.config.url !== '/api/user/info'
|
||||
) {
|
||||
Modal.error({
|
||||
if (!sessionExpiredDialogVisible) {
|
||||
sessionExpiredDialogVisible = true;
|
||||
Modal.error({
|
||||
title: '登录已失效',
|
||||
content: '当前登录状态已失效,请重新登录。',
|
||||
content: '当前登录状态已失效。重新登录后将返回当前页面。',
|
||||
okText: '重新登录',
|
||||
async onOk() {
|
||||
const userStore = useUserStore();
|
||||
sessionStorage.setItem('auth-redirect', `${window.location.pathname}${window.location.search}`);
|
||||
await userStore.logout();
|
||||
window.location.reload();
|
||||
window.location.assign('/login');
|
||||
},
|
||||
});
|
||||
onCancel() {
|
||||
sessionExpiredDialogVisible = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
return Promise.reject(new Error(res.msg || '请求失败'));
|
||||
}
|
||||
return res as unknown as AxiosResponse<HttpResponse>;
|
||||
},
|
||||
(error) => {
|
||||
const content = networkErrorMessage(error);
|
||||
Message.error({
|
||||
content: error.msg || '网络请求失败',
|
||||
content,
|
||||
duration: 5 * 1000,
|
||||
});
|
||||
return Promise.reject(error);
|
||||
return Promise.reject(new Error(content));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user