importEntity增加s2jOpts

This commit is contained in:
lxy 2024-03-28 17:33:29 +08:00
parent e6ce5ec458
commit 7f38aa9152
5 changed files with 10 additions and 4 deletions

1
es/port.d.ts vendored
View File

@ -8,6 +8,7 @@ export declare function importEntity<ED extends EntityDict, Cxt extends AsyncCon
id: string;
file: any;
option: string;
s2jOpts?: string;
}, context: Cxt): Promise<ArrayBuffer | void>;
export declare function exportEntity<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>>(params: {
entity: T;

View File

@ -37,6 +37,7 @@ export async function importEntity(params, context) {
const file = params.file;
const id = params.id;
const option = JSON.parse(params.option);
const s2jOpts = params.s2jOpts ? JSON.parse(params.s2jOpts) : undefined;
const importation = getImportation(id);
if (!importation) {
throw new Error('尚不支持此数据的导入');
@ -48,7 +49,7 @@ export async function importEntity(params, context) {
const errorSheets = [];
for (const sheetName of SheetNames) {
const sheet = Sheets[sheetName];
const dataList = utils.sheet_to_json(sheet);
const dataList = utils.sheet_to_json(sheet, s2jOpts);
const errorMessageList = await fn(dataList, context, option);
if (errorMessageList.length > 0) {
errorSheets.push({

1
lib/port.d.ts vendored
View File

@ -8,6 +8,7 @@ export declare function importEntity<ED extends EntityDict, Cxt extends AsyncCon
id: string;
file: any;
option: string;
s2jOpts?: string;
}, context: Cxt): Promise<ArrayBuffer | void>;
export declare function exportEntity<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>>(params: {
entity: T;

View File

@ -42,6 +42,7 @@ async function importEntity(params, context) {
const file = params.file;
const id = params.id;
const option = JSON.parse(params.option);
const s2jOpts = params.s2jOpts ? JSON.parse(params.s2jOpts) : undefined;
const importation = getImportation(id);
if (!importation) {
throw new Error('尚不支持此数据的导入');
@ -53,7 +54,7 @@ async function importEntity(params, context) {
const errorSheets = [];
for (const sheetName of SheetNames) {
const sheet = Sheets[sheetName];
const dataList = xlsx_1.utils.sheet_to_json(sheet);
const dataList = xlsx_1.utils.sheet_to_json(sheet, s2jOpts);
const errorMessageList = await fn(dataList, context, option);
if (errorMessageList.length > 0) {
errorSheets.push({

View File

@ -2,7 +2,7 @@ import { assert } from 'oak-domain/lib/utils/assert';
import { EntityDict, SelectOption } from 'oak-domain/lib/types/Entity';
import { Importation, Exportation } from 'oak-domain/lib/types/Port';
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
import { read, utils, write, readFile } from 'xlsx';
import { read, utils, write, readFile, Sheet2JSONOpts } from 'xlsx';
const Importations: Record<string, any> = {};
@ -61,6 +61,7 @@ export async function importEntity<
id: string;
file: any; // 是否链接后台的file类型不一致暂时无法解决
option: string;
s2jOpts?: string;
},
context: Cxt
): Promise<ArrayBuffer | void> {
@ -68,6 +69,7 @@ export async function importEntity<
const file = params.file;
const id = params.id;
const option = JSON.parse(params.option);
const s2jOpts: Sheet2JSONOpts = params.s2jOpts ? JSON.parse(params.s2jOpts) : undefined;
const importation = getImportation<ED, keyof ED>(id);
if (!importation) {
throw new Error('尚不支持此数据的导入');
@ -80,7 +82,7 @@ export async function importEntity<
for (const sheetName of SheetNames) {
const sheet = Sheets[sheetName];
const dataList = utils.sheet_to_json(sheet);
const dataList = utils.sheet_to_json(sheet, s2jOpts);
const errorMessageList = await fn(
dataList as Record<string, string | number | boolean>[],
context,