fixImport
This commit is contained in:
parent
908e080977
commit
824dc1d702
|
|
@ -3,7 +3,12 @@ import { Importation, Exportation } from 'oak-domain/lib/types/Port';
|
|||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||||
export declare function registerPorts<ED extends EntityDict>(importations: Importation<ED, keyof ED, any>[], exportations: Exportation<ED, keyof ED, any>[]): void;
|
||||
export declare function clearPorts(): void;
|
||||
export declare function importEntity<ED extends EntityDict, Cxt extends AsyncContext<ED>>(params: FormData, context: Cxt): Promise<ArrayBuffer | void>;
|
||||
export declare function importEntity<ED extends EntityDict, Cxt extends AsyncContext<ED>>(params: {
|
||||
entity: string;
|
||||
id: string;
|
||||
file: File;
|
||||
option: string;
|
||||
}, context: Cxt): Promise<ArrayBuffer | void>;
|
||||
export declare function exportEntity<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>>(params: {
|
||||
entity: T;
|
||||
id: string;
|
||||
|
|
|
|||
12
lib/port.js
12
lib/port.js
|
|
@ -40,17 +40,17 @@ function getExportation(id) {
|
|||
return Exportations[id];
|
||||
}
|
||||
async function importEntity(params, context) {
|
||||
const entity = params.get('entity');
|
||||
const file = params.get('file');
|
||||
const id = params.get('id');
|
||||
const option = JSON.parse(params.get('option'));
|
||||
const entity = params.entity;
|
||||
const file = params.file;
|
||||
const id = params.id;
|
||||
const option = JSON.parse(params.option);
|
||||
const importation = getImportation(id);
|
||||
if (!importation) {
|
||||
throw new Error('尚不支持此数据的导入');
|
||||
}
|
||||
const { fn } = importation;
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const workbook = (0, xlsx_1.read)(arrayBuffer);
|
||||
// const arrayBuffer = await file.arrayBuffer();
|
||||
const workbook = (0, xlsx_1.read)(file, { type: 'buffer' });
|
||||
const { SheetNames, Sheets } = workbook;
|
||||
const errorSheets = [];
|
||||
for (const sheetName of SheetNames) {
|
||||
|
|
|
|||
19
src/port.ts
19
src/port.ts
|
|
@ -47,18 +47,23 @@ function getExportation<ED extends EntityDict, T extends keyof ED>(id: string) {
|
|||
export async function importEntity<
|
||||
ED extends EntityDict,
|
||||
Cxt extends AsyncContext<ED>
|
||||
>(params: FormData, context: Cxt): Promise<ArrayBuffer | void> {
|
||||
const entity = params.get('entity') as keyof ED;
|
||||
const file = params.get('file') as File;
|
||||
const id = params.get('id') as string;
|
||||
const option = JSON.parse(params.get('option') as string);
|
||||
>(params: {
|
||||
entity: string,
|
||||
id: string,
|
||||
file: File,
|
||||
option: string,
|
||||
}, context: Cxt): Promise<ArrayBuffer | void> {
|
||||
const entity = params.entity;
|
||||
const file = params.file;
|
||||
const id = params.id;
|
||||
const option = JSON.parse(params.option);
|
||||
const importation = getImportation<ED, keyof ED>(id);
|
||||
if (!importation) {
|
||||
throw new Error('尚不支持此数据的导入');
|
||||
}
|
||||
const { fn } = importation;
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const workbook = read(arrayBuffer);
|
||||
// const arrayBuffer = await file.arrayBuffer();
|
||||
const workbook = read(file, { type: 'buffer' });
|
||||
const { SheetNames, Sheets } = workbook;
|
||||
const errorSheets = [];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue