feat(platform-web): use lightweight overview for vehicle context
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { Toast } from '@douyinfe/semi-ui';
|
||||
import { api } from './api/client';
|
||||
import type { VehicleServiceStatus } from './api/types';
|
||||
import type { VehicleServiceOverview, VehicleServiceStatus } from './api/types';
|
||||
import { buildAppHash, parseAppHash } from './domain/appRoute';
|
||||
import { AppShell, type PageKey } from './layout/AppShell';
|
||||
import { Dashboard } from './pages/Dashboard';
|
||||
@@ -28,11 +28,12 @@ export default function App() {
|
||||
if (!lookupKey) {
|
||||
return undefined;
|
||||
}
|
||||
const resolved = await api.vehicleResolve(new URLSearchParams({ keyword: lookupKey }));
|
||||
const nextKey = resolved.resolved && resolved.vin ? resolved.vin : lookupKey;
|
||||
setCurrentVehicleStatus(resolved.serviceStatus);
|
||||
setCurrentVehicleLabel(resolved.resolved ? [resolved.plate, resolved.vin || nextKey].filter(Boolean).join(' / ') : lookupKey);
|
||||
return { resolved, nextKey };
|
||||
const overview = await api.vehicleServiceOverview(new URLSearchParams({ keyword: lookupKey }));
|
||||
const nextKey = overview.vin || lookupKey;
|
||||
const resolved = Boolean(overview.vin);
|
||||
setCurrentVehicleStatus(serviceStatusFromOverview(overview));
|
||||
setCurrentVehicleLabel(resolved ? [overview.plate, overview.vin || nextKey].filter(Boolean).join(' / ') : lookupKey);
|
||||
return { resolved, nextKey, overview };
|
||||
}, []);
|
||||
|
||||
const refreshOpsHealth = useCallback((showError = true) => {
|
||||
@@ -120,7 +121,7 @@ export default function App() {
|
||||
setActiveProtocol(nextProtocol);
|
||||
setActivePage('detail');
|
||||
replaceHash('detail', nextKey, nextProtocol);
|
||||
if (!resolved?.resolved) {
|
||||
if (!resolved) {
|
||||
Toast.warning('未匹配到车辆身份,已打开问题排查视图');
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -179,3 +180,56 @@ export default function App() {
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
function serviceStatusFromOverview(overview: VehicleServiceOverview): VehicleServiceStatus {
|
||||
const sourceCount = overview.sourceCount;
|
||||
const onlineSourceCount = overview.onlineSourceCount;
|
||||
if (!overview.vin) {
|
||||
return {
|
||||
status: 'identity_required',
|
||||
severity: 'warning',
|
||||
title: '身份未绑定',
|
||||
detail: '车辆关键词暂未解析到 VIN,需先维护身份绑定后才能形成完整车辆服务。',
|
||||
sourceCount,
|
||||
onlineSourceCount
|
||||
};
|
||||
}
|
||||
if (sourceCount <= 0) {
|
||||
return {
|
||||
status: 'no_data',
|
||||
severity: 'warning',
|
||||
title: '暂无数据来源',
|
||||
detail: '车辆已解析,但暂未查询到 32960、808 或 MQTT 数据来源。',
|
||||
sourceCount,
|
||||
onlineSourceCount
|
||||
};
|
||||
}
|
||||
if (onlineSourceCount <= 0) {
|
||||
return {
|
||||
status: 'offline',
|
||||
severity: 'error',
|
||||
title: '车辆离线',
|
||||
detail: '所有已知数据来源均未在线,需要检查平台转发、终端上报或链路状态。',
|
||||
sourceCount,
|
||||
onlineSourceCount
|
||||
};
|
||||
}
|
||||
if (onlineSourceCount < sourceCount) {
|
||||
return {
|
||||
status: 'degraded',
|
||||
severity: 'warning',
|
||||
title: '部分来源离线',
|
||||
detail: `${onlineSourceCount}/${sourceCount} 个来源在线,车辆服务可用但需要关注离线来源。`,
|
||||
sourceCount,
|
||||
onlineSourceCount
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: 'healthy',
|
||||
severity: 'ok',
|
||||
title: '服务正常',
|
||||
detail: `${onlineSourceCount}/${sourceCount} 个来源在线,全部已知来源在线。`,
|
||||
sourceCount,
|
||||
onlineSourceCount
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user