@cpzxrobot/sdk 1.2.37 → 1.2.39
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/device_gateway.ts +22 -15
- package/dist/device_gateway.js +4 -0
- package/dist/index.js +33 -15
- package/index.ts +36 -19
- package/package.json +1 -1
package/device_gateway.ts
CHANGED
|
@@ -33,7 +33,7 @@ class DeviceFault {
|
|
|
33
33
|
for (let i = 0; i < columns!.length; i++) {
|
|
34
34
|
const column = columns![i];
|
|
35
35
|
const value = values[i];
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
if (column === 'category') params.category = value;
|
|
38
38
|
else if (column === 'time') params.time = new Date(value);
|
|
39
39
|
else if (column === 'resolved') params.resolved = value === 'true';
|
|
@@ -41,7 +41,7 @@ class DeviceFault {
|
|
|
41
41
|
else if (column === 'value') params.value = value;
|
|
42
42
|
else if (column === 'message') params.message = value;
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
this.category = params.category;
|
|
46
46
|
this.time = params.time;
|
|
47
47
|
this.resolved = params.resolved;
|
|
@@ -268,6 +268,13 @@ export class DeviceGateway extends Object {
|
|
|
268
268
|
return this.normalFilter.getData(id, args);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
async info(
|
|
272
|
+
id: number,
|
|
273
|
+
) {
|
|
274
|
+
let axios = await this.context.ready;
|
|
275
|
+
return axios.get(`/api/v1/device/info/${id}`);
|
|
276
|
+
}
|
|
277
|
+
|
|
271
278
|
async validate(serialNumbers: string[], type: string = "pywl") {
|
|
272
279
|
let axios = await this.context.ready;
|
|
273
280
|
return axios.post(`/api/v2/device/validateSerialNumber`, {
|
|
@@ -288,16 +295,16 @@ export class DeviceGateway extends Object {
|
|
|
288
295
|
const json = response.data;
|
|
289
296
|
var faultsData = json.faults as string;
|
|
290
297
|
|
|
291
|
-
// #group,false,false,true,true,false,false,true,true,true,true,true,true
|
|
292
|
-
// #datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,boolean,string,string,string,string,string,string
|
|
293
|
-
// #default,last,,,,,,,,,,,
|
|
294
|
-
// ,result,table,_start,_stop,_time,_value,DeviceId,_field,_measurement,category,field,status
|
|
295
|
-
// ,,0,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:27:00Z,false,004a05c1-7b5b-471c-ab68-f583039ddcfe,bool_value,DeviceStatus,离线报警,online,fault
|
|
296
|
-
// ,,0,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:30:00Z,true,004a05c1-7b5b-471c-ab68-f583039ddcfe,bool_value,DeviceStatus,离线报警,online,fault
|
|
297
|
-
// ,,1,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:27:00Z,false,004a05c1-7b5b-471c-ab68-f583039ddcfe,repeated,DeviceStatus,离线报警,online,fault
|
|
298
|
-
// ,,1,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:30:00Z,false,004a05c1-7b5b-471c-ab68-f583039ddcfe,repeated,DeviceStatus,离线报警,online,fault
|
|
299
|
-
// ,,2,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:27:00Z,false,004a05c1-7b5b-471c-ab68-f583039ddcfe,resolved,DeviceStatus,离线报警,online,fault
|
|
300
|
-
// ,,2,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:30:00Z,true,004a05c1-7b5b-471c-ab68-f583039ddcfe,resolved,DeviceStatus,离线报警,online,fault
|
|
298
|
+
// #group,false,false,true,true,false,false,true,true,true,true,true,true
|
|
299
|
+
// #datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,boolean,string,string,string,string,string,string
|
|
300
|
+
// #default,last,,,,,,,,,,,
|
|
301
|
+
// ,result,table,_start,_stop,_time,_value,DeviceId,_field,_measurement,category,field,status
|
|
302
|
+
// ,,0,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:27:00Z,false,004a05c1-7b5b-471c-ab68-f583039ddcfe,bool_value,DeviceStatus,离线报警,online,fault
|
|
303
|
+
// ,,0,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:30:00Z,true,004a05c1-7b5b-471c-ab68-f583039ddcfe,bool_value,DeviceStatus,离线报警,online,fault
|
|
304
|
+
// ,,1,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:27:00Z,false,004a05c1-7b5b-471c-ab68-f583039ddcfe,repeated,DeviceStatus,离线报警,online,fault
|
|
305
|
+
// ,,1,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:30:00Z,false,004a05c1-7b5b-471c-ab68-f583039ddcfe,repeated,DeviceStatus,离线报警,online,fault
|
|
306
|
+
// ,,2,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:27:00Z,false,004a05c1-7b5b-471c-ab68-f583039ddcfe,resolved,DeviceStatus,离线报警,online,fault
|
|
307
|
+
// ,,2,2025-04-20T22:07:43.623582865Z,2025-04-21T04:07:43.623582865Z,2025-04-21T00:30:00Z,true,004a05c1-7b5b-471c-ab68-f583039ddcfe,resolved,DeviceStatus,离线报警,online,fault
|
|
301
308
|
|
|
302
309
|
faultsData = faultsData.replace(/\r/g, "");
|
|
303
310
|
var arr = faultsData.split("\n");
|
|
@@ -320,7 +327,7 @@ export class DeviceGateway extends Object {
|
|
|
320
327
|
|
|
321
328
|
}
|
|
322
329
|
|
|
323
|
-
|
|
330
|
+
|
|
324
331
|
// 报告设备问题
|
|
325
332
|
report(id: number, status: number, description: string): Promise<any> {
|
|
326
333
|
return this.context.ready.then(() => {
|
|
@@ -340,7 +347,7 @@ export class DeviceGateway extends Object {
|
|
|
340
347
|
get ctrl() {
|
|
341
348
|
return {
|
|
342
349
|
// 获取设备控制参数
|
|
343
|
-
get: (deviceId: number,type: string, no: any
|
|
350
|
+
get: (deviceId: number, type: string, no: any): Promise<any> => {
|
|
344
351
|
return this.context.ready.then(() => {
|
|
345
352
|
return this.context.axios.get(`/api/v2/device/ctrl/${deviceId}/${type}/${no}`)
|
|
346
353
|
.then((res) => {
|
|
@@ -353,7 +360,7 @@ export class DeviceGateway extends Object {
|
|
|
353
360
|
},
|
|
354
361
|
|
|
355
362
|
// 配置设备控制参数
|
|
356
|
-
set: (deviceId: number,type: string, no: any,params: any): Promise<any> => {
|
|
363
|
+
set: (deviceId: number, type: string, no: any, params: any): Promise<any> => {
|
|
357
364
|
return this.context.ready.then(() => {
|
|
358
365
|
return this.context.axios.post(`/api/v2/device/ctrl/${deviceId}/${type}/${no}`, params)
|
|
359
366
|
.then((res) => {
|
package/dist/device_gateway.js
CHANGED
|
@@ -188,6 +188,10 @@ class DeviceGateway extends Object {
|
|
|
188
188
|
}) {
|
|
189
189
|
return this.normalFilter.getData(id, args);
|
|
190
190
|
}
|
|
191
|
+
async info(id) {
|
|
192
|
+
let axios = await this.context.ready;
|
|
193
|
+
return axios.get(`/api/v1/device/info/${id}`);
|
|
194
|
+
}
|
|
191
195
|
async validate(serialNumbers, type = "pywl") {
|
|
192
196
|
let axios = await this.context.ready;
|
|
193
197
|
return axios.post(`/api/v2/device/validateSerialNumber`, {
|
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 = async () => {
|
|
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 = async () => {
|
|
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) => {
|