fix: 增强右键菜单操作完成后的反馈逻辑,添加具体错误信息提示,优化用户体验

This commit is contained in:
xudan 2025-10-16 10:57:32 +08:00
parent 2ac24349a8
commit a4f0027ee1
4 changed files with 36 additions and 17 deletions

View File

@ -162,13 +162,17 @@ const handleOpenChange = (open: boolean) => {
};
//
const handleActionComplete = (data: any) => {
const handleActionComplete = (data: { success: boolean; action: string; message?: string }) => {
console.log('菜单操作完成:', data);
const actionName = getActionDisplayName(data.action);
//
if (data.success) {
const actionName = getActionDisplayName(data.action);
message.success(`${actionName}操作成功`);
} else {
// 使
const errorMessage = data.message || `${actionName}操作失败`;
message.error(errorMessage);
}
emit('actionComplete', data);

View File

@ -261,6 +261,7 @@ const handleStorageAction = async (action: string, actionName: string) => {
action,
location: selectedLocation.value,
success: false,
message: error instanceof Error ? error.message : String(error),
});
}
};

View File

@ -625,8 +625,14 @@ const handleCloseContextMenu = () => {
*/
const handleActionComplete = (data: any) => {
console.log('右键菜单操作完成:', data);
//
//
// 便
handleCloseContextMenu();
//
if (data.success) {
// : sceneStore.refreshData();
//
}
};
/**

View File

@ -10,14 +10,14 @@ export class StorageActionService {
* @param actionName
*/
static async handleStorageAction(
action: string,
location: StorageLocationInfo,
action: string,
location: StorageLocationInfo,
actionName: string
): Promise<void> {
): Promise<{ success: boolean; message: string; data?: any }> {
try {
// 使用layer_name如果没有则使用id或name作为替代
const layerName = location.name;
if (!layerName) {
throw new Error(`库位 ${location.name} 缺少必要信息,无法执行操作`);
}
@ -36,17 +36,25 @@ export class StorageActionService {
// 调用API
const result = await batchUpdateStorageLocationStatus(requestParams);
// 处理结果 - 不在这里显示提示由context-menu统一处理
// 处理结果
if (result.data) {
const { failed_count } = result.data;
if (failed_count !== 0) {
// 失败,抛出错误让上层处理
throw new Error(`${actionName}操作失败`);
const { success_count, failed_count, results } = result.data;
if (failed_count > 0 && results && results.length > 0) {
const first_failed_item = results[0];
const errorMessage = first_failed_item.message || `${actionName}操作失败`;
throw new Error(errorMessage);
}
if (success_count > 0) {
return { success: true, message: `${actionName}操作成功`, data: result.data };
}
}
} catch (error) {
// 默认情况下,如果没有成功或失败的明确指示,我们认为操作失败
throw new Error(`${actionName}操作失败,响应无效`);
} catch (error: any) {
console.error(`库位${actionName}失败:`, error);
// 重新抛出错误,让上层处理提示
throw error;
@ -93,7 +101,7 @@ export class StorageActionService {
// 处理结果 - 不在这里显示提示由context-menu统一处理
if (result.data) {
const { total_count, success_count, failed_count } = result.data;
const { failed_count } = result.data;
if (failed_count !== 0) {
// 失败,抛出错误让上层处理