import { useEffect, useMemo, useState } from 'react'; import { Plus, Search } from 'lucide-react'; import { Breadcrumb, Button, Input, Modal, Select, Table, Textarea, Tag, type TableColumn } from '@/components/ui'; import { adminApi, type DictionaryItem } from '@/api/adminApi'; type DrainageField = DictionaryItem & { code?: string; name?: string; fieldType?: string; required?: boolean; description?: string | null; }; type ReportFieldType = 'string' | 'image' | 'file'; const typeOptions = [ { label: '全部类型', value: 'all' }, { label: '字符串', value: 'string' }, { label: '图片', value: 'image' }, { label: '文件', value: 'file' }, ]; const typeLabels: Record = { string: '字符串', image: '图片', file: '文件' }; export function AdminDrainageFieldsPage() { const [fields, setFields] = useState([]); const [keyword, setKeyword] = useState(''); const [appliedKeyword, setAppliedKeyword] = useState(''); const [type, setType] = useState('all'); const [appliedType, setAppliedType] = useState('all'); const [creating, setCreating] = useState(false); const [code, setCode] = useState(''); const [name, setName] = useState(''); const [fieldType, setFieldType] = useState('string'); const [description, setDescription] = useState(''); const [error, setError] = useState(''); function loadData() { adminApi.listDrainageFields() .then((items) => { setFields(items as DrainageField[]); setError(''); }) .catch((failure: Error) => setError(failure.message || '报备字段加载失败')); } useEffect(() => { loadData(); }, []); const filteredFields = useMemo( () => fields.filter((field) => { const matchesKeyword = !appliedKeyword || [field.code, field.name, field.fieldType, field.description].some((value) => String(value ?? '').includes(appliedKeyword)); const matchesType = appliedType === 'all' || field.fieldType === appliedType; return matchesKeyword && matchesType; }), [appliedKeyword, appliedType, fields], ); function createField() { adminApi.createDrainageField({ code, name, fieldType, description, status: 'active' }) .then(() => { setCode(''); setName(''); setFieldType('string'); setDescription(''); setCreating(false); loadData(); }) .catch((failure: Error) => setError(failure.message || '报备字段新增失败')); } const columns = useMemo>>(() => [ { key: 'code', title: '字段代码', width: '160px', render: (record) => {record.code} }, { key: 'name', title: '字段名称', width: '190px', render: (record) => record.name ?? '-' }, { key: 'type', title: '字段类型', width: '160px', render: (record) => {typeLabels[record.fieldType ?? ''] ?? record.fieldType} }, { key: 'description', title: '描述', render: (record) => record.description ?? '-' }, { key: 'required', title: '是否必填', width: '120px', render: (record) => {record.required ? '必填' : '选填'} }, ], []); return (

报备字段库

{error ?

{error}

: null}
setKeyword(event.target.value)} placeholder="搜索字段名称、代码或描述..." prefix={} value={keyword} /> setCode(event.target.value)} value={code} /> setName(event.target.value)} value={name} />