@cpzxrobot/sdk 1.0.34 → 1.0.36

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 CHANGED
@@ -222,12 +222,41 @@ class Cpzxrobot {
222
222
  if (token) {
223
223
  this.token = token;
224
224
  this.initAxios("https://www.cpzxrobot.com/");
225
- this.resolveReady(this.axios);
225
+ this.axios.get("/api/v1/user/auth").then((res) => {
226
+ if (res.data.Error) {
227
+ window.location.href = "/login.html?error=" + res.data.Error;
228
+ return;
229
+ }
230
+ this.resolveReady(this.axios);
231
+ });
226
232
  return;
227
233
  }
228
234
  else {
229
- //jump to miniapp login page
230
- window.location.href = "/login.html";
235
+ //if url has access_token and app_code, use it
236
+ const url = new URL(window.location.href);
237
+ const access_token = url.searchParams.get("access_token");
238
+ const app_code = url.searchParams.get("app_code");
239
+ if (access_token && app_code) {
240
+ this.initAxios("https://www.cpzxrobot.com/");
241
+ this.axios
242
+ .post("/api/v1/user/auth", {
243
+ appCode: app_code,
244
+ auth: access_token,
245
+ })
246
+ .then((res) => {
247
+ if (res.data.Error) {
248
+ window.location.href = "/login.html?error=" + res.data.Error;
249
+ return;
250
+ }
251
+ this.token = "Bearer " + res.data.token;
252
+ this.resolveReady(this.axios);
253
+ });
254
+ return;
255
+ }
256
+ else {
257
+ //jump to miniapp login page
258
+ window.location.href = "/login.html";
259
+ }
231
260
  }
232
261
  }
233
262
  else {
@@ -33,6 +33,23 @@ class TransportGateway extends Object {
33
33
  get inputs() {
34
34
  return this.getDetail;
35
35
  },
36
+ //按料单获得对应的料塔
37
+ getDeviceByFodderld: (id) => {
38
+ return this.context.ready.then(() => {
39
+ return this.context.axios
40
+ .get("/api/v1/pigfarm/device/fodderTower/getDeviceByFodderld", {
41
+ params: {
42
+ fodderld: id,
43
+ },
44
+ })
45
+ .then((res) => {
46
+ if (res.data.code != 200) {
47
+ throw res.data.message;
48
+ }
49
+ return res.data.data;
50
+ });
51
+ });
52
+ },
36
53
  //获取设备打料数据 deperecated
37
54
  getDetail: (ids, date) => {
38
55
  return this.context.ready.then(() => {
package/index.ts CHANGED
@@ -257,11 +257,40 @@ export class Cpzxrobot {
257
257
  if (token) {
258
258
  this.token = token;
259
259
  this.initAxios("https://www.cpzxrobot.com/");
260
- this.resolveReady(this.axios);
260
+ this.axios.get("/api/v1/user/auth").then((res) => {
261
+ if (res.data.Error) {
262
+ window.location.href = "/login.html?error=" + res.data.Error;
263
+ return;
264
+ }
265
+ this.resolveReady(this.axios);
266
+ });
261
267
  return;
262
268
  } else {
263
- //jump to miniapp login page
264
- window.location.href = "/login.html";
269
+ //if url has access_token and app_code, use it
270
+ const url = new URL(window.location.href);
271
+ const access_token = url.searchParams.get("access_token");
272
+ const app_code = url.searchParams.get("app_code");
273
+ if (access_token && app_code) {
274
+ this.initAxios("https://www.cpzxrobot.com/");
275
+ this.axios
276
+ .post("/api/v1/user/auth", {
277
+ appCode: app_code,
278
+ auth: access_token,
279
+ })
280
+ .then((res) => {
281
+ if (res.data.Error) {
282
+ window.location.href = "/login.html?error=" + res.data.Error;
283
+ return;
284
+ }
285
+ this.token = "Bearer " + res.data.token;
286
+ this.resolveReady(this.axios);
287
+ });
288
+ return;
289
+ }else{
290
+ //jump to miniapp login page
291
+ window.location.href = "/login.html";
292
+ }
293
+
265
294
  }
266
295
  } else {
267
296
  this.initAxios(baseURL);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -80,6 +80,7 @@ baseURL: "/"
80
80
  | cpzxrobot().device.xxx | 获得设备的相关信息 |
81
81
  | cpzxrobot().camera.xxx | 获得摄像头的相关信息 |
82
82
  | cpzxrobot().factory.entry| 获得工厂的可显示动态信息 |
83
+ | cpzxrobot().transport.fodder.getDeviceByFodderld | 获得料单对应的设备 |
83
84
 
84
85
  ### 工厂信息接口
85
86
 
@@ -43,6 +43,23 @@ export class TransportGateway extends Object {
43
43
  get inputs() {
44
44
  return this.getDetail;
45
45
  },
46
+ //按料单获得对应的料塔
47
+ getDeviceByFodderld: (id: number): Promise<any> => {
48
+ return this.context.ready.then(() => {
49
+ return this.context.axios
50
+ .get("/api/v1/pigfarm/device/fodderTower/getDeviceByFodderld", {
51
+ params: {
52
+ fodderld: id,
53
+ },
54
+ })
55
+ .then((res) => {
56
+ if (res.data.code != 200) {
57
+ throw res.data.message;
58
+ }
59
+ return res.data.data;
60
+ });
61
+ });
62
+ },
46
63
  //获取设备打料数据 deperecated
47
64
  getDetail: (ids: Array<number>, date: string): Promise<any> => {
48
65
  return this.context.ready.then(() => {