@cpzxrobot/sdk 1.0.27 → 1.0.29

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_filter.ts CHANGED
@@ -112,13 +112,28 @@ export abstract class DeviceFilter<T extends { id: number }> {
112
112
  type: "diffPerDay", // diffPerDay, sumPerDay, latest
113
113
  }
114
114
  ) {
115
- if (!args.stop) {
116
- args.stop = this.formateDateToYYYYMMDD(new Date());
115
+ if(!args.period || args.period.endsWith("d")) {
116
+ if (!args.stop) {
117
+ args.stop = this.formateDateToYYYYMMDD(new Date());
118
+ }
119
+ if (!args.start) {
120
+ const sevenDaysAgo = new Date();
121
+ sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
122
+ args.start = this.formateDateToYYYYMMDD(sevenDaysAgo);
123
+ }
124
+ }else if(args.period.endsWith("h")) {
125
+ if (!args.stop) {
126
+ args.stop = new Date().toISOString();
127
+ }
128
+ if (!args.start) {
129
+ const oneDayAgo = new Date();
130
+ oneDayAgo.setDate(oneDayAgo.getDate() - 1);
131
+ args.start = oneDayAgo.toISOString();
132
+ }
117
133
  }
118
- if (!args.start) {
119
- const sevenDaysAgo = new Date();
120
- sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
121
- args.start = this.formateDateToYYYYMMDD(sevenDaysAgo);
134
+
135
+ if(!args.type) {
136
+ args.type = "last";
122
137
  }
123
138
 
124
139
  return this.context.ready
@@ -91,13 +91,28 @@ class DeviceFilter {
91
91
  stop: "",
92
92
  type: "diffPerDay", // diffPerDay, sumPerDay, latest
93
93
  }) {
94
- if (!args.stop) {
95
- args.stop = this.formateDateToYYYYMMDD(new Date());
94
+ if (!args.period || args.period.endsWith("d")) {
95
+ if (!args.stop) {
96
+ args.stop = this.formateDateToYYYYMMDD(new Date());
97
+ }
98
+ if (!args.start) {
99
+ const sevenDaysAgo = new Date();
100
+ sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
101
+ args.start = this.formateDateToYYYYMMDD(sevenDaysAgo);
102
+ }
103
+ }
104
+ else if (args.period.endsWith("h")) {
105
+ if (!args.stop) {
106
+ args.stop = new Date().toISOString();
107
+ }
108
+ if (!args.start) {
109
+ const oneDayAgo = new Date();
110
+ oneDayAgo.setDate(oneDayAgo.getDate() - 1);
111
+ args.start = oneDayAgo.toISOString();
112
+ }
96
113
  }
97
- if (!args.start) {
98
- const sevenDaysAgo = new Date();
99
- sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
100
- args.start = this.formateDateToYYYYMMDD(sevenDaysAgo);
114
+ if (!args.type) {
115
+ args.type = "last";
101
116
  }
102
117
  return this.context.ready
103
118
  .then(() => {
@@ -46,5 +46,11 @@ class FactoryGateway extends Object {
46
46
  const response = await axios.get(`/api/v1/factory/${data.id}/organizaion`, data);
47
47
  return response.data;
48
48
  }
49
+ //支持以下三个name:'capacity'(规模),'used_capacity'(存栏量),'workshop_count'(栋舍/车间数量),'manager'(负责人)
50
+ async entry(factory, name) {
51
+ var axios = await this.context.ready;
52
+ const response = await axios.get(`/api/v1/factory/${factory.id}/entry/${name}`);
53
+ return response.data;
54
+ }
49
55
  }
50
56
  exports.FactoryGateway = FactoryGateway;
package/dist/index.js CHANGED
@@ -148,8 +148,14 @@ class Cpzxrobot {
148
148
  });
149
149
  }
150
150
  }
151
- else if (this.isLocalDomain(domain)) {
152
- this.mode = "dev";
151
+ else {
152
+ if (this.isLocalDomain(domain)) {
153
+ this.mode = "dev";
154
+ console.log("欢迎使用上海正诚物联网IOT系统,您当前是开发环境,请在平台获取开发用jwt key,并传入devAuth设置");
155
+ }
156
+ else {
157
+ this.mode = "miniapp_in_web";
158
+ }
153
159
  this.setTitle = function (title) {
154
160
  document.title = title;
155
161
  };
@@ -175,10 +181,6 @@ class Cpzxrobot {
175
181
  URL.revokeObjectURL(url);
176
182
  document.body.removeChild(a);
177
183
  };
178
- console.log("欢迎使用上海正诚物联网IOT系统,您当前是开发环境,请在平台获取开发用jwt key,并传入devAuth设置");
179
- }
180
- else {
181
- this.mode = "miniapp_in_web";
182
184
  }
183
185
  }
184
186
  isIosMiniApp(location) {
@@ -211,26 +213,43 @@ class Cpzxrobot {
211
213
  });
212
214
  return;
213
215
  }
214
- this.initAxios(baseURL);
215
- this.auth = auth;
216
- this.axios
217
- .post("/api/v1/user/auth", {
218
- appCode: this.appCode,
219
- auth: auth,
220
- })
221
- .then((res) => {
222
- if (res.data.Error) {
223
- throw res.data.Error;
216
+ else if (this.mode === "miniapp_in_web") {
217
+ //if url has token
218
+ const url = new URL(window.location.href);
219
+ const token = url.searchParams.get("token");
220
+ if (token) {
221
+ this.token = "Bearer " + token;
222
+ this.initAxios(baseURL);
223
+ this.resolveReady(this.axios);
224
+ return;
224
225
  }
225
226
  else {
226
- this.token = "Bearer " + res.data.token;
227
+ //jump to miniapp login page
228
+ window.location.href = "https:///login";
227
229
  }
228
- this.resolveReady(this.axios);
229
- })
230
- .catch((err) => {
231
- console.log("shzx ready caller reject", err);
232
- this.rejectReady(err);
233
- });
230
+ }
231
+ else {
232
+ this.initAxios(baseURL);
233
+ this.auth = auth;
234
+ this.axios
235
+ .post("/api/v1/user/auth", {
236
+ appCode: this.appCode,
237
+ auth: auth,
238
+ })
239
+ .then((res) => {
240
+ if (res.data.Error) {
241
+ throw res.data.Error;
242
+ }
243
+ else {
244
+ this.token = "Bearer " + res.data.token;
245
+ }
246
+ this.resolveReady(this.axios);
247
+ })
248
+ .catch((err) => {
249
+ console.log("shzx ready caller reject", err);
250
+ this.rejectReady(err);
251
+ });
252
+ }
234
253
  }
235
254
  isLocalDomain(domain) {
236
255
  // 列出所有的本地开发域名
@@ -51,4 +51,11 @@ export class FactoryGateway extends Object {
51
51
  const response = await axios.get(`/api/v1/factory/${data.id}/organizaion`, data);
52
52
  return response.data;
53
53
  }
54
+
55
+ //支持以下三个name:'capacity'(规模),'used_capacity'(存栏量),'workshop_count'(栋舍/车间数量),'manager'(负责人)
56
+ async entry(factory:Factory,name:string): Promise<any> {
57
+ var axios = await this.context.ready;
58
+ const response = await axios.get(`/api/v1/factory/${factory.id}/entry/${name}`);
59
+ return response.data;
60
+ }
54
61
  }
package/index.ts CHANGED
@@ -179,8 +179,15 @@ export class Cpzxrobot {
179
179
  }, 1500);
180
180
  });
