@cpzxrobot/sdk 1.2.37 → 1.2.38
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 +33 -15
- package/index.ts +36 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -131,14 +131,21 @@ class Cpzxrobot {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
_saveBlobAsBase64(blob, filename) {
|
|
134
|
-
const reader = new FileReader();
|
|
135
134
|
var that = this;
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
const reader = new FileReader();
|
|
137
|
+
reader.readAsDataURL(blob);
|
|
138
|
+
reader.onloadend = () => {
|
|
139
|
+
// @ts-ignoreconst reader = new FileReader();
|
|
140
|
+
const base64 = reader.result;
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
await that.saveBase64(base64, filename);
|
|
143
|
+
resolve();
|
|
144
|
+
};
|
|
145
|
+
reader.onerror = (err) => {
|
|
146
|
+
reject(err);
|
|
147
|
+
};
|
|
148
|
+
});
|
|
142
149
|
}
|
|
143
150
|
//获取当前浏览器的域名
|
|
144
151
|
getDomain() {
|
|
@@ -294,16 +301,27 @@ class Cpzxrobot {
|
|
|
294
301
|
const blob = new Blob([byteArray], {
|
|
295
302
|
type: "application/octet-stream",
|
|
296
303
|
});
|
|
297
|
-
this.saveBlob(blob, filename);
|
|
304
|
+
return this.saveBlob(blob, filename);
|
|
298
305
|
};
|
|
299
306
|
this.saveBlob = function (blob, filename) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
+
return new Promise((resolve, reject) => {
|
|
308
|
+
try {
|
|
309
|
+
const url = URL.createObjectURL(blob);
|
|
310
|
+
const a = document.createElement("a");
|
|
311
|
+
a.href = url;
|
|
312
|
+
a.download = filename;
|
|
313
|
+
document.body.appendChild(a);
|
|
314
|
+
a.click();
|
|
315
|
+
setTimeout(() => {
|
|
316
|
+
URL.revokeObjectURL(url);
|
|
317
|
+
document.body.removeChild(a);
|
|
318
|
+
resolve();
|
|
319
|
+
}, 0);
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
reject(error);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
307
325
|
};
|
|
308
326
|
this.getGeo = async function () {
|
|
309
327
|
return new Promise((resolve, reject) => {
|
package/index.ts
CHANGED
|
@@ -46,8 +46,8 @@ export class Cpzxrobot {
|
|
|
46
46
|
_getSelectedUnitFromMiniApp!: () => any;
|
|
47
47
|
_jumpToMiniApp!: (url: string) => any;
|
|
48
48
|
setTitle!: (title: string) => void;
|
|
49
|
-
saveBase64!: (base64: string, filename: string) => void
|
|
50
|
-
saveBlob!: (blob: Blob, filename: string) => void
|
|
49
|
+
saveBase64!: (base64: string, filename: string) => Promise<void>;
|
|
50
|
+
saveBlob!: (blob: Blob, filename: string) => Promise<void>;
|
|
51
51
|
scanQrcode!: () => Promise<string>;
|
|
52
52
|
vibrate!: (time?: number) => void;
|
|
53
53
|
reloadGroup!: (key: string) => void;
|
|
@@ -170,15 +170,22 @@ export class Cpzxrobot {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
_saveBlobAsBase64(blob: Blob, filename: string) {
|
|
174
|
-
const reader = new FileReader();
|
|
173
|
+
_saveBlobAsBase64(blob: Blob, filename: string): Promise<void> {
|
|
175
174
|
var that = this;
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
175
|
+
return new Promise<void>((resolve, reject) => {
|
|
176
|
+
const reader = new FileReader();
|
|
177
|
+
reader.readAsDataURL(blob);
|
|
178
|
+
reader.onloadend = () => {
|
|
179
|
+
// @ts-ignoreconst reader = new FileReader();
|
|
180
|
+
const base64 = reader.result as string;
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
await that.saveBase64(base64, filename);
|
|
183
|
+
resolve();
|
|
184
|
+
};
|
|
185
|
+
reader.onerror = (err) => {
|
|
186
|
+
reject(err);
|
|
187
|
+
};
|
|
188
|
+
});
|
|
182
189
|
}
|
|
183
190
|
|
|
184
191
|
//获取当前浏览器的域名
|
|
@@ -341,16 +348,26 @@ export class Cpzxrobot {
|
|
|
341
348
|
const blob = new Blob([byteArray], {
|
|
342
349
|
type: "application/octet-stream",
|
|
343
350
|
});
|
|
344
|
-
this.saveBlob(blob, filename);
|
|
351
|
+
return this.saveBlob(blob, filename);
|
|
345
352
|
};
|
|
346
|
-
this.saveBlob = function (blob: Blob, filename: string) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
353
|
+
this.saveBlob = function (blob: Blob, filename: string): Promise<void> {
|
|
354
|
+
return new Promise((resolve, reject) => {
|
|
355
|
+
try {
|
|
356
|
+
const url = URL.createObjectURL(blob);
|
|
357
|
+
const a = document.createElement("a");
|
|
358
|
+
a.href = url;
|
|
359
|
+
a.download = filename;
|
|
360
|
+
document.body.appendChild(a);
|
|
361
|
+
a.click();
|
|
362
|
+
setTimeout(() => {
|
|
363
|
+
URL.revokeObjectURL(url);
|
|
364
|
+
document.body.removeChild(a);
|
|
365
|
+
resolve();
|
|
366
|
+
}, 0);
|
|
367
|
+
} catch (error) {
|
|
368
|
+
reject(error);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
354
371
|
};
|
|
355
372
|
this.getGeo = async function () {
|
|
356
373
|
return new Promise((resolve, reject) => {
|