优化:完善分类规则与Excel配置维护并加速查询翻页

This commit is contained in:
2026-10-31 17:50:14 +08:00
parent 9dbe85c65c
commit aa7c320dc6
56 changed files with 1709 additions and 440 deletions
+21 -69
View File
@@ -1,3 +1,4 @@
import { ManagementSections } from './ManagementSections';
import { configurationDateTime } from './configurationName';
import { alertObject, alertsForStatus, monitorLabel } from './taskMonitorModel';
import { useEffect, useRef, useState } from 'react';
@@ -12,7 +13,7 @@ import { isInternalDataField } from './publicDataDisplay';
import './completion.css';
type Row = Record<string, unknown>;
const TABLE_PAGE_SIZE = 20;
const TABLE_PAGE_SIZE = 15;
const INTERNAL_REVISION_FIELDS = new Set(['sourcerevisionid', 'targetrevisionid', 'expectedrevisionid', 'currentrevisionid', 'candidaterevisionid', 'baserevisionid']);
const obj = (value: unknown): Row => value && typeof value === 'object' && !Array.isArray(value) ? value as Row : {};
const rows = (value: unknown): Row[] => Array.isArray(value) ? value.filter(item => item && typeof item === 'object') as Row[] : [];
@@ -212,7 +213,7 @@ function InspectionStrategyPanel({ user, onUnauthorized }: { user: AuthUser; onU
{loading ? <div className="completion-loading"><Spin />读取巡检策略…</div> : canManage ? strategies.length ? <Table size="small" bordered columns={strategyColumns} dataSource={strategies} rowKey={row => String(row.id)} pagination={false} scroll={{ x: 1300 }} /> : <Empty description="服务端当前没有已登记的巡检策略" /> : null}
<div className="completion-filter-row">{canRun && <Button type="primary" loading={running} disabled={!releaseId} onClick={() => void run()}>对当前数据执行巡检</Button>}</div>
{!canRun && <Alert showIcon type="info" message="当前账号不能执行巡检" description="运行和结果查看需要服务端授权的质量查看或业务分析角色及明细查询权限。" />}
{canRun && (runs.length ? <Table size="small" bordered columns={runColumns} dataSource={runs} rowKey={row => String(row.id)} pagination={{ pageSize: 8, showSizeChanger: false }} scroll={{ x: 1120 }} /> : <Empty description={releaseId ? '当前数据尚无巡检运行记录' : '当前还没有可巡检的数据'} />)}
{canRun && (runs.length ? <Table size="small" bordered columns={runColumns} dataSource={runs} rowKey={row => String(row.id)} pagination={{ pageSize: 15, showSizeChanger: false }} scroll={{ x: 1120 }} /> : <Empty description={releaseId ? '当前数据尚无巡检运行记录' : '当前还没有可巡检的数据'} />)}
<Modal className="management-modal" open={editing !== null} title={editing?.id ? `编辑巡检策略 · ${text(editing.name)}` : '新建巡检策略'} okText="保存策略" confirmLoading={saving} onCancel={() => { setEditing(null); form.resetFields(); }} onOk={() => void save()} width={Math.min(820, window.innerWidth - 24)}>
<Form form={form} layout="vertical"><Form.Item name="name" label="策略名称" rules={[{ required: true, whitespace: true }]}><Input maxLength={100} /></Form.Item><Form.Item name="active" label="启用策略" valuePropName="checked"><Switch checkedChildren="启用" unCheckedChildren="停用" /></Form.Item><h3>巡检规则</h3><div className="governance-form-grid">{booleanFields.map(([key, label]) => <Form.Item key={key} name={key} label={label} valuePropName="checked"><Switch /></Form.Item>)}{metricFields.map(field => <Form.Item key={field.key} name={field.key} label={field.label} rules={[{ required: true }]}><InputNumber min={field.min} max={field.max} step={field.step} style={{ width: '100%' }} /></Form.Item>)}</div><p className="completion-note">阈值范围由服务端校验;保存后对后续巡检生效。</p></Form><Alert showIcon type="info" message="受控 AI 下钻" description="启用后仅为巡检发现创建绑定当前用户、当前数据与授权范围的持久化分析轮次;模型不接收业务数据行或业务数值。最多选择 1–3 项。" />
</Modal>
@@ -397,7 +398,7 @@ export function SourceGovernancePanel({ user, currentReleaseId, onUnauthorized }
{ key: 'coverage', label: '到齐与告警', children: <div className="governance-panel-body"><div className="governance-status-strip"><span>适用数据 <strong>当前数据</strong></span><Tag color={coverage?.complete === true ? 'green' : 'red'}>{coverage?.complete === true ? '覆盖完整' : coverage?.complete === false ? '覆盖未齐' : '未返回'}</Tag></div>{coverageItems.length ? <Table size="small" bordered columns={coverageColumns} dataSource={coverageItems} rowKey={row => String(row.protocolId || row.sourceSlot)} pagination={{ pageSize: TABLE_PAGE_SIZE, showSizeChanger: false }} scroll={{ x: 980 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="当前数据没有已登记的来源协议覆盖项" />}</div> },
{ key: 'protocols', label: `来源协议(${protocols.length})`, children: <div className="governance-panel-body">{protocols.length ? <Table size="small" bordered columns={protocolColumns} dataSource={protocols} rowKey={row => String(row.id)} pagination={{ pageSize: TABLE_PAGE_SIZE, showSizeChanger: false }} scroll={{ x: 1120 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="服务端尚未登记来源协议" />}</div> },
{ key: 'changes', label: `来源变更与撤销(${sourceChanges.length})`, children: <div className="governance-panel-body">{conflictCandidates.length > 0 && <Alert showIcon type="warning" message={`${conflictCandidates.length} 个来源身份待裁决`} description={<span>{conflictCandidates.map(item => <Button type="link" key={item.id} onClick={() => { setResolveItem(item); resolveForm.setFieldsValue({ decision: 'REPLACE' }); }}>{item.sourceFile} · 裁决</Button>)}</span>} />}{errors.changes ? <Alert type="error" message={errors.changes} /> : sourceChanges.length ? <Table size="small" bordered columns={changeColumns} dataSource={sourceChanges} rowKey={row => String(row.id)} pagination={{ pageSize: TABLE_PAGE_SIZE, showSizeChanger: false }} scroll={{ x: 1080 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无来源变更或撤销申请" />}</div> },
{ key: 'revisions', label: `原文件记录与证据(${revisions.length})`, children: <div className="governance-panel-body">{revisions.length ? <Table size="small" bordered columns={revisionColumns} dataSource={revisions} rowKey={row => String(row.id)} pagination={{ pageSize: 10, showSizeChanger: false }} scroll={{ x: 1280 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="服务端尚未返回归档原文件记录" />}</div> },
{ key: 'revisions', label: `原文件记录与证据(${revisions.length})`, children: <div className="governance-panel-body">{revisions.length ? <Table size="small" bordered columns={revisionColumns} dataSource={revisions} rowKey={row => String(row.id)} pagination={{ pageSize: 15, showSizeChanger: false }} scroll={{ x: 1280 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="服务端尚未返回归档原文件记录" />}</div> },
]} />
<Modal className="management-modal" open={protocolOpen} title="登记来源协议" width={760} okText="保存协议" confirmLoading={actionBusy === 'protocol'} onCancel={() => setProtocolOpen(false)} onOk={() => void submitProtocol()}>
<Alert showIcon type="info" message="协议定义用于来源身份和到齐校验" description="当前解析器仅验证月度快照和分片快照;来源槽位由阶段、期间、范围和分片共同确定。" />
@@ -418,61 +419,6 @@ export function SourceGovernancePanel({ user, currentReleaseId, onUnauthorized }
</section>;
}
export function CostConfigurationPanel({ user, onUnauthorized }: { user: AuthUser; onUnauthorized: (error: unknown) => boolean }) {
const { message } = App.useApp();
const [items, setItems] = useState<Row[]>([]);
const [loading, setLoading] = useState(true);
const [busy, setBusy] = useState(false);
const [error, setError] = useState('');
const [editing, setEditing] = useState<Row | null>(null);
const [validation, setValidation] = useState<Row | null>(null);
const [form] = Form.useForm<Row>();
const canManage = user.roles.some(role => ['SYSTEM_ADMIN', 'DATA_MAINTAINER', 'RULE_MAINTAINER'].includes(role));
const load = async () => {
setLoading(true);
try { setItems(collectionItems(await api.costConfigurations())); setError(''); }
catch (value) { if (!onUnauthorized(value)) setError(value instanceof Error ? value.message : '成本来源配置读取失败'); }
finally { setLoading(false); }
};
useEffect(() => { void load(); }, []);
const open = (item?: Row) => {
setEditing(item || {}); setValidation(null);
const definition = obj(item?.definition);
form.setFieldsValue({ name: text(item?.name, ''), reason: '', sources: rows(definition.sources) });
};
const save = async () => {
try {
const values = await form.validateFields(); setBusy(true);
const body = { name: String(values.name || '').trim(), reason: String(values.reason || '').trim(), definition: { sources: values.sources || [] }, ...(editing?.id ? { expectedRowVersion: Number(editing.rowVersion || 0) } : {}) };
if (editing?.id) await api.updateCostConfiguration(String(editing.id), body); else await api.createCostConfiguration(body);
message.success('成本来源与公式基线已保存;未执行成本金额计算'); setEditing(null); await load();
} catch (value) { if (value && typeof value === 'object' && 'errorFields' in value) return; if (!onUnauthorized(value)) message.error(value instanceof ApiError && value.status === 409 ? '配置已被其他操作更新,请刷新后重新编辑。' : value instanceof Error ? value.message : '成本配置保存失败'); }
finally { setBusy(false); }
};
const validate = async (item: Row) => {
setBusy(true);
try { const result = await api.validateCostConfiguration(String(item.id), { expectedRowVersion: Number(item.rowVersion || 0) }); setValidation(obj(result.validation)); await load(); }
catch (value) { if (!onUnauthorized(value)) message.error(value instanceof ApiError && value.status === 409 ? '配置已被其他操作更新,请刷新后重试。' : value instanceof Error ? value.message : '来源配置校验失败'); }
finally { setBusy(false); }
};
const columns: ColumnsType<Row> = [
{ title: '配置名称', dataIndex: 'name', key: 'name', fixed: 'left', width: 220 },
{ title: '状态', dataIndex: 'status', key: 'status', width: 150, render: value => <Tag>{text(value)}</Tag> },
{ title: '来源数', key: 'sources', align: 'right', width: 90, render: (_, row) => rows(obj(row.definition).sources).length },
{ title: '操作', key: 'actions', width: 180, render: (_, row) => <span className="completion-actions"><Button type="link" disabled={!canManage || row.status !== 'DRAFT'} onClick={() => open(row)}>编辑</Button><Button type="link" loading={busy} onClick={() => void validate(row)}>校验</Button></span> },
];
return <section className="panel section-panel completion-tools">
<div className="completion-panel-heading"><div><strong>成本来源与计算基线登记</strong><span>仅记录来源字段、单位、审批引用与原公式;成本金额和降本计算保持关闭</span></div><div className="completion-actions"><Button icon={<ReloadOutlined />} onClick={() => void load()}>刷新</Button>{canManage && <Button type="primary" onClick={() => open()}>新建成本来源配置</Button>}</div></div>
{error && <Alert showIcon type="error" message="成本来源配置不可用" description={error} />}
{loading ? <div className="completion-loading"><Spin />读取成本来源配置…</div> : items.length ? <Table size="small" bordered columns={columns} dataSource={items} rowKey={row => String(row.id)} pagination={false} scroll={{ x: 740 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="服务端当前没有成本来源登记" />}
{validation && <Alert showIcon type={validation.valid === true ? 'success' : 'warning'} message={text(validation.readiness, validation.valid === true ? '来源字段已验证' : '来源信息需补充')} description={`错误 ${rows(validation.errors).length} 项 · 成本金额计算:${validation.calculationEnabled === false ? '未启用' : '未由服务端确认'}`} />}
<Modal className="management-modal" open={Boolean(editing)} title={editing?.id ? '编辑成本来源配置' : '登记成本来源配置'} width={900} okText="保存配置" confirmLoading={busy} onCancel={() => setEditing(null)} onOk={() => void save()}>
<Alert showIcon type="info" message="成本核算未启用" description="此表单只登记依赖和原公式,不接受成本金额,不生成成本或降本结论。" />
<Form form={form} layout="vertical"><Form.Item name="name" label="配置名称" rules={[{ required: true, whitespace: true }]}><Input maxLength={180} /></Form.Item><Form.List name="sources">{(fields, { add, remove }) => <div className="target-rule-list"><div className="resource-toolbar"><strong>成本来源字段映射</strong><Button onClick={() => add({ unit: 'CNY/kg' })}>添加来源</Button></div>{fields.map(field => <div className="target-rule-row" key={field.key}><Form.Item {...field} name={[field.name, 'sourceReference']} label="来源引用" rules={[{ required: true, whitespace: true }]}><Input /></Form.Item><Form.Item {...field} name={[field.name, 'objectCode']} label="对象编码" rules={[{ required: true, whitespace: true }]}><Input /></Form.Item><Form.Item {...field} name={[field.name, 'costField']} label="成本字段" rules={[{ required: true, whitespace: true }]}><Input /></Form.Item><Form.Item {...field} name={[field.name, 'unit']} label="单位" rules={[{ required: true, whitespace: true }]}><Input /></Form.Item><Form.Item {...field} name={[field.name, 'currency']} label="币种"><Input placeholder="CNY" /></Form.Item><Form.Item {...field} name={[field.name, 'approvalReference']} label="审批引用"><Input /></Form.Item><Form.Item {...field} name={[field.name, 'originalFormula']} label="原公式"><Input /></Form.Item><Form.Item {...field} name={[field.name, 'fromMonth']} label="起始月 YYYY-MM"><Input /></Form.Item><Form.Item {...field} name={[field.name, 'toMonth']} label="结束月 YYYY-MM"><Input /></Form.Item><Button danger onClick={() => remove(field.name)}>移除</Button></div>)}</div>}</Form.List><Form.Item name="reason" label="登记原因" rules={[{ required: true, whitespace: true }]}><Input.TextArea rows={2} maxLength={300} /></Form.Item></Form>
</Modal>
</section>;
}
export function BackupOperationsPanel({ user, onUnauthorized, onNavigate }: { user: AuthUser; onUnauthorized: (error: unknown) => boolean; onNavigate?: () => void }) {
const { message } = App.useApp();
const [data, setData] = useState<Row | null>(null);
@@ -514,7 +460,7 @@ export function BackupOperationsPanel({ user, onUnauthorized, onNavigate }: { us
return <section className="panel section-panel completion-tools">
<div className="completion-panel-heading"><div><strong>备份、恢复验证与计划</strong><span>恢复验证仅在隔离目录执行;当前不开放在线业务库覆盖恢复</span></div><div className="completion-actions"><Button icon={<ReloadOutlined />} onClick={() => void load()}>刷新</Button>{canManage && <><Button onClick={() => { form.setFieldsValue({ ...plan, reason: '' }); setPlanOpen(true); }}>备份计划</Button><Button type="primary" loading={busy} onClick={() => void runJob('BACKUP_CREATE_VERIFY')}>创建并验证备份</Button></>}</div></div>
{error && <Alert showIcon type="error" message="备份状态不可用" description={error} />}
{loading ? <div className="completion-loading"><Spin />读取备份与恢复状态…</div> : <><div className="governance-monitor-grid"><div><small>计划</small><strong>{plan.active === true ? '已启用' : plan.active === false ? '已停用' : '未配置'}</strong></div><div><small>周期 / RPO</small><strong>{text(plan.intervalHours)} 小时 / {text(plan.rpoHours)} 小时</strong></div><div><small>RTO</small><strong>{text(plan.rtoHours)} 小时</strong></div><div><small>在线恢复</small><strong>{obj(data).liveRestoreEnabled === true ? '开放' : '关闭'}</strong></div></div>{backups.length ? <Table size="small" bordered columns={columns} dataSource={backups} rowKey={row => String(row.id)} pagination={{ pageSize: 10, showSizeChanger: false }} scroll={{ x: 920 }} /> : <Empty description="服务端当前没有备份记录" />}</>}
{loading ? <div className="completion-loading"><Spin />读取备份与恢复状态…</div> : <><div className="governance-monitor-grid"><div><small>计划</small><strong>{plan.active === true ? '已启用' : plan.active === false ? '已停用' : '未配置'}</strong></div><div><small>周期 / RPO</small><strong>{text(plan.intervalHours)} 小时 / {text(plan.rpoHours)} 小时</strong></div><div><small>RTO</small><strong>{text(plan.rtoHours)} 小时</strong></div><div><small>在线恢复</small><strong>{obj(data).liveRestoreEnabled === true ? '开放' : '关闭'}</strong></div></div>{backups.length ? <Table size="small" bordered columns={columns} dataSource={backups} rowKey={row => String(row.id)} pagination={{ pageSize: 15, showSizeChanger: false }} scroll={{ x: 920 }} /> : <Empty description="服务端当前没有备份记录" />}</>}
{onNavigate && <Button type="link" onClick={onNavigate}>查看备份任务进度</Button>}
<Modal className="management-modal" open={planOpen} title="备份计划配置" okText="保存计划" confirmLoading={busy} onCancel={() => setPlanOpen(false)} onOk={() => void savePlan()}><Form form={form} layout="vertical"><Form.Item name="active" label="计划状态" valuePropName="checked"><Switch checkedChildren="启用" unCheckedChildren="停用" /></Form.Item><div className="governance-form-grid"><Form.Item name="intervalHours" label="备份周期(小时)" rules={[{ required: true }]}><InputNumber min={1} max={8760} /></Form.Item><Form.Item name="rpoHours" label="RPO(小时)" rules={[{ required: true }]}><InputNumber min={1} max={8760} /></Form.Item><Form.Item name="rtoHours" label="RTO(小时)" rules={[{ required: true }]}><InputNumber min={1} max={8760} /></Form.Item></div><Form.Item name="reason" label="修改原因" rules={[{ required: true, whitespace: true }]}><Input.TextArea rows={2} /></Form.Item></Form></Modal>
</section>;
@@ -590,16 +536,18 @@ export function OperationsMonitorPanel({ user, onUnauthorized }: { user: AuthUse
{ title: '最近请求', dataIndex: 'lastSeen', key: 'lastSeen', width: 190, render: value => configurationDateTime(value) || '—' },
];
return <>
<section className="panel section-panel governance-monitor">
<ManagementSections items={[
{ key: 'health', label: '运行状态与告警', children: <><section className="panel section-panel governance-monitor">
<div className="completion-panel-heading"><div><strong>运行监控与告警</strong><span>只读取并更新服务端运行状态;不发送外部通知</span></div><div className="completion-actions"><Button icon={<ReloadOutlined />} loading={loading} onClick={() => void load()}>刷新</Button>{canRefresh && <><Button onClick={() => void editPolicy()} disabled={!alertPolicy}>告警阈值</Button><Button type="primary" loading={refreshing} onClick={() => void refresh()}>系统健康检查</Button></>}</div></div>
{error && <Alert showIcon type="error" message="运行监控暂不可用" description={error} />}
{policyError && <Alert showIcon type="error" message="告警策略不可用" description={policyError} />}
{loading ? <div className="completion-loading"><Spin />读取平台状态…</div> : <><div className="governance-monitor-grid">{summaryEntries.length ? summaryEntries.map(([key, value]) => <div key={key}><small>{summaryLabels[key] || '其他指标'}</small><strong>{text(value)}</strong></div>) : <div className="completion-placeholder">服务端没有返回运行指标</div>}</div><Tabs activeKey={alertStatus} onChange={setAlertStatus} items={[{key:'OPEN',label:`当前告警(${alertsForStatus(allAlerts,'OPEN').length})`},{key:'RECOVERED',label:`已恢复(${alertsForStatus(allAlerts,'RECOVERED').length})`}]}/>{alertRows.length ? <Table size="small" bordered columns={alertColumns} dataSource={alertRows} rowKey={row => String(row.id || row.code)} pagination={{ pageSize: 10, showSizeChanger: false }} scroll={{ x: 1260 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={alertStatus === 'OPEN' ? '当前没有未恢复告警' : '暂无已恢复告警'} />}</>}
<h3>接口请求指标</h3><p className="completion-note">累计请求数、失败数与耗时;最近请求时间不代表统计起点。</p>
{loading ? <div className="completion-loading"><Spin />读取接口指标…</div> : requestMetricRows.length ? <Table size="small" bordered columns={requestMetricColumns} dataSource={requestMetricRows} rowKey={row => `${text(row.routePattern)}-${text(row.method)}`} pagination={{ pageSize: 12, showSizeChanger: false }} scroll={{ x: 1200 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="服务端尚未记录接口请求指标" />}
{loading ? <div className="completion-loading"><Spin />读取平台状态…</div> : <><div className="governance-monitor-grid">{summaryEntries.length ? summaryEntries.map(([key, value]) => <div key={key}><small>{summaryLabels[key] || '其他指标'}</small><strong>{text(value)}</strong></div>) : <div className="completion-placeholder">服务端没有返回运行指标</div>}</div><Tabs activeKey={alertStatus} onChange={setAlertStatus} items={[{key:'OPEN',label:`当前告警(${alertsForStatus(allAlerts,'OPEN').length})`},{key:'RECOVERED',label:`已恢复(${alertsForStatus(allAlerts,'RECOVERED').length})`}]}/>{alertRows.length ? <Table size="small" bordered columns={alertColumns} dataSource={alertRows} rowKey={row => String(row.id || row.code)} pagination={{ pageSize: 15, showSizeChanger: false }} scroll={{ x: 1260 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={alertStatus === 'OPEN' ? '当前没有未恢复告警' : '暂无已恢复告警'} />}</>}</section></> },
{ key: 'requests', label: '接口请求指标', children: <section className="panel section-panel"><div className="completion-actions"><Button icon={<ReloadOutlined />} onClick={() => void load()}>刷新</Button></div> <h3>接口请求指标</h3><p className="completion-note">累计请求数、失败数与耗时;最近请求时间不代表统计起点。</p>
{loading ? <div className="completion-loading"><Spin />读取接口指标…</div> : requestMetricRows.length ? <Table size="small" bordered columns={requestMetricColumns} dataSource={requestMetricRows} rowKey={row => `${text(row.routePattern)}-${text(row.method)}`} pagination={{ pageSize: 15, showSizeChanger: false }} scroll={{ x: 1200 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="服务端尚未记录接口请求指标" />}
</section> },
{ key: 'inspection', label: '巡检策略', children: <InspectionStrategyPanel user={user} onUnauthorized={onUnauthorized} /> },
]} />
<Modal className="management-modal" open={policyOpen} title="告警阈值与静默策略" okText="保存策略" confirmLoading={policyBusy} onCancel={() => setPolicyOpen(false)} onOk={() => void savePolicy()}><Form form={policyForm} layout="vertical"><div className="governance-form-grid"><Form.Item name="queueAgeMinutes" label="队列告警(分钟)" rules={[{ required: true }]}><InputNumber min={1} max={1440} /></Form.Item><Form.Item name="diskFreeBytes" label="最低可用磁盘空间(字节)" rules={[{ required: true }]}><InputNumber min={104857600} max={1125899906842624} style={{ width: '100%' }} /></Form.Item><Form.Item name="backupAgeHours" label="备份超时(小时)" rules={[{ required: true }]}><InputNumber min={1} max={720} /></Form.Item><Form.Item name="quietPeriodMinutes" label="重复告警静默(分钟)" rules={[{ required: true }]}><InputNumber min={0} max={10080} /></Form.Item><Form.Item name="slowRequestMillis" label="慢请求阈值(毫秒)" rules={[{ required: true }]}><InputNumber min={100} max={120000} /></Form.Item><Form.Item name="silenceUntil" label="临时静默截止(ISO,可选)"><Input placeholder="2026-10-21T09:00:00Z" /></Form.Item></div><Form.Item name="severityOverrides" label="告警严重度覆盖(JSON)" rules={[{ required: true }]}><Input.TextArea rows={5} spellCheck={false} /></Form.Item><Form.Item name="reason" label="修改原因" rules={[{ required: true, whitespace: true }]}><Input.TextArea rows={2} /></Form.Item><p className="completion-note">保存后按新策略检查;严重度 key 只能使用服务端列出的告警类型。</p></Form></Modal>
</section>
<InspectionStrategyPanel user={user} onUnauthorized={onUnauthorized} />
</>;
}
@@ -676,19 +624,23 @@ export function ServiceIdentityPanel({ user, onUnauthorized }: { user: AuthUser;
{ title: '操作', key: 'action', fixed: 'right', width: 230, render: (_, row) => <span className="completion-actions">{canManage && <><Button type="link" onClick={() => open(row)}>编辑</Button><Button type="link" onClick={() => { setRotating(row); rotateForm.setFieldsValue({ credentialReference: text(row.credentialReference, ''), credentialStatus: text(row.credentialStatus, 'UNCONFIGURED'), reason: '' }); }}>轮换</Button></>}<Button type="link" onClick={async () => { try { setRotations(collectionItems(await api.serviceRotations(String(row.id)))); setRotating({ ...row, showRotations: true }); } catch (value) { if (!onUnauthorized(value)) message.error(value instanceof Error ? value.message : '轮换记录读取失败'); } }}>历史</Button></span> },
];
return <div className="governance-service-identities">
<section className="panel section-panel">
<ManagementSections items={[
{ key: 'identities', label: '服务身份', children: <> <section className="panel section-panel">
<div className="completion-panel-heading"><div><strong>服务身份与最小动作授权</strong><span>仅保存 env: 或 file: 凭据引用,不在浏览器或服务端表单中接收密钥文本</span></div><div className="completion-actions"><Button icon={<ReloadOutlined />} onClick={() => void load()}>刷新</Button>{canManage && <Button type="primary" onClick={() => open()}>新建服务身份</Button>}</div></div>
{error && <Alert showIcon type="error" message="服务身份管理不可用" description={error} />}
{loading ? <div className="completion-loading"><Spin />读取服务身份…</div> : items.length ? <Table size="small" bordered columns={columns} dataSource={items} rowKey={row => String(row.id)} pagination={false} scroll={{ x: 1200 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="尚未创建服务身份" />}
{loading ? <div className="completion-loading"><Spin />读取服务身份…</div> : items.length ? <Table size="small" bordered columns={columns} dataSource={items} rowKey={row => String(row.id)} pagination={{ pageSize: 15, showSizeChanger: false }} scroll={{ x: 1200 }} /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="尚未创建服务身份" />}
</section>
<section className="panel section-panel"><div className="completion-panel-heading"><div><strong>服务接入绑定</strong><span>只允许类型匹配且授权状态可用的身份</span></div></div>{serviceTypes.length ? <div className="governance-binding-list">{serviceTypes.map(type => <div key={type}><strong>{type}</strong><span>{text(bindings.find(item => item.serviceType === type)?.serviceIdentityId, '未绑定')}</span>{canManage && <Select aria-label={`${type}服务身份`} placeholder="选择身份" value={String(bindings.find(item => item.serviceType === type)?.serviceIdentityId || '') || undefined} loading={busy} options={items.filter(item => item.serviceType === type).map(item => ({ label: `${text(item.name)} · ${text(item.credentialStatus)}`, value: String(item.id) }))} onChange={value => void bind(type, value)} />}</div>)}</div> : <Empty description="服务类型尚未由服务端返回" />}</section>
</> },
{ key: 'bindings', label: '接入绑定', children: <> <section className="panel section-panel"><div className="completion-panel-heading"><div><strong>服务接入绑定</strong><span>只允许类型匹配且授权状态可用的身份</span></div></div>{serviceTypes.length ? <div className="governance-binding-list">{serviceTypes.map(type => <div key={type}><strong>{type}</strong><span>{text(bindings.find(item => item.serviceType === type)?.serviceIdentityId, '未绑定')}</span>{canManage && <Select aria-label={`${type}服务身份`} placeholder="选择身份" value={String(bindings.find(item => item.serviceType === type)?.serviceIdentityId || '') || undefined} loading={busy} options={items.filter(item => item.serviceType === type).map(item => ({ label: `${text(item.name)} · ${text(item.credentialStatus)}`, value: String(item.id) }))} onChange={value => void bind(type, value)} />}</div>)}</div> : <Empty description="服务类型尚未由服务端返回" />}</section>
</> },
]} />
<Modal className="management-modal" open={Boolean(editing) && !editing?.showRotations} title={editing?.id ? '编辑服务身份' : '新建服务身份'} okText="保存配置" confirmLoading={busy} onCancel={() => setEditing(null)} onOk={() => void save()}>
<Alert showIcon type="warning" message="服务身份默认停用" description="启用需要 READY 凭据引用和服务端允许的最小动作。输入凭据引用,不要粘贴密钥内容。" />
<Form form={form} layout="vertical"><Form.Item name="name" label="身份名称" rules={[{ required: true, whitespace: true }]}><Input maxLength={190} /></Form.Item><Form.Item name="serviceType" label="服务类型" rules={[{ required: true }]}><Select disabled={Boolean(editing?.id)} options={serviceTypes.map(value => ({ label: value, value }))} /></Form.Item><Form.Item name="allowedActions" label="允许动作" rules={[{ required: true, type: 'array', min: 1 }]}><Select mode="multiple" options={(ACTIONS_BY_TYPE[String(serviceType || '')] || allowedActions).filter((value: string) => allowedActions.includes(value)).map((value: string) => ({ label: value, value }))} /></Form.Item><Form.Item name="credentialReference" label="凭据引用" rules={[{ pattern: /^(?:env:[A-Z][A-Z0-9_]{0,100}|file:[A-Za-z0-9_./-]{1,240})$/, message: '使用 env:NAME 或 file:relative/path 引用,不填密钥内容' }]}><Input placeholder="env:QUALITY_MODEL_KEY" autoComplete="off" /></Form.Item><Form.Item name="credentialStatus" label="凭据状态" rules={[{ required: true }]}><Select options={['UNCONFIGURED', 'READY', 'EXPIRED', 'REVOKED'].map(value => ({ label: value, value }))} /></Form.Item>{Boolean(editing?.id) && <Form.Item name="active" label="身份状态" valuePropName="checked"><Switch checkedChildren="启用" unCheckedChildren="停用" /></Form.Item>}<Form.Item name="reason" label="操作原因" rules={[{ required: true, whitespace: true }]}><Input.TextArea rows={2} maxLength={300} /></Form.Item></Form>
</Modal>
<Modal className="management-modal" open={Boolean(rotating?.id) && !rotating?.showRotations} title="轮换凭据引用" okText="提交轮换" confirmLoading={busy} onCancel={() => setRotating(null)} onOk={() => void rotate()}><Form form={rotateForm} layout="vertical"><Form.Item name="credentialReference" label="凭据引用" rules={[{ required: true, pattern: /^(?:env:[A-Z][A-Z0-9_]{0,100}|file:[A-Za-z0-9_./-]{1,240})$/, message: '使用 env:NAME 或 file:relative/path 引用' }]}><Input autoComplete="off" /></Form.Item><Form.Item name="credentialStatus" label="状态"><Select options={['READY', 'EXPIRED', 'REVOKED', 'UNCONFIGURED'].map(value => ({ label: value, value }))} /></Form.Item><Form.Item name="reason" label="轮换理由" rules={[{ required: true, whitespace: true }]}><Input.TextArea rows={2} /></Form.Item></Form></Modal>
<Modal className="management-modal" open={Boolean(bindingEdit)} title="变更服务身份绑定" okText="保存绑定" confirmLoading={busy} onCancel={() => setBindingEdit(null)} onOk={() => void submitBinding()}><p>服务类型:{text(bindingEdit?.type)} · 身份 ID:{text(bindingEdit?.identityId)}</p><Form form={bindingForm} layout="vertical"><Form.Item name="reason" label="绑定原因" rules={[{ required: true, whitespace: true }]}><Input.TextArea rows={2} maxLength={300} /></Form.Item></Form></Modal>
<Drawer className="management-drawer" open={rotating?.showRotations === true} title="凭据引用变更历史" width={Math.min(680, window.innerWidth)} onClose={() => setRotating(null)}>{rotations.length ? <Table size="small" bordered dataSource={rotations} rowKey={row => String(row.id)} pagination={{ pageSize: 8, showSizeChanger: false }} columns={[{ title: '引用', dataIndex: 'credentialReference', key: 'credentialReference' }, { title: '状态', dataIndex: 'credentialStatus', key: 'credentialStatus' }, { title: '原因', dataIndex: 'reason', key: 'reason' }, { title: '时间', dataIndex: 'createdAt', key: 'createdAt' }]} /> : <Empty description="没有已返回的轮换记录" />}</Drawer>
<Drawer className="management-drawer" open={rotating?.showRotations === true} title="凭据引用变更历史" width={Math.min(680, window.innerWidth)} onClose={() => setRotating(null)}>{rotations.length ? <Table size="small" bordered dataSource={rotations} rowKey={row => String(row.id)} pagination={{ pageSize: 15, showSizeChanger: false }} columns={[{ title: '引用', dataIndex: 'credentialReference', key: 'credentialReference' }, { title: '状态', dataIndex: 'credentialStatus', key: 'credentialStatus' }, { title: '原因', dataIndex: 'reason', key: 'reason' }, { title: '时间', dataIndex: 'createdAt', key: 'createdAt' }]} /> : <Empty description="没有已返回的轮换记录" />}</Drawer>
</div>;
}