@cpzxrobot/sdk 1.0.6 → 1.0.8
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 +39 -2
- package/index.ts +4 -4
- package/package.json +1 -1
- package/types.d.ts +3 -2
package/dist/index.js
CHANGED
|
@@ -21,7 +21,6 @@ class Cpzxrobot {
|
|
|
21
21
|
this.mode = "dev";
|
|
22
22
|
this.auth = "";
|
|
23
23
|
this.token = "";
|
|
24
|
-
this.setTitle = () => { };
|
|
25
24
|
//获取当前浏览器的域名
|
|
26
25
|
this.ready = new Promise((resolve, reject) => {
|
|
27
26
|
this.resolveReady = resolve;
|
|
@@ -66,6 +65,15 @@ class Cpzxrobot {
|
|
|
66
65
|
this.axios = instance;
|
|
67
66
|
}
|
|
68
67
|
}
|
|
68
|
+
_saveBlobAsBase64(blob, filename) {
|
|
69
|
+
const reader = new FileReader();
|
|
70
|
+
reader.onload = function () {
|
|
71
|
+
const base64 = reader.result;
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
window.miniapp.saveBase64(base64, filename);
|
|
74
|
+
};
|
|
75
|
+
reader.readAsDataURL(blob);
|
|
76
|
+
}
|
|
69
77
|
//获取当前浏览器的域名
|
|
70
78
|
getDomain() {
|
|
71
79
|
const domain = window.location.hostname;
|
|
@@ -83,6 +91,9 @@ class Cpzxrobot {
|
|
|
83
91
|
this._jumpToMiniApp = window.miniapp.open;
|
|
84
92
|
// @ts-ignore
|
|
85
93
|
this.setTitle = window.miniapp.setTitle;
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
this.saveBase64 = window.miniapp.saveBase64;
|
|
96
|
+
this.saveBlob = this._saveBlobAsBase64;
|
|
86
97
|
}
|
|
87
98
|
else if (domain == "appassets.androidplatform.net" ||
|
|
88
99
|
this.isIosMiniApp(window.location)) {
|
|
@@ -100,7 +111,11 @@ class Cpzxrobot {
|
|
|
100
111
|
return platform.callHandler("app.openMiniapp", url);
|
|
101
112
|
};
|
|
102
113
|
this.setTitle = function (title) {
|
|
103
|
-
|
|
114
|
+
platform.callHandler("app.setTitle", title);
|
|
115
|
+
};
|
|
116
|
+
this.saveBlob = this._saveBlobAsBase64;
|
|
117
|
+
this.saveBase64 = function (base64, filename) {
|
|
118
|
+
return platform.callHandler("app.saveBase64", base64, filename);
|
|
104
119
|
};
|
|
105
120
|
this.axios = {
|
|
106
121
|
get: function (url, data) {
|
|
@@ -127,6 +142,28 @@ class Cpzxrobot {
|
|
|
127
142
|
this.setTitle = function (title) {
|
|
128
143
|
document.title = title;
|
|
129
144
|
};
|
|
145
|
+
this.saveBase64 = function (base64, filename) {
|
|
146
|
+
//decode base64 to blob
|
|
147
|
+
const byteCharacters = atob(base64);
|
|
148
|
+
const byteNumbers = new Array(byteCharacters.length);
|
|
149
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
150
|
+
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
151
|
+
}
|
|
152
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
153
|
+
const blob = new Blob([byteArray], {
|
|
154
|
+
type: "application/octet-stream",
|
|
155
|
+
});
|
|
156
|
+
this.saveBlob(blob, filename);
|
|
157
|
+
};
|
|
158
|
+
this.saveBlob = function (blob, filename) {
|
|
159
|
+
const url = URL.createObjectURL(blob);
|
|
160
|
+
const a = document.createElement("a");
|
|
161
|
+
a.href = url;
|
|
162
|
+
a.download = filename;
|
|
163
|
+
a.click();
|
|
164
|
+
URL.revokeObjectURL(url);
|
|
165
|
+
document.body.removeChild(a);
|
|
166
|
+
};
|
|
130
167
|
console.log("欢迎使用上海正诚物联网IOT系统,您当前是开发环境,请在平台获取开发用jwt key,并传入devAuth设置");
|
|
131
168
|
}
|
|
132
169
|
else {
|
package/index.ts
CHANGED
|
@@ -31,9 +31,9 @@ export class Cpzxrobot {
|
|
|
31
31
|
_getSelectedFarmFromMiniApp!: () => any;
|
|
32
32
|
_getSelectedUnitFromMiniApp!: () => any;
|
|
33
33
|
_jumpToMiniApp!: (url: string) => any;
|
|
34
|
-
setTitle:
|
|
35
|
-
saveBase64
|
|
36
|
-
saveBlob
|
|
34
|
+
setTitle!: (title: string) => void;
|
|
35
|
+
saveBase64!: (base64: string, filename: string) => void;
|
|
36
|
+
saveBlob!: (blob: Blob, filename: string) => void;
|
|
37
37
|
assistant: AssistantGateway;
|
|
38
38
|
energy: EnergyGateway;
|
|
39
39
|
camera: CameraGateway;
|
|
@@ -140,7 +140,7 @@ export class Cpzxrobot {
|
|
|
140
140
|
return platform.callHandler("app.openMiniapp", url);
|
|
141
141
|
};
|
|
142
142
|
this.setTitle = function (title: string) {
|
|
143
|
-
|
|
143
|
+
platform.callHandler("app.setTitle", title);
|
|
144
144
|
};
|
|
145
145
|
this.saveBlob = this._saveBlobAsBase64;
|
|
146
146
|
this.saveBase64 = function (base64: string, filename: string) {
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -132,8 +132,9 @@ export class Cpzxrobot {
|
|
|
132
132
|
axios: MyAxiosInstance;
|
|
133
133
|
_getSelectedFarmFromMiniApp: () => Promise<Factory>;
|
|
134
134
|
_getSelectedUnitFromMiniApp: () => Promise<Unit>;
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
setTitle: (title: string) => void;
|
|
136
|
+
saveBase64: (base64: string, filename: string) => void;
|
|
137
|
+
saveBlob: (blob: Blob, filename: string) => void;
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
declare global {
|