181
181
  }
182
- } else if (this.isLocalDomain(domain)) {
183
- this.mode = "dev";
182
+ } else {
183
+ if (this.isLocalDomain(domain)) {
184
+ this.mode = "dev";
185
+ console.log(
186
+ "欢迎使用上海正诚物联网IOT系统,您当前是开发环境,请在平台获取开发用jwt key,并传入devAuth设置"
187
+ );
188
+ } else {
189
+ this.mode = "miniapp_in_web";
190
+ }
184
191
  this.setTitle = function (title: string) {
185
192
  document.title = title;
186
193
  };
@@ -206,11 +213,6 @@ export class Cpzxrobot {
206
213
  URL.revokeObjectURL(url);
207
214
  document.body.removeChild(a);
208
215
  };
209
- console.log(
210
- "欢迎使用上海正诚物联网IOT系统,您当前是开发环境,请在平台获取开发用jwt key,并传入devAuth设置"
211
- );
212
- } else {
213
- this.mode = "miniapp_in_web";
214
216
  }
215
217
  }
216
218
  isIosMiniApp(location: Location): boolean {
@@ -246,26 +248,40 @@ export class Cpzxrobot {
246
248
  this.resolveReady(this.axios);
247
249
  });
248
250
  return;
249
- }
250
- this.initAxios(baseURL);
251
- this.auth = auth;
252
- this.axios
253
- .post("/api/v1/user/auth", {
254
- appCode: this.appCode,
255
- auth: auth,
256
- })
257
- .then((res) => {
258
- if (res.data.Error) {
259
- throw res.data.Error;
260
- } else {
261
- this.token = "Bearer " + res.data.token;
262
- }
251
+ } else if (this.mode === "miniapp_in_web") {
252
+ //if url has token
253
+ const url = new URL(window.location.href);
254
+ const token = url.searchParams.get("token");
255
+ if (token) {
256
+ this.token = "Bearer " + token;
257
+ this.initAxios(baseURL);
263
258
  this.resolveReady(this.axios);
264
- })
265
- .catch((err) => {
266
- console.log("shzx ready caller reject", err);
267
- this.rejectReady(err);
268
- });
259
+ return;
260
+ } else {
261
+ //jump to miniapp login page
262
+ window.location.href = "https:///login";
263
+ }
264
+ } else {
265
+ this.initAxios(baseURL);
266
+ this.auth = auth;
267
+ this.axios
268
+ .post("/api/v1/user/auth", {
269
+ appCode: this.appCode,
270
+ auth: auth,
271
+ })
272
+ .then((res) => {
273
+ if (res.data.Error) {
274
+ throw res.data.Error;
275
+ } else {
276
+ this.token = "Bearer " + res.data.token;
277
+ }
278
+ this.resolveReady(this.axios);
279
+ })
280
+ .catch((err) => {
281
+ console.log("shzx ready caller reject", err);
282
+ this.rejectReady(err);
283
+ });
284
+ }
269
285
  }
270
286
 
271
287
  isLocalDomain(domain: string): boolean {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -79,6 +79,7 @@ baseURL: "/"
79
79
  | cpzxrobot().device.feedTower.list | 获得料塔设备的列表 |
80
80
  | cpzxrobot().device.xxx | 获得设备的相关信息 |
81
81
  | cpzxrobot().camera.xxx | 获得摄像头的相关信息 |
82
+ | cpzxrobot().factory.entry| 获得工厂的可显示动态信息 |
82
83
 
83
84
  ### 工厂信息接口
84
85