feat(tab): 拆开展示与序列化 — field.format(展示) vs stringify/parse(可逆往返)
v0.6.3 用同一个 stringify 同时扛表格展示和 export 序列化,二者诉求冲突: 展示要好看可有损,export 要可逆完整。现拆为: - field.format → _label 展示文本(给人看,可有损),默认 JSON.stringify - field.stringify/parse → export/import 可逆对(机器往返),默认 JSON export 改用 stringify(可逆)而非 _label,import 的 parse 能还原。
This commit is contained in:
@@ -60,8 +60,8 @@ export const defaultTypeHandlers: Record<string, IFieldTypeHandler> = {
|
||||
}
|
||||
return value
|
||||
},
|
||||
// 本体原样下发对象(不再 stringify);展示文本走 _label
|
||||
resLabel: (value, field) => (field.stringify ?? JSON.stringify)(value),
|
||||
// 本体原样下发对象(不再 stringify);展示文本走 _label,用 format(给人看,可有损)
|
||||
resLabel: (value, field) => (field.format ?? JSON.stringify)(value),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -395,13 +395,15 @@ export class ShrimpTableModule<T, P extends ITableCrudProto<T> = ITableCrudProto
|
||||
delete shrimpQuery.limit
|
||||
const result = await this.dataSource.list(shrimpQuery)
|
||||
result.list = await this.prepareResponseItems(result.list)
|
||||
// 导出是"给人看"的边界:把带 resLabel 的结构化字段(如 tab)用其字符串文本替换对象本体,
|
||||
// 列保持可读,且能被 import 的 reqFilter(parse)原样还原;去掉额外的 _label 列。
|
||||
// 导出是机器往返的边界:结构化字段(如 tab)用可逆的 stringify 序列化(默认 JSON),
|
||||
// import 端的 reqFilter(parse) 能原样还原;展示用的 _label 不进导出,去掉。
|
||||
const labelFields = this.fields.filter(f => this.getTypeHandler(f)?.resLabel)
|
||||
return result.list.map(item => {
|
||||
const row = this.filterHidden(item)
|
||||
for (const f of labelFields) {
|
||||
if (row[`${f.key}_label`] !== undefined) row[f.key] = row[`${f.key}_label`]
|
||||
if (row[f.key] !== undefined && typeof row[f.key] === "object") {
|
||||
row[f.key] = (f.stringify ?? JSON.stringify)(row[f.key])
|
||||
}
|
||||
delete row[`${f.key}_label`]
|
||||
}
|
||||
return row
|
||||
|
||||
Reference in New Issue
Block a user