iter(g175): 确认气泡支持异步确认

This commit is contained in:
HIsheR
2026-10-26 16:23:23 +08:00
parent 66c39e0145
commit cbce645b3b
6 changed files with 30 additions and 14 deletions
+12 -5
View File
@@ -12,12 +12,19 @@ export function popconfirm(props: PopconfirmProps, trigger: HTMLElement): HTMLEl
/*** 收起弹层:写回信号即触发 popover 的显隐与 Esc 栈清理 ***/
const close = (): void => { open(false); };
/*** 确认:先收起再回调,避免回调里同步改数据时弹层还开着 ***/
const idle = props.confirmText ?? '确定'; // 确认按钮常态文案,异步结束后还原
/*** 确认:同步回调先收起再执行(避免回调里改数据时弹层还开着);返回 Promise 时就地 loading,成功才收起、失败留在弹层重试 ***/
const accept = (): void => {
accepted = true;
close();
props.onConfirm();
const out = props.onConfirm();
if (!(out instanceof Promise)) { accepted = true; close(); return; }
okBtn.disabled = true;
okBtn.textContent = '处理中…';
out.then(() => { accepted = true; close(); })
.catch(() => { /* 失败保持展开:提示交给调用方的 toast */ })
.finally(() => { okBtn.disabled = false; okBtn.textContent = idle; });
};
const okBtn = button({ label: idle, variant: props.variant === 'danger' ? 'danger' : 'primary', onClick: () => accept() }) as HTMLButtonElement;
const body = h(
'div',
@@ -27,7 +34,7 @@ export function popconfirm(props: PopconfirmProps, trigger: HTMLElement): HTMLEl
'div',
{ class: 'ua-popconfirm-actions' },
button({ label: props.cancelText ?? '取消', variant: 'ghost', onClick: () => close() }),
button({ label: props.confirmText ?? '确定', variant: props.variant === 'danger' ? 'danger' : 'primary', onClick: () => accept() }),
okBtn,
),
);