Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
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, { useCallback, useMemo, useState } from 'react';
|
||||
import { Button, Card, Typography } from '@douyinfe/semi-ui';
|
||||
import { ActionCenter, ACTION_TABS } from './ActionCenter';
|
||||
import {
|
||||
ChangeAttribution,
|
||||
TiersAndRankings,
|
||||
TopModels,
|
||||
TrendChart,
|
||||
} from './Analysis';
|
||||
import { HealthSegments, KeyFindings, KpiGrid, ReportHeader } from './Overview';
|
||||
import { SectionTitle } from './shared';
|
||||
import {
|
||||
EMPTY_DETAIL_FILTER,
|
||||
exportOrgDetail,
|
||||
OrgDetailTable,
|
||||
SalesRepTable,
|
||||
} from './Tables';
|
||||
import {
|
||||
deriveActionLists,
|
||||
deriveFindings,
|
||||
deriveSalesReps,
|
||||
getCnyParams,
|
||||
} from './utils';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// 页签内锚点跳转:顶栏与跑马灯为 fixed,元素上已加 scroll-mt 让位
|
||||
const scrollToId = (id) => {
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
};
|
||||
|
||||
const ReportSkeleton = () => (
|
||||
<div className='space-y-4'>
|
||||
<div className='h-[92px] rounded-xl bg-gray-100 dark:bg-gray-800 animate-pulse' />
|
||||
<div className='h-[160px] rounded-xl bg-gray-100 dark:bg-gray-800 animate-pulse' />
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3'>
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className='h-[96px] rounded-xl bg-gray-100 dark:bg-gray-800 animate-pulse'
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const OrgReportPanel = ({ report, loading, error, onRetry, t }) => {
|
||||
const cny = useMemo(getCnyParams, []);
|
||||
const [actionTab, setActionTab] = useState('renewal');
|
||||
const [detailFilter, setDetailFilter] = useState(EMPTY_DETAIL_FILTER);
|
||||
|
||||
const lists = useMemo(
|
||||
() => deriveActionLists(report?.orgs, report?.meta),
|
||||
[report],
|
||||
);
|
||||
const findings = useMemo(
|
||||
() => deriveFindings(report, lists, cny, t),
|
||||
[report, lists, cny, t],
|
||||
);
|
||||
const reps = useMemo(
|
||||
() => deriveSalesReps(report?.orgs, lists),
|
||||
[report, lists],
|
||||
);
|
||||
|
||||
const jump = useCallback((target) => {
|
||||
if (ACTION_TABS.includes(target)) {
|
||||
setActionTab(target);
|
||||
scrollToId('org-report-actions');
|
||||
return;
|
||||
}
|
||||
scrollToId(`org-report-${target}`);
|
||||
}, []);
|
||||
|
||||
const filterDetail = useCallback((patch) => {
|
||||
setDetailFilter({ ...EMPTY_DETAIL_FILTER, ...patch });
|
||||
scrollToId('org-report-detail');
|
||||
}, []);
|
||||
|
||||
if (!report) {
|
||||
if (error) {
|
||||
return (
|
||||
<Card className='shadow-sm'>
|
||||
<div className='py-12 flex flex-col items-center gap-3'>
|
||||
<Text type='danger'>{t('企业经营报表加载失败,请稍后重试')}</Text>
|
||||
<Button onClick={onRetry} loading={loading}>
|
||||
{t('重试')}
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
return <ReportSkeleton />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
loading
|
||||
? 'opacity-60 transition-opacity pointer-events-none'
|
||||
: 'transition-opacity'
|
||||
}
|
||||
>
|
||||
<ReportHeader
|
||||
report={report}
|
||||
onExport={() => exportOrgDetail(report.orgs || [], cny, t)}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<KeyFindings findings={findings} onJump={jump} t={t} />
|
||||
|
||||
<SectionTitle
|
||||
index={1}
|
||||
title={t('核心指标')}
|
||||
desc={t('本期对比等长对比期;点击卡片定位到相关分析')}
|
||||
/>
|
||||
<KpiGrid report={report} lists={lists} cny={cny} onJump={jump} t={t} />
|
||||
|
||||
<SectionTitle
|
||||
index={2}
|
||||
title={t('客户健康分群')}
|
||||
desc={t('按本期与对比期的使用变化划分,点击分群筛选企业明细')}
|
||||
/>
|
||||
<HealthSegments
|
||||
report={report}
|
||||
cny={cny}
|
||||
activeSegment={detailFilter.segment}
|
||||
onSelect={(segment) =>
|
||||
segment
|
||||
? filterDetail({ segment })
|
||||
: setDetailFilter(EMPTY_DETAIL_FILTER)
|
||||
}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<SectionTitle
|
||||
index={3}
|
||||
title={t('行动清单')}
|
||||
desc={t('续费、挽回、增长、激活四类待办,含建议动作与联系人')}
|
||||
/>
|
||||
<ActionCenter
|
||||
lists={lists}
|
||||
activeTab={actionTab}
|
||||
onTabChange={setActionTab}
|
||||
cny={cny}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<SectionTitle
|
||||
index={4}
|
||||
title={t('变化归因')}
|
||||
desc={t('本期相对对比期的消耗变化由哪些企业、哪些分群贡献')}
|
||||
/>
|
||||
<ChangeAttribution report={report} cny={cny} t={t} />
|
||||
|
||||
<SectionTitle
|
||||
index={5}
|
||||
title={t('客户结构')}
|
||||
desc={t('ABC 价值分层与头部企业')}
|
||||
/>
|
||||
<TiersAndRankings
|
||||
report={report}
|
||||
cny={cny}
|
||||
onSelectTier={(tier) => filterDetail({ tier })}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<SectionTitle index={6} title={t('趋势与模型')} />
|
||||
<div className='grid grid-cols-1 xl:grid-cols-2 gap-4'>
|
||||
<TrendChart report={report} cny={cny} t={t} />
|
||||
<TopModels report={report} cny={cny} t={t} />
|
||||
</div>
|
||||
|
||||
<SectionTitle index={7} title={t('团队与明细')} />
|
||||
<div className='space-y-4 mb-6'>
|
||||
<SalesRepTable
|
||||
reps={reps}
|
||||
cny={cny}
|
||||
onSelect={(salesRep) => filterDetail({ salesRep })}
|
||||
t={t}
|
||||
/>
|
||||
<OrgDetailTable
|
||||
report={report}
|
||||
filter={detailFilter}
|
||||
setFilter={setDetailFilter}
|
||||
cny={cny}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default OrgReportPanel;
|
||||
Reference in New Issue
Block a user