@cpzxrobot/sdk 1.1.87 → 1.1.88
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 +24 -20
- package/index.ts +5 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -91,28 +91,32 @@ class Cpzxrobot {
|
|
|
91
91
|
instance.getAndPreview = instance.getAndSave;
|
|
92
92
|
// @ts-ignore
|
|
93
93
|
instance.upload = (url, option) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
//add a file button to the body
|
|
96
|
+
var button = document.createElement("input");
|
|
97
|
+
button.type = "file";
|
|
98
|
+
button.style.display = "none";
|
|
99
|
+
document.body.appendChild(button);
|
|
100
|
+
button.onclick = (e) => {
|
|
101
|
+
var _a;
|
|
102
|
+
var file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
103
|
+
if (file) {
|
|
104
|
+
const formData = new FormData();
|
|
105
|
+
formData.append((option === null || option === void 0 ? void 0 : option["fileField"]) || "file", file);
|
|
106
|
+
for (let key in option === null || option === void 0 ? void 0 : option["data"]) {
|
|
107
|
+
formData.append(key, option["data"][key]);
|
|
108
|
+
}
|
|
109
|
+
instance.post(url, formData).then((res) => {
|
|
110
|
+
button.remove();
|
|
111
|
+
resolve(res);
|
|
112
|
+
});
|
|
107
113
|
}
|
|
108
|
-
|
|
114
|
+
else {
|
|
109
115
|
button.remove();
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
+
resolve({ data: { Error: "没有选择文件" } });
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
});
|
|
116
120
|
};
|
|
117
121
|
// @ts-ignore
|
|
118
122
|
this.axios = instance;
|
package/index.ts
CHANGED
|
@@ -127,7 +127,8 @@ export class Cpzxrobot {
|
|
|
127
127
|
instance.upload = (url: string, option?: {
|
|
128
128
|
[key: string]: any;
|
|
129
129
|
}) => {
|
|
130
|
-
|
|
130
|
+
return new Promise<any>((resolve, reject)=>{
|
|
131
|
+
//add a file button to the body
|
|
131
132
|
var button = document.createElement("input");
|
|
132
133
|
button.type = "file";
|
|
133
134
|
button.style.display = "none";
|
|
@@ -142,11 +143,14 @@ export class Cpzxrobot {
|
|
|
142
143
|
}
|
|
143
144
|
instance.post(url, formData).then((res) => {
|
|
144
145
|
button.remove();
|
|
146
|
+
resolve(res);
|
|
145
147
|
});
|
|
146
148
|
} else {
|
|
147
149
|
button.remove();
|
|
150
|
+
resolve({data:{Error:"没有选择文件"}})
|
|
148
151
|
}
|
|
149
152
|
};
|
|
153
|
+
})
|
|
150
154
|
}
|
|
151
155
|
// @ts-ignore
|
|
152
156
|
this.axios = instance;
|