fix: 增强右键菜单操作完成后的反馈逻辑,添加具体错误信息提示,优化用户体验
This commit is contained in:
parent
2ac24349a8
commit
a4f0027ee1
@ -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);
|
||||
|
@ -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),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -625,8 +625,14 @@ const handleCloseContextMenu = () => {
|
||||
*/
|
||||
const handleActionComplete = (data: any) => {
|
||||
console.log('右键菜单操作完成:', data);
|
||||
// 可以在这里添加操作完成后的处理逻辑
|
||||
// 比如刷新数据、显示消息等
|
||||
// 操作完成后,关闭菜单,以便下次打开时刷新数据
|
||||
handleCloseContextMenu();
|
||||
|
||||
// 如果成功,可以触发一个全局事件或调用一个方法来刷新整个场景的数据
|
||||
if (data.success) {
|
||||
// 例如: sceneStore.refreshData();
|
||||
// 目前,关闭菜单后,用户再次右键会看到最新状态,这已经满足了基本需求。
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
// 失败,抛出错误让上层处理
|
||||
|
Loading…
x
Reference in New Issue
Block a user