@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.
- package/dist/index.js +13 -5
- package/index.ts +12 -4
- 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.
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
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
|
-
|
|
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.
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
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
|
}
|