ValidationStats.tsx
3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { UCard } from '@uj/ui';
import type { StoreImportCheckVO } from '@/api/modules/store';
export interface StatItem {
label: string;
value: string | number;
desc: string;
tone: 'primary' | 'success' | 'warning' | 'default';
}
interface StatCardProps {
item: StatItem;
}
const toneMap: Record<StatItem['tone'], { border: string; accent: string }> = {
primary: {
border: '1px solid #C7D2FE',
accent: '#2B5CE6',
},
success: {
border: '1px solid #86EFAC',
accent: '#16A34A',
},
warning: {
border: '1px solid #FCD34D',
accent: '#CA8A04',
},
default: {
border: '1px solid #E5E7EB',
accent: '#6B7280',
},
};
function StatCard({ item }: StatCardProps) {
const tone = toneMap[item.tone];
return (
<UCard
styles={{ body: { padding: '18px 20px' } }}
style={{
borderLeft: `3px solid ${tone.accent}`,
border: tone.border,
borderRadius: 10,
background: '#fff',
}}
>
<div
style={{
fontSize: 13,
color: '#6B7280',
marginBottom: 10,
fontWeight: 500,
}}
>
{item.label}
</div>
<div
style={{
fontSize: 26,
fontWeight: 700,
color: '#1A202C',
marginBottom: 8,
lineHeight: 1.2,
}}
>
{item.value}
</div>
<div
style={{
fontSize: 12,
color: '#9CA3AF',
lineHeight: 1.5,
}}
>
{item.desc}
</div>
</UCard>
);
}
export interface ValidationStatsProps {
stats?: StatItem[];
checkResult?: StoreImportCheckVO;
}
function buildStatsFromCheckResult(vo: StoreImportCheckVO): StatItem[] {
const rows = vo.productCategoryRowCount ?? vo.totalRows;
const storeCount = 1;
const sceneCount = vo.distinctBusinessSceneCount;
const items: StatItem[] = [
{
label: '解析总行数',
value: vo.totalRows,
desc: `${storeCount} 家门店 · ${sceneCount} 个业务场景 · ${rows} 行`,
tone: 'primary',
},
{
label: '校验通过',
value: vo.passRows,
desc: vo.passRows > 0 ? '可提交审批' : '无通过数据',
tone: 'success',
},
];
if (vo.failRows > 0) {
items.push({
label: '校验失败',
value: vo.failRows,
desc: vo.failFileUrl ? '可下载失败明细文件' : '需修正后重新上传',
tone: 'warning',
});
}
return items;
}
const defaultStats: StatItem[] = [
{
label: '解析总行数',
value: '-',
desc: '上传文件后展示',
tone: 'primary',
},
{
label: '校验通过',
value: '-',
desc: '上传文件后展示',
tone: 'success',
},
];
export function ValidationStats({ stats, checkResult }: ValidationStatsProps) {
const finalStats: StatItem[] =
stats ?? (checkResult ? buildStatsFromCheckResult(checkResult) : defaultStats);
// 按实际卡片数量平分整行宽度
const colCount = Math.max(1, finalStats.length);
return (
<div
style={{
display: 'grid',
gridTemplateColumns: `repeat(${colCount}, minmax(0, 1fr))`,
gap: 16,
marginBottom: 20,
}}
>
{finalStats.map((s) => (
<StatCard key={s.label} item={s} />
))}
</div>
);
}