Skip to content

Commit ff77d0f

Browse files
committed
fix: import formdata error
1 parent e256dd1 commit ff77d0f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

dist/vika.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/datasheet/datasheet.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import FormData from 'form-data';
21
import { DEFAULT_REQUEST_TIMEOUT } from '../const';
32
import { IAttachment } from '../interface';
43
import { Vika } from '../vika';
@@ -7,6 +6,7 @@ import { RecordManager } from './record';
76
import { ViewManager } from './view';
87

98

9+
let FormData: any = null;
1010
export class Datasheet {
1111
vika: Vika
1212

@@ -27,6 +27,11 @@ export class Datasheet {
2727
return new RecordManager(this);
2828
}
2929

30+
private async importFormDataIfNeeded() {
31+
if (!FormData) {
32+
FormData = (await import('form-data')).default;
33+
}
34+
}
3035
/**
3136
* 上传文件
3237
* @param file
@@ -37,6 +42,7 @@ export class Datasheet {
3742
if (Array.isArray(file)) {
3843
file = file[0];
3944
}
45+
await this.importFormDataIfNeeded();
4046
const form = new FormData();
4147
form.append('file', file);
4248

lib/vika.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class Vika {
8080
const error = e?.response?.data || e;
8181
result = {
8282
success: false,
83-
code: error?.code || 500,
83+
code: error?.code || 400,
8484
message: error?.message || '请求参数配置错误',
8585
};
8686
}

0 commit comments

Comments
 (0)