提示优化

This commit is contained in:
fuenmao
2026-09-02 15:55:12 +08:00
parent 058727982b
commit 7e74fb3b4b
8 changed files with 262 additions and 42 deletions
+33
View File
@@ -0,0 +1,33 @@
/** 判断 Element Plus 弹窗是否由用户主动取消或关闭。 */
function isUserCancelled(action: unknown) {
return action === "cancel" || action === "close";
}
/**
* 执行确认弹窗。用户取消时返回 false,真正的异常继续抛出。
*/
export async function isMessageBoxConfirmed(confirmPromise: Promise<unknown>) {
try {
await confirmPromise;
return true;
} catch (action) {
if (isUserCancelled(action)) {
return false;
}
throw action;
}
}
/**
* 执行输入弹窗。用户取消时返回 null,真正的异常继续抛出。
*/
export async function getMessageBoxPromptResult<T>(promptPromise: Promise<T>) {
try {
return await promptPromise;
} catch (action) {
if (isUserCancelled(action)) {
return null;
}
throw action;
}
}