优化:整理指标目标并支持中文字段公式编辑
黑片和亮片按结果展示完整公式,在同一窗口维护条件与未匹配取值。支持中文字段选择、运算符和求和,并保留原计算语义及特殊策略。 移除重复账号入口与配置说明,统一紧凑表格。保留仓库既有权限判断,不包含此前未同步的角色迁移、预览快照或运行数据。 验证:前端构建及68项相关检查通过。
This commit is contained in:
+40
-23
@@ -45,7 +45,10 @@ import type { DataWorkflowStatus } from './NoCodeDataTypes';
|
||||
import type { PageKey } from './QualityWorkspace';
|
||||
import { readableSelectPopup } from './readableSelectPopup';
|
||||
import './management-alignment.css';
|
||||
import { TargetVersionAdmin } from './AnalyticsCompletion';
|
||||
import { QualityTargetsPanel } from './QualityTargetsPanel';
|
||||
import { METRIC_KEYS, formulaOnly, ruleChangeSummary } from './rulePresentation';
|
||||
import { ruleLogicIssues } from './ruleEditing';
|
||||
import './rules-workspace.css';
|
||||
import { AnalysisReportExport, NativeAnalysisReport } from './AnalysisReportExport';
|
||||
import { AiMarkdown } from './AiMarkdown';
|
||||
import { authorizeAnalysisSnapshot } from './analysisSnapshot';
|
||||
@@ -229,13 +232,23 @@ export default function ManagementPages(props: ManagementPageProps) {
|
||||
<ManagementPageContents {...props}/>
|
||||
</CompactManagementTables.Provider>;
|
||||
}
|
||||
function RulesWorkspace({ user, onUnauthorized, onNavigate }: Omit<ManagementPageProps, 'page'>) {
|
||||
const [section, setSection] = useState('dictionary');
|
||||
const [focusMetric, setFocusMetric] = useState<{ code: string; request: number }>();
|
||||
const editFormula = (code: string) => { setFocusMetric({ code: METRIC_KEYS[code] || code, request: Date.now() }); setSection('settings'); };
|
||||
return <ManagementSections selectedKey={section} onSelect={setSection} items={[
|
||||
{ key: 'dictionary', label: '指标说明', children: <MetricDictionaryPanel user={user} onUnauthorized={onUnauthorized} onEditFormula={editFormula} /> },
|
||||
...(user.roles.some(role => ['SYSTEM_ADMIN', 'RULE_MAINTAINER'].includes(role)) ? [{ key: 'targets', label: '质量目标', children: <QualityTargetsPanel onUnauthorized={onUnauthorized} /> }] : []),
|
||||
{ key: 'settings', label: '计算设置', children: <ConfigManagementPage kind="rules" user={user} onUnauthorized={onUnauthorized} onNavigate={onNavigate} focusMetric={focusMetric} /> },
|
||||
]} />;
|
||||
}
|
||||
function ManagementPageContents({ page, user, onUnauthorized, onNavigate }: ManagementPageProps) {
|
||||
if (page === 'sources' || page === 'imports') return <SourcesPage onUnauthorized={onUnauthorized} user={user} />;
|
||||
if (page === 'tasks') return <TasksMonitorPage user={user} onUnauthorized={onUnauthorized} />;
|
||||
if (page === 'analysis') return <AnalysisPage onUnauthorized={onUnauthorized} user={user} />;
|
||||
if (page === 'access') return <AccessPage user={user} onUnauthorized={onUnauthorized} />;
|
||||
if (page === 'basis') return <BasisPage onUnauthorized={onUnauthorized} />;
|
||||
if (page === 'rules') return <ManagementSections items={[{ key: 'rules', label: '计算规则', children: <ConfigManagementPage kind={page} user={user} onUnauthorized={onUnauthorized} onNavigate={onNavigate} /> },{ key: 'dictionary', label: '指标定义', children: <MetricDictionaryPanel user={user} onUnauthorized={onUnauthorized} /> },...(user.roles.some(role => ['SYSTEM_ADMIN', 'RULE_MAINTAINER'].includes(role)) ? [{ key: 'targets', label: '目标管理', children: <TargetVersionAdmin onUnauthorized={onUnauthorized} /> }] : [])]} />;
|
||||
if (page === 'rules') return <RulesWorkspace user={user} onUnauthorized={onUnauthorized} onNavigate={onNavigate} />;
|
||||
if (page === 'masterData') return <ManagementSections items={[{ key: 'catalog', label: '基础名录', children: <ConfigManagementPage kind={page} user={user} onUnauthorized={onUnauthorized} onNavigate={onNavigate} /> },{ key: 'filters', label: '查询字段', children: <FilterFieldSettings canManage={user.roles.some(role => ['SYSTEM_ADMIN','DATA_MAINTAINER'].includes(role))} onUnauthorized={onUnauthorized} /> }]} />;
|
||||
if (page === 'mappings') return <MappingMaintenancePage user={user} onUnauthorized={onUnauthorized} onNavigate={onNavigate} />;
|
||||
const resource: Record<string, { endpoint: 'imports' | 'tasks'; title: string; subtitle: string }> = {
|
||||
@@ -401,7 +414,7 @@ function ruleDisplayName(value: unknown): string {
|
||||
|
||||
type PublishedConfigNames = Pick<OptionsResponse, 'departments' | 'groups' | 'products' | 'projectGroups'> & { groupDepartments?: Record<string, string | null> };
|
||||
|
||||
function ConfigManagementPage({ kind, user, onUnauthorized, onNavigate, extraSections }: { extraSections?: { key: string; label: string; children: React.ReactNode }[]; kind: 'rules' | 'mappings' | 'masterData'; user: AuthUser; onUnauthorized: (error: unknown) => boolean; onNavigate: (page: PageKey) => void }) {
|
||||
function ConfigManagementPage({ kind, user, onUnauthorized, onNavigate, extraSections, focusMetric }: { focusMetric?: { code: string; request: number }; extraSections?: { key: string; label: string; children: React.ReactNode }[]; kind: 'rules' | 'mappings' | 'masterData'; user: AuthUser; onUnauthorized: (error: unknown) => boolean; onNavigate: (page: PageKey) => void }) {
|
||||
const { message } = App.useApp();
|
||||
const { active: pageActive } = usePageCache();
|
||||
const [items, setItems] = useState<Record<string, unknown>[]>([]);
|
||||
@@ -427,6 +440,7 @@ function ConfigManagementPage({ kind, user, onUnauthorized, onNavigate, extraSec
|
||||
const classificationUpdates=useClassificationQueue(kind==='mappings'?String(user.id):'inactive-'+kind);
|
||||
const [ruleSchema, setRuleSchema] = useState<Record<string, unknown> | null>(null);
|
||||
const [ruleSchemaError, setRuleSchemaError] = useState('');
|
||||
const [ruleBaseline, setRuleBaseline] = useState<ConfigDefinition>({});
|
||||
const [publishedNames, setPublishedNames] = useState<PublishedConfigNames | null>(null);
|
||||
const [matchMetadata,setMatchMetadata]=useState<Record<string,unknown>|null>(null);
|
||||
const [differenceItem, setDifferenceItem] = useState<Record<string, unknown> | null>(null);
|
||||
@@ -488,6 +502,7 @@ function ConfigManagementPage({ kind, user, onUnauthorized, onNavigate, extraSec
|
||||
const definitionKey=JSON.stringify([kind,active?.id??fallback?.id,definition]);
|
||||
if (definition && typeof definition === 'object' && loadedDefinitionKey.current!==definitionKey) {loadedDefinitionKey.current=definitionKey;const serialized=JSON.stringify(definition),prior=loadedDefinition.current;setDraftDefinition(previous=>!prior||JSON.stringify(previous)===prior?JSON.parse(serialized) as ConfigDefinition:previous);loadedDefinition.current=serialized;}
|
||||
const metadata = items.find(row => String(row.id) === String(active?.id)) ?? fallback;
|
||||
if (!drafting && isRules) setRuleBaseline(JSON.parse(JSON.stringify(definition || {})) as ConfigDefinition);
|
||||
if (!drafting) form.setFieldsValue({ name: testMode ? currentConfigurationName(active?.name ?? metadata?.name, metadata?.createdAt) : isRules ? ruleDisplayName(active?.name || fallback?.name || '测试计算规则') : String(active?.name || fallback?.name || '测试基础数据与对应关系'), description: isRules ? readableRuleDescription(active?.description || fallback?.description) : String(active?.description || fallback?.description || '') });
|
||||
}, [workflowStatus, items, kind, isRules, testMode, ruleSchema, drafting, form]);
|
||||
|
||||
@@ -613,6 +628,10 @@ function ConfigManagementPage({ kind, user, onUnauthorized, onNavigate, extraSec
|
||||
if (actionLock.current) return; actionLock.current = true;
|
||||
try {
|
||||
await form.validateFields();
|
||||
if (isRules && ruleSchema) {
|
||||
const issues = ruleLogicIssues(draftDefinition, ruleSchema);
|
||||
if (issues.length) throw new Error(issues[0].message);
|
||||
}
|
||||
const values = form.getFieldsValue(true);
|
||||
await workflowOperation.start(() => api.applyDataWorkflow({ kind: isRules ? 'rule' : 'mapping', name: configurationDateTime(new Date()), definition: draftDefinition, expectedCurrentReleaseId: workflowStatus?.currentReleaseId ?? null, ...(values.description?.trim() ? { description: values.description.trim() } : {}) }));
|
||||
} catch (value) {
|
||||
@@ -643,13 +662,14 @@ function ConfigManagementPage({ kind, user, onUnauthorized, onNavigate, extraSec
|
||||
<div className="completion-actions"><ConfigurationWorkbookActions value={draftDefinition} onChange={setDraftDefinition} scope={mode==='rules'?'rules':mode==='catalog'?'catalogs':'all'} label={mode==='rules'?'计算规则':mode==='catalog'?'基础名录':'对应关系配置'} defaults={Array.isArray(matchMetadata?.defaultRules)?matchMetadata.defaultRules:[]} readOnly={!canApplyWorkflow} disabled={loading||(isRules?!ruleSchema:!matchMetadata)} validate={isRules?undefined:validateStructuredMappingDefinition} whole /></div>
|
||||
<Button icon={<ReloadOutlined />} onClick={() => { void load(); void refreshWorkflowStatus(); void loadEditorSupport(); }}>刷新</Button>
|
||||
</div>
|
||||
{mode === 'rules' && <Form form={form} layout="vertical"><div className="structured-config-form-grid"><Form.Item name="name" label="配置名称"><Input readOnly /></Form.Item><Form.Item name="description" label="说明(可选)"><Input disabled={!canApplyWorkflow} maxLength={1000} /></Form.Item></div></Form>}
|
||||
{mode === 'rules' ? canApplyWorkflow ? <RuleDefinitionEditor value={draftDefinition} onChange={setDraftDefinition} schema={ruleSchema} schemaError={ruleSchemaError} showWorkbookActions={false} /> : <RuleContents value={draftDefinition} />
|
||||
{mode === 'rules' && <Form form={form} component={false}><Form.Item name="name" hidden><Input readOnly /></Form.Item><Form.Item name="description" hidden><Input readOnly /></Form.Item></Form>}
|
||||
{mode === 'rules' ? <RuleDefinitionEditor value={draftDefinition} onChange={setDraftDefinition} schema={ruleSchema} schemaError={ruleSchemaError} showWorkbookActions={false} focusMetric={focusMetric} readOnly={!canApplyWorkflow} />
|
||||
: mode === 'catalog' ? <MasterDataDefinitionEditor value={draftDefinition} onChange={setDraftDefinition} publishedNames={publishedNames ?? undefined} simplified readOnly={!canApplyWorkflow} />
|
||||
: mode === 'lookups' ? <MappingDefinitionEditor value={draftDefinition} onChange={setDraftDefinition} simplified readOnly={!canApplyWorkflow} />
|
||||
: <MatchRulesDefinitionEditor value={draftDefinition} onChange={setDraftDefinition} metadata={matchMetadata??workflowStatus} readOnly={!canApplyWorkflow} />}
|
||||
{!isRules && validateStructuredMappingDefinition(draftDefinition, publishedNames?.groupDepartments).length > 0 && <Alert showIcon type="warning" message="有名录引用需要留意" description={<ul className="structured-config-error-list">{validateStructuredMappingDefinition(draftDefinition, publishedNames?.groupDepartments).slice(0,12).map((issue,index)=><li key={index}>{issue}</li>)}</ul>} />}
|
||||
{canApplyWorkflow && <div className="nc-simple-save-row"><span>保存后检查配置并更新报表。</span><Button type="primary" size="large" disabled={workflowOperation.busy || classificationBusy || (isRules && !ruleSchema)} loading={workflowOperation.busy} onClick={() => void applyCurrent()}>保存并更新报表</Button></div>}
|
||||
{isRules && ruleChangeSummary(ruleBaseline, draftDefinition).length > 0 && <div className="rule-pending-changes"><strong>本次变更</strong><span>{ruleChangeSummary(ruleBaseline, draftDefinition).join(';')}</span></div>}
|
||||
{canApplyWorkflow && <div className="nc-simple-save-row"><span>{isRules ? '检查规则 → 重新计算 → 更新报表' : '保存后检查配置并更新报表。'}</span><Button type="primary" size="large" disabled={workflowOperation.busy || classificationBusy || (isRules && !ruleSchema)} loading={workflowOperation.busy} onClick={() => void applyCurrent()}>保存并更新报表</Button></div>}
|
||||
</section>
|
||||
</div>;
|
||||
if (kind === 'masterData') return <><Form form={form} component={false} />{editor('catalog')}</>;
|
||||
@@ -811,7 +831,7 @@ function MappingIssueResolutionPanel({ onUnauthorized, onEdit }: { onUnauthorize
|
||||
</div>;
|
||||
}
|
||||
|
||||
function MetricDictionaryPanel({ user, onUnauthorized }: { user: AuthUser; onUnauthorized: (error: unknown) => boolean }) {
|
||||
function MetricDictionaryPanel({ user, onUnauthorized, onEditFormula }: { user: AuthUser; onUnauthorized: (error: unknown) => boolean; onEditFormula?: (code: string) => void }) {
|
||||
const { message } = App.useApp();
|
||||
const { active } = usePageCache();
|
||||
const [items, setItems] = useState<Record<string, unknown>[]>([]);
|
||||
@@ -853,7 +873,7 @@ function MetricDictionaryPanel({ user, onUnauthorized }: { user: AuthUser; onUna
|
||||
reason: values.reason.trim(),
|
||||
expectedRowVersion: Number(editing.rowVersion || 0),
|
||||
});
|
||||
message.success('术语名称、别名和说明已保存'); setEditing(null); form.resetFields(); await load();
|
||||
message.success('指标说明已保存'); setEditing(null); form.resetFields(); await load();
|
||||
} catch (value) {
|
||||
if (value && typeof value === 'object' && 'errorFields' in value) return;
|
||||
if (!onUnauthorized(value)) message.error(apiMessage(value));
|
||||
@@ -862,33 +882,30 @@ function MetricDictionaryPanel({ user, onUnauthorized }: { user: AuthUser; onUna
|
||||
};
|
||||
|
||||
const columns: ColumnsType<Record<string, unknown>> = [
|
||||
{ title: '术语名称', dataIndex: 'name', key: 'name', width: 160 },
|
||||
{ title: '说明', dataIndex: 'description', key: 'description', width: 200, render: value => readableValue(readableRuleDescription(value)) },
|
||||
{ title: '单位', dataIndex: 'unit', key: 'unit', width: 55, render: value => value === 'RATE' ? '%' : toText(value) },
|
||||
{ title: '适用范围', dataIndex: 'dimensions', key: 'dimensions', width: 130, render: value => <BusinessValue value={value} field="dimensions" /> },
|
||||
{ title: '当前生效公式', key: 'formula', width: 420, render: (_, row) => <div style={{ whiteSpace: 'normal', overflowWrap: 'anywhere', lineHeight: 1.7 }}>{currentMetricFormula(row)}</div> },
|
||||
{ title: '状态', dataIndex: 'enabled', key: 'enabled', width: 70, render: value => <Tag color={value === true ? 'green' : 'default'}>{value === true ? '启用' : value === false ? '停用' : '—'}</Tag> },
|
||||
{ title: '操作', key: 'actions', fixed: 'right', width: 100, render: (_, row) => <span className="task-actions"><Button type="link" onClick={() => setInspecting(row)}>查看</Button>{canManage && <Button type="link" onClick={() => openEditor(row)}>编辑术语</Button>}</span> },
|
||||
{ title: '指标', dataIndex: 'name', key: 'name', width: 190 },
|
||||
{ title: '当前计算公式', key: 'formula', width: 330, render: (_, row) => <div style={{ whiteSpace: 'normal', overflowWrap: 'anywhere', lineHeight: 1.7 }}>{formulaOnly(currentMetricFormula(row))}</div> },
|
||||
{ title: '计算口径', dataIndex: 'description', key: 'description', width: 280, render: value => readableValue(readableRuleDescription(value)) },
|
||||
{ title: '操作', key: 'actions', width: 220, render: (_, row) => <span className="task-actions"><Button type="link" onClick={() => setInspecting(row)}>查看说明</Button>{canManage && <><Button type="link" onClick={() => openEditor(row)}>编辑说明</Button>{onEditFormula && <Button type="link" onClick={() => onEditFormula(String(row.code))}>修改公式</Button>}</>}</span> },
|
||||
];
|
||||
useMaintenanceRefresh(load);
|
||||
return <section className="panel section-panel completion-tools">
|
||||
<div className="completion-panel-heading"><div><strong>指标术语字典</strong><span>维护展示名称与别名;计算公式在上方计算规则中维护</span></div><Button icon={<ReloadOutlined />} onClick={() => void load()}>刷新字典</Button></div>
|
||||
return <CompactManagementTables.Provider value={true}><section className="panel section-panel completion-tools metric-explanation-panel">
|
||||
<div className="completion-panel-heading"><div><strong>当前生效指标</strong></div><Button icon={<ReloadOutlined />} onClick={() => void load()}>刷新</Button></div>
|
||||
{dictionaryError && <Alert showIcon type="error" message="术语字典读取失败" description={loaded ? `${dictionaryError};以下为上次成功读取的结果。` : dictionaryError} action={!loaded ? <Button size="small" onClick={() => void load()}>重试</Button> : undefined} />}
|
||||
{loading && !loaded ? <div className="loading-panel"><Spin />读取术语定义…</div> : loaded ? items.length ? <div className="resource-table"><Table size="small" bordered columns={columns} dataSource={items} rowKey={row => String(row.code)} pagination={{ pageSize: TABLE_PAGE_SIZE, showSizeChanger: false }} scroll={{ x: 1100 }} /></div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无指标术语" /> : null}
|
||||
<Alert showIcon type="info" message="术语编辑不改变计算规则" description="公式来自当前查询数据所绑定的计算规则;编辑术语不会改变计算结果。" />
|
||||
<Modal className="management-modal" open={Boolean(editing)} title={`编辑术语 · ${String(editing?.code || '')}`} okText="保存术语" confirmLoading={saving} onCancel={() => { setEditing(null); form.resetFields(); }} onOk={() => void save()}>
|
||||
{loading && !loaded ? <div className="loading-panel"><Spin />读取指标说明…</div> : loaded ? items.length ? <div className="resource-table"><Table size="small" bordered columns={columns} dataSource={items} rowKey={row => String(row.code)} pagination={{ pageSize: TABLE_PAGE_SIZE, showSizeChanger: false }} scroll={{ x: 1100 }} /></div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无指标说明" /> : null}
|
||||
|
||||
<Modal className="management-modal" open={Boolean(editing)} title={`编辑说明 · ${String(editing?.name || '')}`} okText="保存说明" confirmLoading={saving} onCancel={() => { setEditing(null); form.resetFields(); }} onOk={() => void save()}>
|
||||
<Form form={form} layout="vertical">
|
||||
<Form.Item name="name" label="展示名称" rules={[{ required: true, whitespace: true, message: '请填写展示名称' }]}><Input maxLength={160} /></Form.Item>
|
||||
<Form.Item name="aliases" label="别名" extra="每行一个,也可用逗号分隔"><Input.TextArea rows={4} maxLength={1000} /></Form.Item>
|
||||
<Form.Item name="description" label="术语说明"><Input.TextArea rows={3} maxLength={1000} /></Form.Item>
|
||||
<Form.Item name="description" label="指标说明"><Input.TextArea rows={3} maxLength={1000} /></Form.Item>
|
||||
<Form.Item name="reason" label="修改原因" rules={[{ required: true, whitespace: true, message: '请填写修改原因' }]}><Input.TextArea rows={2} maxLength={300} /></Form.Item>
|
||||
</Form>
|
||||
<Alert showIcon type="info" message="当前生效公式" description={editing ? currentMetricFormula(editing) : undefined} />
|
||||
</Modal>
|
||||
<Drawer className="management-drawer" open={Boolean(inspecting)} title={`指标术语 · ${String(inspecting?.name || '')}`} width={Math.min(760, window.innerWidth)} onClose={() => setInspecting(null)}>
|
||||
<Drawer className="management-drawer" open={Boolean(inspecting)} title={`指标说明 · ${String(inspecting?.name || '')}`} width={Math.min(760, window.innerWidth)} onClose={() => setInspecting(null)}>
|
||||
{inspecting && <dl className="completion-definition-list"><dt>名称</dt><dd>{toText(inspecting.name)}</dd><dt>别名</dt><dd>{Array.isArray(inspecting.aliases) ? inspecting.aliases.map(String).join('、') : toText(inspecting.aliases)}</dd><dt>说明</dt><dd>{toText(readableRuleDescription(inspecting.description))}</dd><dt>单位</dt><dd>{inspecting.unit === 'RATE' ? '%' : toText(inspecting.unit)}</dd><dt>适用维度</dt><dd><BusinessValue value={inspecting.dimensions} field="dimensions" /></dd><dt>当前生效公式</dt><dd>{currentMetricFormula(inspecting)}</dd><dt>状态</dt><dd><BusinessValue value={inspecting.enabled} /></dd></dl>}
|
||||
</Drawer>
|
||||
</section>;
|
||||
</section></CompactManagementTables.Provider>;
|
||||
}
|
||||
|
||||
function TaskTable({ items, importOnly, user, onUnauthorized, onRefresh }: { items: Record<string, unknown>[]; importOnly: boolean; user: AuthUser; onUnauthorized: (error: unknown) => boolean; onRefresh: () => void }) {
|
||||
|
||||
Reference in New Issue
Block a user