完善运行轨迹点展示与模拟数据
This commit is contained in:
@@ -116,5 +116,10 @@ assertIncludes(
|
||||
"if (detail.track && typeof detail.track === 'object')",
|
||||
'运行轨迹详情必须解包 track 聚合主记录',
|
||||
);
|
||||
assertIncludes(
|
||||
detailContract,
|
||||
"rawColumns: ['direction']",
|
||||
'轨迹点行进方向必须保留原始采集值,不得套用收支方向枚举',
|
||||
);
|
||||
|
||||
process.stdout.write('平台48类资源中文展示契约检查通过\n');
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
export type ResourceCollectionContract = {
|
||||
columns: string[];
|
||||
jsonColumns?: string[];
|
||||
rawColumns?: string[];
|
||||
relationIdentityKeys?: Record<string, string>;
|
||||
};
|
||||
|
||||
@@ -115,6 +116,7 @@ const contracts: Record<string, ResourceDetailContract> = {
|
||||
'occurred_at', 'received_at', 'longitude', 'latitude', 'accuracy',
|
||||
'speed', 'direction', 'source', 'request_no',
|
||||
],
|
||||
rawColumns: ['direction'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -173,3 +175,15 @@ export function isCollectionJsonField(
|
||||
?.jsonColumns?.includes(column),
|
||||
);
|
||||
}
|
||||
|
||||
/** 判断集合字段是否必须保留接口原始值,避免同名全局枚举误用到其他业务语义。 */
|
||||
export function isCollectionRawField(
|
||||
resourceName: string,
|
||||
collectionKey: string,
|
||||
column: string,
|
||||
) {
|
||||
return Boolean(
|
||||
contracts[resourceName]?.collections?.[collectionKey]
|
||||
?.rawColumns?.includes(column),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
>
|
||||
<template #cell="{ record }">
|
||||
<div v-if="collectionRelationIdentityKey(definition.name, collection.key, column)" class="collection-relation-value">
|
||||
<span>{{ displayRawValue(column, record[column]) }}</span>
|
||||
<span>{{ displayCollectionValue(collection.key, column, record[column]) }}</span>
|
||||
<IdentityText
|
||||
v-if="record[collectionRelationIdentityKey(definition.name, collection.key, column)]"
|
||||
:value="String(record[collectionRelationIdentityKey(definition.name, collection.key, column)])"
|
||||
@@ -55,7 +55,7 @@
|
||||
<pre class="collection-json-value">{{ formatCollectionJson(record[column]) }}</pre>
|
||||
</template>
|
||||
</a-popover>
|
||||
<template v-else>{{ displayRawValue(column, record[column]) }}</template>
|
||||
<template v-else>{{ displayCollectionValue(collection.key, column, record[column]) }}</template>
|
||||
</template>
|
||||
</a-table-column>
|
||||
</template>
|
||||
@@ -81,6 +81,7 @@ import {
|
||||
import {
|
||||
collectionRelationIdentityKey,
|
||||
isCollectionJsonField,
|
||||
isCollectionRawField,
|
||||
isResourceJsonField,
|
||||
resourceDetailContract,
|
||||
} from '@/api/resource-detail-contract';
|
||||
@@ -134,6 +135,18 @@ function collectionColumnWidth(collectionKey: string, column: string) {
|
||||
return 160;
|
||||
}
|
||||
|
||||
/** 按聚合集合契约格式化单元格,专属原始字段不得套用同名全局枚举。 */
|
||||
function displayCollectionValue(
|
||||
collectionKey: string,
|
||||
column: string,
|
||||
value: unknown,
|
||||
) {
|
||||
if (isCollectionRawField(props.definition.name, collectionKey, column)) {
|
||||
return value == null || value === '' ? '-' : String(value);
|
||||
}
|
||||
return displayRawValue(column, value);
|
||||
}
|
||||
|
||||
/** 将字符串或对象参数格式化为可读 JSON;历史非 JSON 文本保持原样。 */
|
||||
function formatCollectionJson(value: unknown) {
|
||||
if (value == null || value === '') return '暂无参数';
|
||||
|
||||
Reference in New Issue
Block a user