import { useEffect, useState } from 'react'; import { Button, Checkbox, Modal, Space, Typography } from 'antd'; import { HolderOutlined } from '@ant-design/icons'; import type { ListColumnSettingItem } from '../lib/list-column-prefs'; type Props = { open: boolean; items: ListColumnSettingItem[]; saving?: boolean; onCancel: () => void; onReset: () => void; onSave: (items: ListColumnSettingItem[]) => void; }; export function AdminListColumnsModal({ open, items, saving, onCancel, onReset, onSave }: Props) { const [draft, setDraft] = useState(items); const [dragKey, setDragKey] = useState(null); useEffect(() => { if (open) setDraft(items); }, [open, items]); function move(from: number, to: number) { if (to < 0 || to >= draft.length) return; const next = [...draft]; const [row] = next.splice(from, 1); next.splice(to, 0, row); setDraft(next); } return ( } > 勾选显示列,拖拽或上下箭头调整顺序。序号与操作列固定,不在此列表中。
{draft.map((item, index) => (
setDragKey(item.key)} onDragOver={(e) => e.preventDefault()} onDrop={() => { if (!dragKey || dragKey === item.key) return; const from = draft.findIndex((r) => r.key === dragKey); if (from >= 0) move(from, index); setDragKey(null); }} style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '6px 0', borderBottom: '1px solid #f0f0f0', cursor: 'move', }} > { const next = [...draft]; next[index] = { ...item, visible: e.target.checked }; setDraft(next); }} > {item.title}
))}
); }