提示优化
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user