@cpzxrobot/sdk 1.2.64 → 1.2.66

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 CHANGED
@@ -202,6 +202,10 @@ export class DeviceGateway extends Object {
202
202
  return this.getFilter("ElectricMeter", ElectricMeterGateway);
203
203
  }
204
204
 
205
+ share(id: number){
206
+ this.context.shareDevice(id);
207
+ }
208
+
205
209
  private getFilter<T extends { id: number }>(
206
210
  type: string,
207
211
  cls: new (context: Cpzxrobot) => DeviceFilter<T>
@@ -154,6 +154,9 @@ class DeviceGateway extends Object {
154
154
  get electricMeter() {
155
155
  return this.getFilter("ElectricMeter", electricmeter_1.ElectricMeterGateway);
156
156
  }
157
+ share(id) {
158
+ this.context.shareDevice(id);
159
+ }
157
160
  getFilter(type, cls) {
158
161
  if (this.filters.has(type)) {
159
162
  return this.filters.get(type);
package/dist/index.js CHANGED
@@ -111,7 +111,22 @@ class Cpzxrobot {
111
111
  const instance = {
112
112
  get: async (url, config) => {
113
113
  if (config && config.params) {
114
- url += "?" + new URLSearchParams(config.params).toString();
114
+ const flattenParams = (params, prefix = '') => {
115
+ const result = {};
116
+ Object.keys(params).forEach(key => {
117
+ const value = params[key];
118
+ const fullKey = prefix ? `${prefix}[${key}]` : key;
119
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
120
+ Object.assign(result, flattenParams(value, fullKey));
121
+ }
122
+ else {
123
+ result[fullKey] = value.toString();
124
+ }
125
+ });
126
+ return result;
127
+ };
128
+ const flattened = flattenParams(config.params);
129
+ url += "?" + new URLSearchParams(flattened).toString();
115
130
  delete config.params;
116
131
  }
117
132
  const response = await fetchWithAuth(url, {
@@ -227,6 +242,8 @@ class Cpzxrobot {
227
242
  this.setError = window.miniapp.setError;
228
243
  // @ts-ignore
229
244
  this.setProgress = window.miniapp.setProgress;
245
+ // @ts-ignore
246
+ this.shareDevice = window.miniapp.shareDevice;
230
247
  }
231
248
  else if (domain == "appassets.androidplatform.net" || domain == "webc.cpzxrobot.com" ||
232
249
  this.isIosMiniApp(window.location)) {
@@ -266,6 +283,9 @@ class Cpzxrobot {
266
283
  this.vibrate = function (time) {
267
284
  return platform.callHandler("app.vibrate", time);
268
285
  };
286
+ this.shareDevice = function (deviceId) {
287
+ return platform.callHandler("app.shareDevice", deviceId);
288
+ };
269
289
  this.reloadGroup = function (group) {
270
290
  return platform.callHandler("app.reloadGroup", group);
271
291
  };
@@ -388,6 +408,9 @@ class Cpzxrobot {
388
408
  }
389
409
  });
390
410
  };
411
+ this.shareDevice = function (deviceId) {
412
+ return this.axios.get("/api/v1/device/share/" + deviceId);
413
+ };
391
414
  }
392
415
  }
393
416
  isIosMiniApp(location) {
package/index.ts CHANGED
@@ -20,7 +20,7 @@ import { LogsGateway } from "./logs_gateway";
20
20
  import { RobotGateway } from "./robot_gateway";
21
21
  import { QuotationGateway } from "./quotation_gateway";
22
22
  import { AiGateway } from "./ai_gateway";
23
- import { ConstructionGateway } from "./construction_gateway";
23
+ import { ConstructionGateway } from "./construction_gateway";
24
24
  import { SystemGateway } from "./system_gateway";
25
25
 
26
26
  export class Cpzxrobot {
@@ -51,6 +51,7 @@ export class Cpzxrobot {
51
51
  saveBlob!: (blob: Blob, filename: string) => Promise<void>;
52
52
  scanQrcode!: () => Promise<string>;
53
53
  vibrate!: (time?: number) => void;
54
+ shareDevice!: (deviceId: number) => Promise<void>;
54
55
  reloadGroup!: (key: string) => void;
55
56
  getGeo!: () => Promise<{
56
57
  lat: number;
@@ -119,7 +120,7 @@ export class Cpzxrobot {
119
120
  ...init,
120
121
  headers
121
122
  });
122
-
123
+
123
124
  if (!response.ok) {
124
125
  throw new Error(`HTTP error! status: ${response.status}`);
125
126
  }
@@ -129,7 +130,22 @@ export class Cpzxrobot {
129
130
  const instance = {
130
131
  get: async (url: string, config?: any) => {
131
132
  if (config && config.params) {
132
- url += "?" + new URLSearchParams(config.params).toString();
133
+ const flattenParams = (params: any, prefix = '') => {
134
+ const result: Record<string, string> = {};
135
+ Object.keys(params).forEach(key => {
136
+ const value = params[key];
137
+ const fullKey = prefix ? `${prefix}[${key}]` : key;
138
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
139
+ Object.assign(result, flattenParams(value, fullKey));
140
+ } else {
141
+ result[fullKey] = value.toString();
142
+ }
143
+ });
144
+ return result;
145
+ };
146
+
147
+ const flattened = flattenParams(config.params);
148
+ url += "?" + new URLSearchParams(flattened).toString();
133
149
  delete config.params;
134
150
  }
135
151
  const response = await fetchWithAuth(url, {
@@ -248,6 +264,8 @@ export class Cpzxrobot {
248
264
  this.setError = window.miniapp.setError;
249
265
  // @ts-ignore
250
266
  this.setProgress = window.miniapp.setProgress;
267
+ // @ts-ignore
268
+ this.shareDevice = window.miniapp.shareDevice;
251
269
  } else if (
252
270
  domain == "appassets.androidplatform.net" || domain == "webc.cpzxrobot.com" ||
253
271
  this.isIosMiniApp(window.location)
@@ -290,6 +308,9 @@ export class Cpzxrobot {
290
308
  this.vibrate = function (time?: number) {
291
309
  return platform.callHandler("app.vibrate", time);
292
310
  };
311
+ this.shareDevice = function (deviceId: number) {
312
+ return platform.callHandler("app.shareDevice", deviceId);
313
+ };
293
314
  this.reloadGroup = function (group: string) {
294
315
  return platform.callHandler("app.reloadGroup", group);
295
316
  };
@@ -416,6 +437,9 @@ export class Cpzxrobot {
416
437
  }
417
438
  });
418
439
  };
440
+ this.shareDevice = function (deviceId: number) {
441
+ return this.axios.get("/api/v1/device/share/" + deviceId);
442
+ };
419
443
  }
420
444
  }
421
445
  isIosMiniApp(location: Location): boolean {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.2.64",
3
+ "version": "1.2.66",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/types.d.ts CHANGED
@@ -363,6 +363,7 @@ class Cpzxrobot {
363
363
  vibrate: (time?: number) => void;
364
364
  reloadGroup: (key: string) => void;
365
365
  getGeo: () => Promise<{ lat: number; lng: number }>;
366
+ shareDevice: (deviceId: number) => Promise<void>;
366
367
  }
367
368
 
368
369
  declare global {