@cpzxrobot/sdk 1.2.76 → 1.2.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +13 -5
  2. package/index.ts +12 -4
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -160,13 +160,21 @@ class Cpzxrobot {
160
160
  const button = document.createElement("input");
161
161
  button.type = "file";
162
162
  button.style.display = "none";
163
+ button.multiple = (option === null || option === void 0 ? void 0 : option.multiple) || false;
163
164
  document.body.appendChild(button);
164
- button.onclick = async (e) => {
165
- var _a;
166
- const file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
167
- if (file) {
165
+ button.click(); // 手动触发点击
166
+ button.onchange = async (e) => {
167
+ const files = e.target.files;
168
+ if (files && files.length > 0) {
168
169
  const formData = new FormData();
169
- formData.append((option === null || option === void 0 ? void 0 : option["fileField"]) || "file", file);
170
+ if (option === null || option === void 0 ? void 0 : option.multiple) {
171
+ for (let i = 0; i < files.length; i++) {
172
+ formData.append("files[]", files[i]);
173
+ }
174
+ }
175
+ else {
176
+ formData.append((option === null || option === void 0 ? void 0 : option["fileField"]) || "file", files[0]);
177
+ }
170
178
  for (let key in option === null || option === void 0 ? void 0 : option["data"]) {
171
179
  formData.append(key, option["data"][key]);
172
180
  }
package/index.ts CHANGED
@@ -182,12 +182,20 @@ export class Cpzxrobot {
182
182
  const button = document.createElement("input");
183
183
  button.type = "file";
184
184
  button.style.display = "none";
185
+ button.multiple = option?.multiple || false;
185
186
  document.body.appendChild(button);
186
- button.onclick = async (e: Event) => {
187
- const file = (e.target as HTMLInputElement).files?.[0];
188
- if (file) {
187
+ button.click(); // 手动触发点击
188
+ button.onchange = async (e: Event) => {
189
+ const files = (e.target as HTMLInputElement).files;
190
+ if (files && files.length > 0) {
189
191
  const formData = new FormData();
190
- formData.append(option?.["fileField"] || "file", file);
192
+ if (option?.multiple) {
193
+ for (let i = 0; i < files.length; i++) {
194
+ formData.append("files[]", files[i]);
195
+ }
196
+ } else {
197
+ formData.append(option?.["fileField"] || "file", files[0]);
198
+ }
191
199
  for (let key in option?.["data"]) {
192
200
  formData.append(key, option!["data"][key]);
193
201
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.2.76",
3
+ "version": "1.2.77",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {