卢春龙
2026-04-24 aa8038c44dc8e2eda1e801b8f44f54d00fd649e3
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
// 距离值归一化为米/公里展示结构
export const normalizeDistanceKm = (value: any) => {
  const num = Number(value);
  if (Number.isNaN(num)) {
    return null;
  }
  if (num >= 1000) {
    return { value: Number((num / 1000).toFixed(1)), unit: 'km' as const };
  }
  return { value: Math.max(0, Math.round(num)), unit: 'm' as const };
};
 
// 时长值归一化为秒
export const normalizeDurationSeconds = (value: any) => {
  const num = Number(value);
  if (Number.isNaN(num)) {
    return null;
  }
  return Math.round(num);
};
 
// 剩余时长展示(begin-route):分钟按向下截断,秒按四舍五入
export const formatRemainingDurationDisplay = (value: any) => {
  const num = Number(value);
  if (Number.isNaN(num)) {
    return { value: 0, unit: '分钟' as const };
  }
  if (num < 60) {
    return { value: Math.max(0, Math.round(num)), unit: '秒' as const };
  }
  return { value: Math.max(0, Math.floor(num / 60)), unit: '分钟' as const };
};