fix: 修复统计报表完成率格式和项目名称显示

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
kkfluous
2026-04-01 21:26:31 +08:00
parent 7e2eefc3da
commit dd1834477d

View File

@@ -12,6 +12,20 @@ import {
import type { TargetSummary, TargetVehicle, TrendPoint } from './types'; import type { TargetSummary, TargetVehicle, TrendPoint } from './types';
import { fetchTargets, fetchTargetVehicles, fetchTrend } from './api'; import { fetchTargets, fetchTargetVehicles, fetchTrend } from './api';
function shortTargetName(name: string): string {
// Extract the number and a short description
const match = name.match(/(\d+)[辆台](.+)/);
if (!match) return name;
const count = match[1];
let desc = match[2];
// Simplify common patterns
desc = desc.replace('4.5T普货', '普货');
desc = desc.replace('4.5T冷链车', '冷藏车');
desc = desc.replace('4.5T冷链', '冷藏车');
desc = desc.replace('18T', '18T');
return `${count}${desc}`;
}
export default function StatisticsView() { export default function StatisticsView() {
const [targets, setTargets] = useState<TargetSummary[]>([]); const [targets, setTargets] = useState<TargetSummary[]>([]);
const [trendData, setTrendData] = useState<TrendPoint[]>([]); const [trendData, setTrendData] = useState<TrendPoint[]>([]);
@@ -56,7 +70,7 @@ export default function StatisticsView() {
: 'bg-slate-50 landscape:bg-slate-800 text-slate-500 landscape:text-slate-400 hover:bg-slate-100 landscape:hover:bg-slate-700' : 'bg-slate-50 landscape:bg-slate-800 text-slate-500 landscape:text-slate-400 hover:bg-slate-100 landscape:hover:bg-slate-700'
}`} }`}
> >
{target.targetName} {shortTargetName(target.targetName)}
</button> </button>
))} ))}
</div> </div>
@@ -208,7 +222,7 @@ export default function StatisticsView() {
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
<span className="text-[9px] text-slate-400">:</span> <span className="text-[9px] text-slate-400">:</span>
<span className={`text-[9px] font-bold ${target.avgCompletion >= 90 ? 'text-emerald-500' : 'text-blue-500'}`}>{target.avgCompletion}%</span> <span className={`text-[9px] font-bold ${target.avgCompletion >= 90 ? 'text-emerald-500' : 'text-blue-500'}`}>{target.avgCompletion.toFixed(1)}%</span>
</div> </div>
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
<span className="text-[9px] text-slate-400">:</span> <span className="text-[9px] text-slate-400">:</span>
@@ -426,7 +440,7 @@ export default function StatisticsView() {
style={{ width: `${target.avgCompletion}%` }} style={{ width: `${target.avgCompletion}%` }}
/> />
</div> </div>
<span className="text-[10px] font-bold text-white">{target.avgCompletion}%</span> <span className="text-[10px] font-bold text-white">{target.avgCompletion.toFixed(1)}%</span>
</div> </div>
</td> </td>
<td className="p-4 text-[10px] text-slate-400">{target.period}</td> <td className="p-4 text-[10px] text-slate-400">{target.period}</td>