fix: processFieldName handles object fields ({name, multi_entity}) format
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+9
-7
@@ -10,20 +10,22 @@ dayjs.extend(utc);
|
||||
* 处理字段名,去除类型后缀
|
||||
* 例如: "字段名_类型" -> "字段名"
|
||||
*/
|
||||
export function processFieldName(field: string): string {
|
||||
if (field.includes('_')) {
|
||||
return field.split('_')[0]; // 只保留类型前面的字段名
|
||||
export function processFieldName(field: string | { name: string; [key: string]: unknown }): string {
|
||||
const name = typeof field === 'string' ? field : (field?.name || '');
|
||||
if (name.includes('_')) {
|
||||
return name.split('_')[0]; // 只保留类型前面的字段名
|
||||
}
|
||||
return field;
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理字段数组,去除类型后缀并去重
|
||||
* 支持字符串和 {name, multi_entity} 对象格式
|
||||
*/
|
||||
export function processFieldNames(fields: string[]): string[] {
|
||||
export function processFieldNames(fields: (string | { name: string; [key: string]: unknown })[]): string[] {
|
||||
// 处理字段,去掉类型后缀
|
||||
const processedFields = fields.map(processFieldName);
|
||||
|
||||
const processedFields = fields.map(processFieldName).filter(Boolean);
|
||||
|
||||
// 去重并返回
|
||||
return [...new Set(processedFields)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user