/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Empty, Tag } from 'antd';
import { Table } from '@/components/ui';
import { ConsoleAlert as Alert } from '../console/ConsolePrimitives';
import { listDecisions } from './api';
import { gateText, jevReasonText, srcText } from './labels';
// 判定明细:只读 router_eval_records(§12.3)
const DecisionTable = ({ mode, orgId }) => {
const { t } = useTranslation();
const [data, setData] = useState({ items: [], total: 0 });
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(20);
const [loading, setLoading] = useState(true);
const [error, setError] = useState('');
const load = useCallback(async () => {
setLoading(true);
setError('');
try {
setData(
(await listDecisions(mode, orgId, {
p: page,
page_size: pageSize,
})) || {
items: [],
total: 0,
},
);
} catch (e) {
setError(e?.message || t('加载失败'));
} finally {
setLoading(false);
}
}, [mode, orgId, page, pageSize, t]);
useEffect(() => {
load();
}, [load]);
const columns = [
{
title: t('时间'),
dataIndex: 'created_at',
width: 180,
render: (v) => (
{new Date(v * 1000).toLocaleString()}
),
},
{
title: t('虚拟模型'),
dataIndex: 'virtual_model',
width: 180,
render: (v) => {v},
},
{
title: t('实际模型'),
dataIndex: 'actual_model',
width: 200,
render: (v) => {v || '-'},
},
{
title: t('判定来源'),
dataIndex: 'src',
width: 200,
render: (v, r) => (
{srcText(t, v)}
{r.reason ? ` · ${jevReasonText(t, r.reason)}` : ''}
),
},
{
title: t('任务 / 难度档'),
key: 'task',
width: 140,
render: (_, r) => `${r.task || '-'} / ${r.difficulty_tier}`,
},
{
title: t('合规闸门'),
dataIndex: 'gate',
width: 140,
render: (v) => gateText(t, v),
},
{
title: t('状态码'),
dataIndex: 'status_code',
width: 90,
align: 'right',
render: (v) => {v},
},
{
title: t('判定耗时'),
dataIndex: 'judge_ms',
width: 110,
align: 'right',
render: (v) => (
{v ? `${v} ms` : '-'}
),
},
];
if (error)
return (
{t('重试')}
}
/>
);
return (
}
pagination={{
current: page,
pageSize,
total: data.total || 0,
size: 'small',
showSizeChanger: mode === 'org',
onPageSizeChange:
mode === 'org'
? (size) => {
setPage(1);
setPageSize(size);
}
: undefined,
showTotal: (total) => t('共 {{total}} 条', { total }),
onChange: setPage,
}}
/>
);
};
export default DecisionTable;