@cpzxrobot/sdk 1.0.28 → 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.
Files changed (3) hide show
  1. package/dist/index.js +42 -23
  2. package/index.ts +42 -26
  3. package/package.json +1 -1
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
  // 列出所有的本地开发域名
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.28",
3
+ "version": "1.0.29",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {