Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
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 '@douyinfe/semi-ui';
|
||||
import { TrendingDown, TrendingUp } from 'lucide-react';
|
||||
import { changeRate, ORG_STATUS, orgDisplayName, REASONS } from './utils';
|
||||
|
||||
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>
|
||||
}
|
||||
bodyStyle={{ padding: '16px', ...bodyStyle }}
|
||||
>
|
||||
{children}
|
||||
</Card>
|
||||
);
|
||||
|
||||
export const SectionTitle = ({ id, index, title, desc }) => (
|
||||
<div
|
||||
id={id}
|
||||
className='flex items-baseline gap-2 mb-3 mt-8 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(--semi-color-success)' : 'var(--semi-color-danger)',
|
||||
}}
|
||||
>
|
||||
{up ? (
|
||||
<TrendingUp className='w-3 h-3' />
|
||||
) : (
|
||||
<TrendingDown className='w-3 h-3' />
|
||||
)}
|
||||
{up ? '+' : ''}
|
||||
{rate.toFixed(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' : ''}`}
|
||||
bodyStyle={{ padding: '14px 16px' }}
|
||||
onClick={onClick}
|
||||
style={{
|
||||
borderLeft: `3px solid ${accent || 'var(--semi-color-primary)'}`,
|
||||
}}
|
||||
>
|
||||
<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>
|
||||
);
|
||||
Reference in New Issue
Block a user