@cpzxrobot/sdk 1.2.10 → 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 +23 -17
  2. package/index.ts +46 -41
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -405,24 +405,30 @@ class Cpzxrobot {
405
405
  else {
406
406
  this.initAxios(baseURL);
407
407
  this.auth = auth;
408
- this.axios
409
- .post("/api/v1/user/auth", {
410
- appCode: this.appCode,
411
- auth: auth,
412
- })
413
- .then((res) => {
414
- if (res.data.Error) {
415
- throw res.data.Error;
416
- }
417
- else {
418
- this.token = "Bearer " + res.data.token;
419
- }
408
+ if (this.auth.startsWith("Bearer ")) {
409
+ this.token = auth;
420
410
  this.resolveReady(this.axios);
421
- })
422
- .catch((err) => {
423
- console.log("shzx ready caller reject", err);
424
- this.rejectReady(err);
425
- });
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
+ }
426
432
  }
427
433
  }
428
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,9 +432,9 @@ export class Cpzxrobot {
432
432
  window.location.href = "/login.html?error=" + res.data.Error;
433
433
  return;
434
434
  }
435
- if (res.data.token){
435
+ if (res.data.token) {
436
436
  this.token = "Bearer " + res.data.token;
437
- }else if (access_token.startsWith("Bearer ")){
437
+ } else if (access_token.startsWith("Bearer ")) {
438
438
  this.token = access_token;
439
439
  }
440
440
  localStorage.setItem("token", this.token);
@@ -450,23 +450,28 @@ export class Cpzxrobot {
450
450
  } else {
451
451
  this.initAxios(baseURL);
452
452
  this.auth = auth;
453
- this.axios
454
- .post("/api/v1/user/auth", {
455
- appCode: this.appCode,
456
- auth: auth,
457
- })
458
- .then((res) => {
459
- if (res.data.Error) {
460
- throw res.data.Error;
461
- } else {
462
- this.token = "Bearer " + res.data.token;
463
- }
464
- this.resolveReady(this.axios);
465
- })
466
- .catch((err) => {
467
- console.log("shzx ready caller reject", err);
468
- this.rejectReady(err);
469
- });
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
+ }
470
475
  }
471
476
  }
472
477
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {