import { useEffect, useMemo, useState } from 'react'; import { Plus, Search, Trash2 } from 'lucide-react'; import { Breadcrumb, Button, Input, Modal, Select, Table, Tag, Textarea, type TableColumn } from '@/components/ui'; import { adminApi, type DictionaryItem, type EnterpriseApplication, type TenantOption } from '@/api/adminApi'; type EnterpriseBlacklistItem = DictionaryItem & { tenantId?: string; applicationId?: string; tenant?: TenantOption; application?: EnterpriseApplication; phoneNumber?: string; reason?: string | null; }; export function AdminEnterpriseBlacklistPage() { const [items, setItems] = useState([]); const [tenants, setTenants] = useState([]); const [applications, setApplications] = useState([]); const [enterpriseKeyword, setEnterpriseKeyword] = useState(''); const [applicationKeyword, setApplicationKeyword] = useState(''); const [phoneKeyword, setPhoneKeyword] = useState(''); const [reasonKeyword, setReasonKeyword] = useState(''); const [status, setStatus] = useState('all'); const [appliedFilters, setAppliedFilters] = useState({ enterpriseKeyword: '', applicationKeyword: '', phoneNumber: '', reasonKeyword: '', status: 'all' }); const [formTenantId, setFormTenantId] = useState(''); const [formApplicationId, setFormApplicationId] = useState(''); const [phone, setPhone] = useState(''); const [reason, setReason] = useState(''); const [modalOpen, setModalOpen] = useState(false); const [error, setError] = useState(''); function loadData(filters = appliedFilters) { Promise.all([ adminApi.listEnterpriseBlacklist(filters), adminApi.listTenants(), adminApi.listEnterpriseApplications(), ]) .then(([blacklist, tenantItems, applicationItems]) => { setItems(blacklist as EnterpriseBlacklistItem[]); setTenants(tenantItems); setApplications(applicationItems); setError(''); }) .catch((failure: Error) => setError(failure.message || '企业黑名单加载失败')); } useEffect(() => { loadData(); }, []); const modalApplications = applications.filter((application) => application.tenantId === formTenantId && application.status !== 'deleted'); const columns = useMemo>>(() => [ { key: 'enterprise', title: '企业名称', width: '180px', render: (record) => {record.tenant?.name ?? record.tenantId} }, { key: 'application', title: '应用名称', width: '180px', render: (record) => {record.application?.name ?? record.applicationId} }, { key: 'phone', title: '手机号码', width: '150px', render: (record) => {record.phoneNumber} }, { key: 'createdAt', title: '入库时间', width: '170px', render: (record) => record.createdAt ?? '-' }, { key: 'reason', title: '入库原因', render: (record) => record.reason ?? '-' }, { key: 'status', title: '状态', width: '130px', render: (record) => {record.status === 'active' ? '生效中' : record.status === 'deleted' ? '已删除' : record.status ?? '-'} }, { key: 'actions', title: '操作', width: '130px', align: 'right', render: (record) => ( ), }, ], [appliedFilters]); function addItem() { adminApi.createEnterpriseBlacklist({ tenantId: formTenantId, applicationId: formApplicationId, phoneNumber: phone, reason, status: 'active' }) .then(() => { setFormTenantId(''); setFormApplicationId(''); setPhone(''); setReason(''); setModalOpen(false); loadData(); }) .catch((failure: Error) => setError(failure.message || '添加企业黑名单失败')); } return (

企业黑名单

{error ?

{error}

: null}
setEnterpriseKeyword(event.target.value)} placeholder="请输入企业名称" prefix={} value={enterpriseKeyword} /> setApplicationKeyword(event.target.value)} placeholder="请输入企业应用名称" prefix={} value={applicationKeyword} /> setPhoneKeyword(event.target.value)} placeholder="请输入手机号码" value={phoneKeyword} /> setReasonKeyword(event.target.value)} placeholder="请输入入库原因" value={reasonKeyword} /> { setFormTenantId(event.target.value); setFormApplicationId(''); }} options={[{ label: '请选择企业', value: '' }, ...tenants.map((item) => ({ label: item.name, value: item.id }))]} value={formTenantId} /> setPhone(event.target.value)} placeholder="请输入手机号码" value={phone} />