增强地图编辑 CAD 能力与反射对象管理体验。
补充对齐/批量建站 API,并优化反射面板、历史栈与字段管理相关交互。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import http from './http'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
mockReflectionAssemblies,
|
||||
mockReflectionBundle,
|
||||
@@ -64,6 +65,8 @@ export interface ReflectionMethod {
|
||||
returnType: string
|
||||
hasParams: boolean
|
||||
params: ReflectionParam[]
|
||||
requiresPlatformConfirm?: boolean
|
||||
confirmMessage?: string | null
|
||||
}
|
||||
|
||||
export interface ReflectionObject {
|
||||
@@ -225,30 +228,94 @@ export function emptyMonitorVisibilityMap(): MonitorVisibilityMap {
|
||||
// 单独保留命名是为了表达"业务含义不同"——可勾选全集 vs 已勾选白名单。
|
||||
export const emptyMonitorAvailableMap = emptyMonitorVisibilityMap
|
||||
|
||||
export class ReflectionApiError extends Error {
|
||||
code: number
|
||||
data: unknown
|
||||
|
||||
constructor(message: string, code: number, data?: unknown) {
|
||||
super(message)
|
||||
this.name = 'ReflectionApiError'
|
||||
this.code = code
|
||||
this.data = data ?? null
|
||||
}
|
||||
}
|
||||
|
||||
export interface ReflectionExecuteResult {
|
||||
returnValue?: string | null
|
||||
accepted?: boolean
|
||||
completed?: boolean
|
||||
}
|
||||
|
||||
/** 根据 execute 返回区分「已完成」与「已受理(后台继续)」文案。 */
|
||||
export function formatReflectionExecuteMessage(
|
||||
label: string,
|
||||
result: ReflectionExecuteResult
|
||||
): string {
|
||||
if (result.returnValue) return `已执行:${result.returnValue}`
|
||||
if (result.accepted && result.completed === false) {
|
||||
return `已受理:${label}(后台继续执行,请稍后在 SimpleLite 查看结果)`
|
||||
}
|
||||
if (result.accepted) return `已执行 ${label}`
|
||||
return `已执行 ${label}`
|
||||
}
|
||||
|
||||
export interface ReflectionExecuteOptions {
|
||||
/** 已在平台侧完成二次确认时带上,对应后端 X-Platform-Confirmed: 1 */
|
||||
platformConfirmed?: boolean
|
||||
}
|
||||
|
||||
async function get<T>(path: string): Promise<T> {
|
||||
const { data } = await http.get<ReflectionEnvelope<T>>(`${BASE}${path}`)
|
||||
if (!data?.success) throw new Error(data?.message ?? `reflection ${path} failed`)
|
||||
if (!data?.success) throw new ReflectionApiError(data?.message ?? `reflection ${path} failed`, data?.code ?? 500, data?.data)
|
||||
return data.data as T
|
||||
}
|
||||
|
||||
async function post<T>(path: string, params?: Record<string, string | number | boolean>): Promise<T> {
|
||||
const { data } = await http.post<ReflectionEnvelope<T>>(`${BASE}${path}`, null, { params })
|
||||
if (!data?.success) throw new Error(data?.message ?? `reflection ${path} failed`)
|
||||
async function post<T>(
|
||||
path: string,
|
||||
params?: Record<string, string | number | boolean>,
|
||||
headers?: Record<string, string>
|
||||
): Promise<T> {
|
||||
const { data } = await http.post<ReflectionEnvelope<T>>(`${BASE}${path}`, null, { params, headers })
|
||||
if (!data?.success) throw new ReflectionApiError(data?.message ?? `reflection ${path} failed`, data?.code ?? 500, data?.data)
|
||||
return data.data as T
|
||||
}
|
||||
|
||||
async function del<T>(path: string): Promise<T> {
|
||||
const { data } = await http.delete<ReflectionEnvelope<T>>(`${BASE}${path}`)
|
||||
if (!data?.success) throw new Error(data?.message ?? `reflection ${path} failed`)
|
||||
if (!data?.success) throw new ReflectionApiError(data?.message ?? `reflection ${path} failed`, data?.code ?? 500, data?.data)
|
||||
return data.data as T
|
||||
}
|
||||
|
||||
async function patchJson<T>(path: string, body: unknown): Promise<T> {
|
||||
const { data } = await http.patch<ReflectionEnvelope<T>>(`${BASE}${path}`, body)
|
||||
if (!data?.success) throw new Error(data?.message ?? `reflection PATCH ${path} failed`)
|
||||
if (!data?.success) throw new ReflectionApiError(data?.message ?? `reflection PATCH ${path} failed`, data?.code ?? 500, data?.data)
|
||||
return data.data as T
|
||||
}
|
||||
|
||||
async function executeWithPlatformConfirm<T>(
|
||||
path: string,
|
||||
params?: Record<string, string | number | boolean>,
|
||||
opts?: ReflectionExecuteOptions
|
||||
): Promise<T> {
|
||||
const headers = opts?.platformConfirmed ? { 'X-Platform-Confirmed': '1' } : undefined
|
||||
try {
|
||||
return await post<T>(path, params, headers)
|
||||
} catch (e) {
|
||||
if (e instanceof ReflectionApiError && e.code === 428 && !opts?.platformConfirmed) {
|
||||
const confirmMessage =
|
||||
(e.data as { confirmMessage?: string | null } | null)?.confirmMessage?.trim()
|
||||
|| '此操作需要确认'
|
||||
await ElMessageBox.confirm(confirmMessage, '确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消'
|
||||
})
|
||||
return await post<T>(path, params, { 'X-Platform-Confirmed': '1' })
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
export const reflectionApi = {
|
||||
listKinds: () => MOCK
|
||||
? Promise.resolve(mockReflectionKinds())
|
||||
@@ -371,16 +438,23 @@ export const reflectionApi = {
|
||||
fieldList?: ReflectionKv[]
|
||||
}>(`/bundle/${kind}/${id}`),
|
||||
|
||||
execute: (kind: ReflectionKind, id: number, method: string, params?: Record<string, string | number | boolean>) => MOCK
|
||||
execute: (
|
||||
kind: ReflectionKind,
|
||||
id: number,
|
||||
method: string,
|
||||
params?: Record<string, string | number | boolean>,
|
||||
opts?: ReflectionExecuteOptions
|
||||
) => MOCK
|
||||
? Promise.resolve(mockReflectionExecute(
|
||||
kind,
|
||||
id,
|
||||
method,
|
||||
Object.fromEntries(Object.entries(params ?? {}).map(([k, v]) => [k, String(v)]))
|
||||
))
|
||||
: post<{ returnValue: string }>(
|
||||
: executeWithPlatformConfirm<ReflectionExecuteResult>(
|
||||
`/execute/${kind}/${id}/${encodeURIComponent(method)}`,
|
||||
params
|
||||
params,
|
||||
opts
|
||||
),
|
||||
|
||||
/** 车辆前往指定站点(Web「去某地」;不依赖 SimpleUI.GetPoint)。 */
|
||||
|
||||
Reference in New Issue
Block a user