export增加properties

This commit is contained in:
wenjiarui 2023-06-26 18:42:58 +08:00
parent 321543482e
commit ef70ab18ca
3 changed files with 6 additions and 2 deletions

1
lib/port.d.ts vendored
View File

@ -13,6 +13,7 @@ export declare function exportEntity<ED extends EntityDict, T extends keyof ED,
entity: T;
id: string;
filter?: ED[T]['Selection']['filter'];
properties?: Record<string, any>;
}, context: Cxt): Promise<ArrayBuffer>;
export declare function getImportationTemplate<ED extends EntityDict, Cxt extends AsyncContext<ED>>(params: {
id: string;

View File

@ -76,6 +76,7 @@ exports.importEntity = importEntity;
async function exportEntity(params, context) {
const id = params.id;
const filter = params.filter;
const properties = params.properties;
const exportation = getExportation(id);
if (!exportation) {
throw new Error('尚不支持此数据的导出');
@ -89,7 +90,7 @@ async function exportEntity(params, context) {
(0, assert_1.default)(headers2 && headers2.length > 0, '导出未传入表头');
const fittedDatalist = [];
for (const data of dataList) {
fittedDatalist.push(await fn(data, context));
fittedDatalist.push(await fn(data, context, properties));
}
const exportSheet = xlsx_1.utils.json_to_sheet(fittedDatalist, { header: headers2 });
const exportBook = xlsx_1.utils.book_new();

View File

@ -99,9 +99,11 @@ export async function exportEntity<
entity: T;
id: string;
filter?: ED[T]['Selection']['filter'];
properties?: Record<string, any>;
}, context: Cxt): Promise<ArrayBuffer> {
const id = params.id;
const filter = params.filter;
const properties = params.properties;
const exportation = getExportation<ED, keyof ED>(id);
if (!exportation) {
throw new Error('尚不支持此数据的导出');
@ -119,7 +121,7 @@ export async function exportEntity<
assert(headers2 && headers2.length > 0, '导出未传入表头')
const fittedDatalist = []
for (const data of dataList) {
fittedDatalist.push(await fn(data as ED[keyof ED]['Schema'], context));
fittedDatalist.push(await fn(data as ED[keyof ED]['Schema'], context, properties));
}
const exportSheet = utils.json_to_sheet(fittedDatalist, { header: headers2 });
const exportBook = utils.book_new();