@cpzxrobot/sdk 1.2.9 → 1.2.11

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 +29 -18
  2. package/index.ts +49 -40
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -385,7 +385,12 @@ class Cpzxrobot {
385
385
  window.location.href = "/login.html?error=" + res.data.Error;
386
386
  return;
387
387
  }
388
- this.token = "Bearer " + res.data.token;
388
+ if (res.data.token) {
389
+ this.token = "Bearer " + res.data.token;
390
+ }
391
+ else if (access_token.startsWith("Bearer ")) {
392
+ this.token = access_token;
393
+ }
389
394
  localStorage.setItem("token", this.token);
390
395
  this.resolveReady(this.axios);
391
396
  });
@@ -400,24 +405,30 @@ class Cpzxrobot {
400
405
  else {
401
406
  this.initAxios(baseURL);
402
407
  this.auth = auth;
403
- this.axios
404
- .post("/api/v1/user/auth", {
405
- appCode: this.appCode,
406
- auth: auth,
407
- })
408
- .then((res) => {
409
- if (res.data.Error) {
410
- throw res.data.Error;
411
- }
412
- else {
413
- this.token = "Bearer " + res.data.token;
414
- }
408
+ if (this.auth.startsWith("Bearer ")) {
409
+ this.token = auth;
415
410
  this.resolveReady(this.axios);
416
- })
417
- .catch((err) => {
418
- console.log("shzx ready caller reject", err);
419
- this.rejectReady(err);
420
- });
411
+ }
412
+ else {
413
+ this.axios
414
+ .post("/api/v1/user/auth", {
415
+ appCode: this.appCode,
416
+ auth: auth,
417
+ })
418
+ .then((res) => {
419
+ if (res.data.Error) {
420
+ throw res.data.Error;
421
+ }
422
+ else {
423
+ this.token = "Bearer " + res.data.token;
424
+ }
425
+ this.resolveReady(this.axios);
426
+ })
427
+ .catch((err) => {
428
+ console.log("shzx ready caller reject", err);
429
+ this.rejectReady(err);
430
+ });
431
+ }
421
432
  }
422
433
  }
423
434
  isLocalDomain(domain) {
package/index.ts CHANGED
@@ -132,29 +132,29 @@ export class Cpzxrobot {
132
132
  instance.upload = (url: string, option?: {
133
133
  [key: string]: any;
134
134
  }) => {
135
- return new Promise<any>((resolve, reject)=>{
135
+ return new Promise<any>((resolve, reject) => {
136
136
  //add a file button to the body
137
- var button = document.createElement("input");
138
- button.type = "file";
139
- button.style.display = "none";
140
- document.body.appendChild(button);
141
- button.onclick = (e: Event) => {
142
- var file = (e.target as HTMLInputElement).files?.[0];
143
- if (file) {
144
- const formData = new FormData();
145
- formData.append(option?.["fileField"] || "file", file);
146
- for (let key in option?.["data"]) {
147
- formData.append(key, option!["data"][key]);
148
- }
149
- instance.post(url, formData).then((res) => {
137
+ var button = document.createElement("input");
138
+ button.type = "file";
139
+ button.style.display = "none";
140
+ document.body.appendChild(button);
141
+ button.onclick = (e: Event) => {
142
+ var file = (e.target as HTMLInputElement).files?.[0];
143
+ if (file) {
144
+ const formData = new FormData();
145
+ formData.append(option?.["fileField"] || "file", file);
146
+ for (let key in option?.["data"]) {
147
+ formData.append(key, option!["data"][key]);
148
+ }
149
+ instance.post(url, formData).then((res) => {
150
+ button.remove();
151
+ resolve(res);
152
+ });
153
+ } else {
150
154
  button.remove();
151
- resolve(res);
152
- });
153
- } else {
154
- button.remove();
155
- resolve({data:{Error:"没有选择文件"}})
156
- }
157
- };
155
+ resolve({ data: { Error: "没有选择文件" } })
156
+ }
157
+ };
158
158
  })
159
159
  }
160
160
  // @ts-ignore
@@ -197,7 +197,7 @@ export class Cpzxrobot {
197
197
  // @ts-ignore
198
198
  this.vibrate = window.miniapp.vibrate;
199
199
  // @ts-ignore
200
- this.reloadGroup= window.miniapp.reloadGroup;
200
+ this.reloadGroup = window.miniapp.reloadGroup;
201
201
  this.saveBlob = this._saveBlobAsBase64;
202
202
  // @ts-ignore
203
203
  this.getGeo = window.miniapp.getGeo;
@@ -432,7 +432,11 @@ export class Cpzxrobot {
432
432
  window.location.href = "/login.html?error=" + res.data.Error;
433
433
  return;
434
434
  }
435
- this.token = "Bearer " + res.data.token;
435
+ if (res.data.token) {
436
+ this.token = "Bearer " + res.data.token;
437
+ } else if (access_token.startsWith("Bearer ")) {
438
+ this.token = access_token;
439
+ }
436
440
  localStorage.setItem("token", this.token);
437
441
  this.resolveReady(this.axios);
438
442
  });
@@ -446,23 +450,28 @@ export class Cpzxrobot {
446
450
  } else {
447
451
  this.initAxios(baseURL);
448
452
  this.auth = auth;
449
- this.axios
450
- .post("/api/v1/user/auth", {
451
- appCode: this.appCode,
452
- auth: auth,
453
- })
454
- .then((res) => {
455
- if (res.data.Error) {
456
- throw res.data.Error;
457
- } else {
458
- this.token = "Bearer " + res.data.token;
459
- }
460
- this.resolveReady(this.axios);
461
- })
462
- .catch((err) => {
463
- console.log("shzx ready caller reject", err);
464
- this.rejectReady(err);
465
- });
453
+ if (this.auth.startsWith("Bearer ")) {
454
+ this.token = auth;
455
+ this.resolveReady(this.axios);
456
+ } else {
457
+ this.axios
458
+ .post("/api/v1/user/auth", {
459
+ appCode: this.appCode,
460
+ auth: auth,
461
+ })
462
+ .then((res) => {
463
+ if (res.data.Error) {
464
+ throw res.data.Error;
465
+ } else {
466
+ this.token = "Bearer " + res.data.token;
467
+ }
468
+ this.resolveReady(this.axios);
469
+ })
470
+ .catch((err) => {
471
+ console.log("shzx ready caller reject", err);
472
+ this.rejectReady(err);
473
+ });
474
+ }
466
475
  }
467
476
  }
468
477
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {