437a0345e8
- 公共表格:统一分组标签、状态开关和危险操作确认,支持防重复提交和失败重试,修复浮层触发组件的 ref 转发。 - 控制台:统一用户和渠道编辑抽屉,修正分组回填与提交格式,对齐系统设置操作区和预约列表。 - 企业中心:调整技能中心页签和窄屏布局,优化质量监控提示栏、效能分析及成本对账,统一消耗明细和审计日志筛选。 - 用户中心及公共页面:优化密钥和消费记录展示,对齐模型超市筛选,统一公开与内嵌客户端下载页。 - 同步多语言文案、组件规范与移动端视口要求。
77 lines
1.8 KiB
React
77 lines
1.8 KiB
React
import React, { useRef, useState } from 'react';
|
|
import { Popconfirm } from 'antd';
|
|
|
|
export default function TableActionPopconfirm({
|
|
children,
|
|
content,
|
|
position,
|
|
onConfirm,
|
|
...props
|
|
}) {
|
|
const [open, setOpen] = useState(false);
|
|
const cancelButton = useRef(null);
|
|
const trigger = useRef(null);
|
|
const pending = useRef(false);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
|
|
const confirm = (event) => {
|
|
if (pending.current) return;
|
|
pending.current = true;
|
|
setSubmitting(true);
|
|
void (async () => {
|
|
try {
|
|
if ((await onConfirm(event)) !== false) setOpen(false);
|
|
} catch {
|
|
// The request or page already reports the error.
|
|
} finally {
|
|
pending.current = false;
|
|
setSubmitting(false);
|
|
}
|
|
})();
|
|
};
|
|
|
|
const cancel = () => {
|
|
if (pending.current) return;
|
|
setOpen(false);
|
|
trigger.current?.focus();
|
|
};
|
|
|
|
const handleKeyDown = (event) => {
|
|
if (event.key === 'Escape') {
|
|
event.stopPropagation();
|
|
cancel();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Popconfirm
|
|
{...props}
|
|
open={open}
|
|
description={content ?? props.description}
|
|
placement={position ?? props.placement}
|
|
onOpenChange={(nextOpen) => {
|
|
if (pending.current) return;
|
|
if (nextOpen) trigger.current = document.activeElement;
|
|
setOpen(nextOpen);
|
|
}}
|
|
afterOpenChange={(visible) => {
|
|
if (visible) cancelButton.current?.focus();
|
|
}}
|
|
onConfirm={confirm}
|
|
onCancel={cancel}
|
|
cancelButtonProps={{
|
|
ref: cancelButton,
|
|
disabled: submitting,
|
|
onKeyDown: handleKeyDown,
|
|
}}
|
|
okButtonProps={{
|
|
danger: true,
|
|
loading: submitting,
|
|
onKeyDown: handleKeyDown,
|
|
}}
|
|
>
|
|
{children}
|
|
</Popconfirm>
|
|
);
|
|
}
|