@cpzxrobot/sdk 1.2.36 → 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 +34 -18
- package/index.ts +37 -22
- 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() {
|
|
@@ -208,9 +215,7 @@ class Cpzxrobot {
|
|
|
208
215
|
this.setTitle = function (title) {
|
|
209
216
|
platform.callHandler("app.setTitle", title);
|
|
210
217
|
};
|
|
211
|
-
this.saveBlob =
|
|
212
|
-
return platform.callHandler("app.saveBlob", blob, filename);
|
|
213
|
-
};
|
|
218
|
+
this.saveBlob = this._saveBlobAsBase64;
|
|
214
219
|
this.saveBase64 = function (base64, filename) {
|
|
215
220
|
return platform.callHandler("app.saveBase64", base64, filename);
|
|
216
221
|
};
|
|
@@ -296,16 +301,27 @@ class Cpzxrobot {
|
|
|
296
301
|
const blob = new Blob([byteArray], {
|
|
297
302
|
type: "application/octet-stream",
|
|
298
303
|
});
|
|
299
|
-
this.saveBlob(blob, filename);
|
|
304
|
+
return this.saveBlob(blob, filename);
|
|
300
305
|
};
|
|
301
306
|
this.saveBlob = function (blob, filename) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
+
});
|
|
309
325
|
};
|
|
310
326
|
this.getGeo = async function () {
|
|
311
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
|
//获取当前浏览器的域名
|
|
@@ -252,9 +259,7 @@ export class Cpzxrobot {
|
|
|
252
259
|
this.setTitle = function (title: string) {
|
|
253
260
|
platform.callHandler("app.setTitle", title);
|
|
254
261
|
};
|
|
255
|
-
this.saveBlob =
|
|
256
|
-
return platform.callHandler("app.saveBlob", blob, filename);
|
|
257
|
-
};
|
|
262
|
+
this.saveBlob = this._saveBlobAsBase64;
|
|
258
263
|
this.saveBase64 = function (base64: string, filename: string) {
|
|
259
264
|
return platform.callHandler("app.saveBase64", base64, filename);
|
|
260
265
|
};
|
|
@@ -343,16 +348,26 @@ export class Cpzxrobot {
|
|
|
343
348
|
const blob = new Blob([byteArray], {
|
|
344
349
|
type: "application/octet-stream",
|
|
345
350
|
});
|
|
346
|
-
this.saveBlob(blob, filename);
|
|
351
|
+
return this.saveBlob(blob, filename);
|
|
347
352
|
};
|
|
348
|
-
this.saveBlob = function (blob: Blob, filename: string) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
+
});
|
|
356
371
|
};
|
|
357
372
|
this.getGeo = async function () {
|
|
358
373
|
return new Promise((resolve, reject) => {
|