增加审批组件
This commit is contained in:
parent
0a64cfc339
commit
07db17faf6
@ -4,7 +4,35 @@ import { X } from "lucide-react"
|
|||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
const Dialog = DialogPrimitive.Root
|
/**
|
||||||
|
* 修复 Radix UI Dialog 关闭后 body.style.pointerEvents 残留的问题
|
||||||
|
* 当 Dialog 从打开变为关闭时,自动清理 body 样式
|
||||||
|
*/
|
||||||
|
const Dialog: React.FC<React.ComponentPropsWithoutRef<typeof DialogPrimitive.Root>> = ({ open, onOpenChange, ...props }) => {
|
||||||
|
// 监听 open 状态变化,关闭时清理 body 样式
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (open === false) {
|
||||||
|
// 延迟执行,确保在 Dialog 关闭动画之后
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
// 强制移除 body 的 pointer-events 限制
|
||||||
|
if (document.body.style.pointerEvents === 'none') {
|
||||||
|
document.body.style.pointerEvents = '';
|
||||||
|
}
|
||||||
|
}, 350); // 稍微比 Dialog 动画时间(200ms)长一点
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Root
|
||||||
|
open={open}
|
||||||
|
onOpenChange={onOpenChange}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
Dialog.displayName = "Dialog"
|
||||||
|
|
||||||
const DialogTrigger = DialogPrimitive.Trigger
|
const DialogTrigger = DialogPrimitive.Trigger
|
||||||
|
|
||||||
|
|||||||
@ -47,21 +47,20 @@ const FormBasicInfoModal: React.FC<FormBasicInfoModalProps> = ({
|
|||||||
|
|
||||||
// 加载分类列表和初始化数据
|
// 加载分类列表和初始化数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible) {
|
// 只在弹窗打开时初始化数据
|
||||||
loadCategories();
|
if (!visible) return;
|
||||||
if (mode === 'edit' && record) {
|
|
||||||
setFormData({
|
loadCategories();
|
||||||
name: record.name,
|
|
||||||
key: record.key,
|
if (mode === 'edit' && record) {
|
||||||
categoryId: record.categoryId,
|
setFormData({
|
||||||
description: record.description || '',
|
name: record.name,
|
||||||
isTemplate: record.isTemplate || false,
|
key: record.key,
|
||||||
});
|
categoryId: record.categoryId,
|
||||||
} else if (mode === 'create') {
|
description: record.description || '',
|
||||||
resetForm();
|
isTemplate: record.isTemplate || false,
|
||||||
}
|
});
|
||||||
} else {
|
} else if (mode === 'create') {
|
||||||
// 弹窗关闭时重置表单数据
|
|
||||||
resetForm();
|
resetForm();
|
||||||
}
|
}
|
||||||
}, [visible, mode, record?.id]); // 只依赖 record.id 而不是整个 record 对象
|
}, [visible, mode, record?.id]); // 只依赖 record.id 而不是整个 record 对象
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user