import { useEffect, useState } from 'react'; import { Alert, Badge, Button, Field, Input } from './ui.jsx'; const selectedBlue = '#2563EB'; export function toneForStatus(status) { if (['启用', '在线', '正常', '生效', '已计费', '完成', '已完成', '开启', '可试听', '成功'].includes(status)) return 'success'; if (['观察', '抖动', '待质检', '处理中', '失败不计费'].includes(status)) return 'warning'; if (['停用', '禁用', '暂停', '告警', '关闭', '失败'].includes(status)) return 'danger'; return 'neutral'; } export function Icon({ type }) { const common = { width: 16, height: 16, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round' }; const paths = { plus: , search: <>, export: <>, reload: <>, arrow: <>, phoneOff: <>, collapse: <>, expand: <>, logout: <>, }; return {paths[type]}; } export function PageTitle({ title, desc, actions }) { return (

{title}

{desc}

{actions}
); } export function Toolbar({ children }) { return
{children}
; } export function DateRangeFields({ startDate, endDate, onStartChange, onEndChange }) { return ( <> onStartChange(event.target.value)} /> onEndChange(event.target.value)} /> ); } export function Pagination({ total, take, skip, count, loading, onPageChange, onPageSizeChange }) { const start = total ? skip + 1 : 0; const end = Math.min(total, skip + count); return (
显示 {start}-{end} 条,共 {total} 条
); } export function Panel({ title, aside, children, className = '' }) { return (

{title}

{aside}
{children}
); } export function ApiNotice({ loading, error, onRetry }) { if (loading) { return null; } if (error) { return ( {error} {onRetry ? : null} ); } return null; } export function PageLoadingDialog({ loading, message = '页面加载中,请稍候…', delay = 2000 }) { const [visible, setVisible] = useState(false); useEffect(() => { if (!loading) { setVisible(false); return undefined; } const timer = window.setTimeout(() => setVisible(true), delay); return () => window.clearTimeout(timer); }, [delay, loading]); if (!visible) return null; return (
); } export function EmptyState({ title = '暂无数据', children = '当前筛选条件下没有可展示的数据。' }) { return (
{title} {children}
); } export function Modal({ title, aside, children, onClose, size = 'lg' }) { return (
event.stopPropagation()}>

{title}

{aside}
{children}
); } export function ConfirmDialog({ title, children, confirmLabel = '确认', confirmVariant = 'primary', busy = false, onCancel, onConfirm, }) { return ( {} : onCancel} size="sm">
{typeof children === 'string' ?

{children}

: children}
); } export function Drawer({ title, aside, children, onClose }) { return (
); } export function StatusBadge({ children }) { return {children}; } export function SimpleTable({ columns, rows, onRowClick, selectedKey, loading = false, emptyTitle = '暂无数据', emptyDescription }) { return (
{columns.some((column) => column.width) ? ( {columns.map((column) => )} ) : null} {columns.map((column) => )} {loading && rows.length === 0 ? Array.from({ length: 4 }, (_, rowIndex) => ( {columns.map((column) => )} )) : rows.length === 0 ? ( ) : rows.map((row, index) => ( onRowClick(row) : undefined} > {columns.map((column) => ( ))} ))}
{column.label}
{emptyDescription}
{column.status ? {row[column.key]} : column.render ? column.render(row) : row[column.key]}
); } export function MiniBarChart({ data, color = selectedBlue }) { const max = Math.max(1, ...data); return (
{data.map((value, index) => ( ))}
); } export function LineChart({ data }) { const points = data.map((value, index) => `${(index / Math.max(1, data.length - 1)) * 100},${100 - value}`).join(' '); return ( ); } export function KeyValue({ label, value }) { return (
{label} {value}
); }