feat(platform): expose realtime service status
This commit is contained in:
@@ -11,6 +11,22 @@ function canOpenVehicle(vin?: string) {
|
||||
return Boolean(value && value !== 'unknown');
|
||||
}
|
||||
|
||||
function vehicleServiceStatus(row: VehicleRealtimeRow) {
|
||||
if (row.serviceStatus) {
|
||||
return {
|
||||
label: row.serviceStatus.title,
|
||||
color: row.serviceStatus.severity === 'ok' ? 'green' as const : row.serviceStatus.severity === 'error' ? 'red' as const : 'orange' as const
|
||||
};
|
||||
}
|
||||
if (row.onlineSourceCount <= 0) {
|
||||
return { label: '车辆离线', color: 'red' as const };
|
||||
}
|
||||
if (row.onlineSourceCount < row.sourceCount) {
|
||||
return { label: '部分来源离线', color: 'orange' as const };
|
||||
}
|
||||
return { label: '服务正常', color: 'green' as const };
|
||||
}
|
||||
|
||||
export function Realtime({ onOpenVehicle }: { onOpenVehicle: (vin: string, protocol?: string) => void }) {
|
||||
const [rows, setRows] = useState<VehicleRealtimeRow[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -23,6 +39,7 @@ export function Realtime({ onOpenVehicle }: { onOpenVehicle: (vin: string, proto
|
||||
if (values?.keyword) params.set('keyword', values.keyword);
|
||||
if (values?.protocol) params.set('protocol', values.protocol);
|
||||
if (values?.online) params.set('online', values.online);
|
||||
if (values?.serviceStatus) params.set('serviceStatus', values.serviceStatus);
|
||||
api.vehicleRealtime(params)
|
||||
.then((nextPage) => {
|
||||
setRows(nextPage.items);
|
||||
@@ -55,6 +72,12 @@ export function Realtime({ onOpenVehicle }: { onOpenVehicle: (vin: string, proto
|
||||
<Select.Option value="online">在线</Select.Option>
|
||||
<Select.Option value="offline">离线</Select.Option>
|
||||
</Form.Select>
|
||||
<Form.Select field="serviceStatus" label="服务状态" placeholder="全部" style={{ width: 150 }}>
|
||||
<Select.Option value="healthy">服务正常</Select.Option>
|
||||
<Select.Option value="degraded">部分来源离线</Select.Option>
|
||||
<Select.Option value="offline">车辆离线</Select.Option>
|
||||
<Select.Option value="identity_required">身份未绑定</Select.Option>
|
||||
</Form.Select>
|
||||
<Space>
|
||||
<Button htmlType="submit" theme="solid" type="primary">查询</Button>
|
||||
<Button onClick={() => {
|
||||
@@ -95,6 +118,14 @@ export function Realtime({ onOpenVehicle }: { onOpenVehicle: (vin: string, proto
|
||||
)
|
||||
},
|
||||
{ title: '覆盖', width: 90, render: (_: unknown, row: VehicleRealtimeRow) => `${row.onlineSourceCount}/${row.sourceCount}` },
|
||||
{
|
||||
title: '车辆服务状态',
|
||||
width: 130,
|
||||
render: (_: unknown, row: VehicleRealtimeRow) => {
|
||||
const status = vehicleServiceStatus(row);
|
||||
return <Tag color={status.color}>{status.label}</Tag>;
|
||||
}
|
||||
},
|
||||
{ title: '在线', width: 90, render: (_: unknown, row: VehicleRealtimeRow) => <StatusTag status={row.online ? 'ok' : 'offline'} /> },
|
||||
{ title: '速度 km/h', dataIndex: 'speedKmh' },
|
||||
{ title: 'SOC %', dataIndex: 'socPercent' },
|
||||
|
||||
Reference in New Issue
Block a user