e70e0d2224
验证:868 项单测、ESLint、Prettier、UI 依赖审计和差异检查通过。
176 lines
5.0 KiB
React
176 lines
5.0 KiB
React
/*
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
import React from 'react';
|
|
import { Card, Tag, Tooltip } from '@/components/ui';
|
|
import { TrendingDown, TrendingUp } from 'lucide-react';
|
|
import { changeRate, ORG_STATUS, orgDisplayName, REASONS } from './utils';
|
|
import { formatPercent } from '../../../helpers/safeDisplay';
|
|
|
|
export const SectionCard = ({
|
|
id,
|
|
title,
|
|
icon,
|
|
extra,
|
|
children,
|
|
bodyStyle,
|
|
}) => (
|
|
<Card
|
|
id={id}
|
|
className='shadow-sm h-full scroll-mt-24'
|
|
title={
|
|
<div className='flex items-center gap-2 flex-wrap min-w-0'>
|
|
<span className='text-brand flex-shrink-0'>{icon}</span>
|
|
<span className='font-semibold'>{title}</span>
|
|
{extra}
|
|
</div>
|
|
}
|
|
styles={{ body: { padding: '16px', ...bodyStyle } }}
|
|
>
|
|
{children}
|
|
</Card>
|
|
);
|
|
|
|
export const SectionTitle = ({ id, index, title, desc }) => (
|
|
<div
|
|
id={id}
|
|
className='flex items-baseline gap-2 mb-3 mt-4 flex-wrap scroll-mt-24'
|
|
>
|
|
{index ? (
|
|
<span className='text-xs font-semibold tracking-wider text-brand tabular-nums'>
|
|
{String(index).padStart(2, '0')}
|
|
</span>
|
|
) : null}
|
|
<h3 className='text-base font-semibold text-gray-800 dark:text-gray-100'>
|
|
{title}
|
|
</h3>
|
|
{desc ? (
|
|
<span className='text-xs text-gray-500 dark:text-gray-400'>{desc}</span>
|
|
) : null}
|
|
</div>
|
|
);
|
|
|
|
// 变化值:上升绿、下降红;对比期为 0 时无法计算
|
|
export const ChangeText = ({ cur, prev, t, size = 'xs', showNew = true }) => {
|
|
const rate = changeRate(cur, prev);
|
|
const sizeClass = size === 'sm' ? 'text-sm' : 'text-xs';
|
|
if (rate === null) {
|
|
return cur > 0 && showNew ? (
|
|
<span className={`${sizeClass} text-gray-400`}>{t('对比期无数据')}</span>
|
|
) : (
|
|
<span className={`${sizeClass} text-gray-400`}>—</span>
|
|
);
|
|
}
|
|
const up = rate >= 0;
|
|
return (
|
|
<span
|
|
className={`inline-flex items-center gap-0.5 ${sizeClass} font-medium tabular-nums`}
|
|
style={{
|
|
color: up ? 'var(--ui-color-success)' : 'var(--ui-color-danger)',
|
|
}}
|
|
>
|
|
{up ? (
|
|
<TrendingUp className='w-3 h-3' />
|
|
) : (
|
|
<TrendingDown className='w-3 h-3' />
|
|
)}
|
|
{up ? '+' : ''}
|
|
{formatPercent(rate, 1)}
|
|
</span>
|
|
);
|
|
};
|
|
|
|
export const KpiCard = ({
|
|
title,
|
|
value,
|
|
sub,
|
|
compare,
|
|
tip,
|
|
accent,
|
|
onClick,
|
|
}) => (
|
|
<Card
|
|
className={`shadow-sm border-none transition-shadow ${onClick ? 'cursor-pointer hover:shadow-md' : ''}`}
|
|
onClick={onClick}
|
|
style={{
|
|
borderLeft: `3px solid ${accent || 'var(--ui-color-primary)'}`,
|
|
}}
|
|
styles={{ body: { padding: '14px 16px' } }}
|
|
>
|
|
<div className='flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400 mb-1'>
|
|
<span className='truncate'>{title}</span>
|
|
{tip ? (
|
|
<Tooltip content={tip}>
|
|
<span className='cursor-help text-gray-400'>ⓘ</span>
|
|
</Tooltip>
|
|
) : null}
|
|
</div>
|
|
<div className='text-xl font-bold text-gray-800 dark:text-gray-100 tabular-nums truncate'>
|
|
{value}
|
|
</div>
|
|
<div className='flex items-center justify-between gap-2 mt-1 min-h-[18px]'>
|
|
<span className='text-xs text-gray-500 dark:text-gray-400 truncate'>
|
|
{sub}
|
|
</span>
|
|
{compare}
|
|
</div>
|
|
</Card>
|
|
);
|
|
|
|
export const OrgNameCell = ({ org, t, showCode = true }) => {
|
|
const name = orgDisplayName(org, t);
|
|
const status = ORG_STATUS[org.status];
|
|
return (
|
|
<div className='min-w-0'>
|
|
<div className='flex items-center gap-1.5 min-w-0'>
|
|
<span className='font-medium truncate' title={name}>
|
|
{name}
|
|
</span>
|
|
{!org.deleted && status && org.status !== 1 ? (
|
|
<Tag size='small' color={status.color} className='flex-shrink-0'>
|
|
{t(status.label)}
|
|
</Tag>
|
|
) : null}
|
|
</div>
|
|
{showCode && org.code ? (
|
|
<div className='text-xs text-gray-400 truncate'>{org.code}</div>
|
|
) : null}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const ReasonTags = ({ reasons, t }) => (
|
|
<div className='flex flex-wrap gap-1'>
|
|
{(reasons || []).map((r) => (
|
|
<Tag key={r} size='small' color={REASONS[r]?.color || 'grey'}>
|
|
{t(REASONS[r]?.label || r)}
|
|
</Tag>
|
|
))}
|
|
</div>
|
|
);
|
|
|
|
export const EmptyBlock = ({ height = 240, text }) => (
|
|
<div
|
|
className='flex items-center justify-center text-gray-400 text-sm'
|
|
style={{ height }}
|
|
>
|
|
{text}
|
|
</div>
|
|
);
|