mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
refactor: 优化错误处理和消息提示机制
- 移除前端冗余的错误消息提示,统一使用console.error记录错误 - 使用后端返回的msg作为成功提示消息 - 更新演示环境地址和API端口配置 - 清理缓存管理模块的冗余消息提示 - 改进认证错误提示信息,增加状态码 ``` 这个提交消息: 1. 使用refactor类型,因为主要是代码结构的优化而非功能修改 2. 概括了主要修改内容:错误处理和消息提示机制的优化 3. 在消息体中列出了具体修改点,包括: - 前端错误处理方式统一 - 成功提示消息来源调整 - 配置更新 - 特定模块的清理 - 认证提示改进
This commit is contained in:
+17
-59
@@ -207,16 +207,11 @@ const getCacheNameList = () => {
|
||||
loading.value = true;
|
||||
getCacheNames()
|
||||
.then(({ data: result }) => {
|
||||
if (result.status_code === 200) {
|
||||
cacheNames.value = result.data || [];
|
||||
resetCacheForm();
|
||||
} else {
|
||||
message.error(result.msg)
|
||||
}
|
||||
cacheNames.value = result.data || [];
|
||||
resetCacheForm();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取缓存列表出错:', error);
|
||||
message.error('获取缓存列表失败');
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
@@ -226,7 +221,6 @@ const getCacheNameList = () => {
|
||||
// 刷新缓存列表
|
||||
const refreshCacheNames = () => {
|
||||
getCacheNameList();
|
||||
message.success('刷新缓存列表成功');
|
||||
};
|
||||
|
||||
// 清理缓存名称
|
||||
@@ -236,17 +230,11 @@ const handleClearCacheName = (row: CacheInfo) => {
|
||||
content: `确定要清理缓存名称[${row.cache_name}]吗?`,
|
||||
onOk() {
|
||||
deleteCacheName(row.cache_name)
|
||||
.then(({ data: result }) => {
|
||||
if (result.status_code === 200) {
|
||||
message.success(result.msg);
|
||||
getCacheNameList();
|
||||
} else {
|
||||
message.error(result.msg)
|
||||
}
|
||||
.then(() => {
|
||||
getCacheNameList();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('清理缓存失败:', error);
|
||||
message.error('清理缓存失败');
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -260,22 +248,16 @@ const getCacheKeyList = (row?: CacheInfo) => {
|
||||
subLoading.value = true;
|
||||
getCacheKeys(cacheName)
|
||||
.then(({ data: result }) => {
|
||||
if (result.status_code === 200) {
|
||||
cacheKeys.value = result.data || [];
|
||||
nowCacheName.value = cacheName;
|
||||
cacheForm.value = {
|
||||
cache_name: cacheName,
|
||||
cache_key: '',
|
||||
cache_value: ''
|
||||
};
|
||||
message.success(result.msg);
|
||||
} else {
|
||||
message.error(result.msg)
|
||||
}
|
||||
cacheKeys.value = result.data || [];
|
||||
nowCacheName.value = cacheName;
|
||||
cacheForm.value = {
|
||||
cache_name: cacheName,
|
||||
cache_key: '',
|
||||
cache_value: ''
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取缓存键名列表失败:', error);
|
||||
message.error('获取缓存键名列表失败');
|
||||
})
|
||||
.finally(() => {
|
||||
subLoading.value = false;
|
||||
@@ -285,7 +267,6 @@ const getCacheKeyList = (row?: CacheInfo) => {
|
||||
// 刷新键名列表
|
||||
const refreshCacheKeys = () => {
|
||||
getCacheKeyList();
|
||||
message.success('刷新键名列表成功');
|
||||
};
|
||||
|
||||
// 清理缓存键名
|
||||
@@ -296,16 +277,10 @@ const handleClearCacheKey = (cacheKey: string) => {
|
||||
onOk() {
|
||||
deleteCacheKey(cacheKey)
|
||||
.then(({ data: result }) => {
|
||||
if (result.status_code === 200) {
|
||||
message.success(result.msg);
|
||||
getCacheKeyList();
|
||||
} else {
|
||||
message.error(result.msg)
|
||||
}
|
||||
getCacheKeyList();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('清理缓存键名失败:', error);
|
||||
message.error('清理缓存键名失败');
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -315,16 +290,10 @@ const handleClearCacheKey = (cacheKey: string) => {
|
||||
const handleCacheValue = (cacheKey: string) => {
|
||||
getCacheValue(nowCacheName.value, cacheKey)
|
||||
.then(({ data: result }) => {
|
||||
if (result.status_code === 200) {
|
||||
cacheForm.value = result.data;
|
||||
message.success(result.msg);
|
||||
} else {
|
||||
message.error(result.msg)
|
||||
}
|
||||
cacheForm.value = result.data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取缓存内容失败:', error);
|
||||
message.error('获取缓存内容失败');
|
||||
});
|
||||
};
|
||||
|
||||
@@ -335,17 +304,11 @@ const handleClearCacheAll = () => {
|
||||
content: '确定要清理全部缓存吗?',
|
||||
onOk() {
|
||||
deleteCacheAll()
|
||||
.then(({ data: result }) => {
|
||||
if (result.status_code === 200) {
|
||||
message.success(result.msg);
|
||||
getCacheNameList();
|
||||
} else {
|
||||
message.error(result.msg)
|
||||
}
|
||||
.then(() => {
|
||||
getCacheNameList();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('清理全部缓存失败:', error);
|
||||
message.error('清理全部缓存失败');
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -355,20 +318,15 @@ const handleClearCacheAll = () => {
|
||||
const getInfo = () => {
|
||||
getCacheInfo()
|
||||
.then(({ data: result }) => {
|
||||
if (result.status_code === 200) {
|
||||
cache.value = result.data || {
|
||||
cache.value = result.data || {
|
||||
info: {},
|
||||
command_stats: [],
|
||||
dbSize: 0
|
||||
};
|
||||
initCharts();
|
||||
message.success(result.msg || '获取缓存监控数据成功');
|
||||
} else {
|
||||
message.error(result.msg || '获取缓存监控数据失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
message.error('获取缓存监控数据失败:', error);
|
||||
console.error('获取缓存监控数据失败:', error);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -149,9 +149,8 @@ const handleForceLogout = (row: OnlineUser) => {
|
||||
try {
|
||||
await deleteOnline(row.session_id);
|
||||
await loadingData();
|
||||
message.success('强退成功');
|
||||
} catch (error) {
|
||||
message.error('强退失败');
|
||||
console.error('强退失败:', error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -301,8 +301,7 @@ async function getList() {
|
||||
const response = await getServer();
|
||||
server.value = response.data.data;
|
||||
} catch (error) {
|
||||
message.error('获取服务器信息失败');
|
||||
console.error(error);
|
||||
console.error('获取服务器信息失败:', error);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ const handleModalSubmit = () => {
|
||||
forgetPassword(forgetPasswordForm)
|
||||
.then(response => {
|
||||
if (response.data.status_code === 200) {
|
||||
message.success('密码重置成功');
|
||||
message.success(response.data.msg);
|
||||
modalVisible.value = false;
|
||||
}
|
||||
})
|
||||
@@ -245,7 +245,7 @@ const handleModalSubmit = () => {
|
||||
registerUser({ ...registerForm })
|
||||
.then(response => {
|
||||
if (response.data.status_code === 200) {
|
||||
message.success('注册成功');
|
||||
message.success(response.data.msg);
|
||||
modalVisible.value = false;
|
||||
}
|
||||
})
|
||||
|
||||
@@ -172,7 +172,6 @@ const loadConfigData = async () => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载配置数据失败:', error);
|
||||
message.error('加载配置数据失败');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -209,11 +208,9 @@ const handleUpload = async (options: any, type: string) => {
|
||||
}
|
||||
|
||||
onSuccess(response, file);
|
||||
message.success('上传成功');
|
||||
} catch (error) {
|
||||
onError(error);
|
||||
console.error('上传失败:', error);
|
||||
message.error('上传失败');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -222,11 +219,9 @@ const handleSave = async () => {
|
||||
try {
|
||||
// 调用更新配置接口
|
||||
await updateConfig(configData);
|
||||
message.success('配置保存成功');
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
console.error('保存配置失败:', error);
|
||||
message.error('配置保存失败');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -401,10 +401,8 @@ const loadDictTypes = () => {
|
||||
getDictTypeOptionselect().then(response => {
|
||||
const result = response.data;
|
||||
dictTypeOptions.value = result.data;
|
||||
message.success(result.msg);
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
message.error('获取字典类型失败');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -173,7 +173,6 @@ const init = async (record: tableDataType) => {
|
||||
|
||||
} catch (error) {
|
||||
console.error('获取权限数据失败:', error);
|
||||
message.error('获取权限数据失败');
|
||||
} finally {
|
||||
tableLoading.value = false;
|
||||
}
|
||||
@@ -197,7 +196,6 @@ const handleDrawerSave = () => {
|
||||
emit('event');
|
||||
}).catch(error => {
|
||||
console.error('保存权限失败:', error);
|
||||
message.error('保存权限失败');
|
||||
drawerSaving.value = false;
|
||||
})
|
||||
}
|
||||
|
||||
@@ -903,7 +903,7 @@ const customRequest = ({ file, onSuccess, onError, onProgress }: any) => {
|
||||
fileItem.percent = 100;
|
||||
upload.isUploading = false;
|
||||
upload.open = false;
|
||||
message.success('用户导入成功');
|
||||
message.success(response.data.msg);
|
||||
onSuccess(response);
|
||||
loadingData(); // 刷新数据
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user