运维网关支持按车辆配置方法真实下发,并按用户过滤审计。

新增 ops.car.execute 路径与前端运维操作/选中面板联动。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
黄兆尉
2026-08-26 17:50:34 +08:00
co-authored by Cursor
parent c5d5f7a726
commit c9e835aaf7
7 changed files with 681 additions and 217 deletions
@@ -1,3 +1,4 @@
import { executeOp } from './ops'
import { ReflectionApiError, reflectionApi } from './reflection'
export type VehicleMaintenanceMode = 'online' | 'offline' | 'repair' | 'blown'
@@ -54,28 +55,23 @@ export async function setVehicleMaintenance(
}
}
async function tryExecuteMethods(carId: number, methods: readonly string[]): Promise<boolean> {
let lastErr: unknown
for (const method of methods) {
try {
await reflectionApi.execute('car', carId, method)
return true
} catch (err) {
if (!isUnsupportedMethodError(err)) throw err
lastErr = err
}
}
if (lastErr) throw lastErr
return false
}
function isUnsupportedMethodError(err: unknown): boolean {
if (err instanceof ReflectionApiError && (err.code === 404 || err.code === 405)) return true
const msg = err instanceof Error ? err.message : String(err)
return /method|not\s*found|unsupported|not\s*supported/i.test(msg)
}
/** 执行车辆快捷动作;失败抛错,由调用方提示。 */
async function executeCarMethodViaOps(carId: number, method: string): Promise<void> {
const resp = await executeOp({
opCode: 'ops.car.execute',
targetId: String(carId),
method
})
if (resp.ok) return
throw new Error(resp.message || `执行 ${method} 未成功`)
}
/** 执行车辆快捷动作;失败抛错,由调用方提示。经运维网关以便写入运维记录。 */
export async function executeVehicleQuickAction(
carId: number,
action: VehicleQuickAction
@@ -84,12 +80,26 @@ export async function executeVehicleQuickAction(
throw new Error('无效车辆 ID')
}
if (action === 'endTask') {
const ok = await tryExecuteMethods(carId, END_TASK_METHODS)
if (!ok) throw new Error('当前车型不支持结束任务')
return
let lastErr: unknown
for (const method of END_TASK_METHODS) {
try {
await executeCarMethodViaOps(carId, method)
return
} catch (err) {
lastErr = err
if (!isUnsupportedMethodError(err) && !isUnconfiguredMethodError(err)) throw err
}
}
if (lastErr) throw lastErr
throw new Error('当前车型不支持结束任务')
}
const method = QUICK_METHOD_MAP[action]
await reflectionApi.execute('car', carId, method)
await executeCarMethodViaOps(carId, method)
}
function isUnconfiguredMethodError(err: unknown): boolean {
const msg = err instanceof Error ? err.message : String(err)
return /不在该车型已配置|未配置动作/.test(msg)
}
export function openOnboardWeb(url?: string | null, ip?: string | null): void {