@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.
- package/dist/index.js +29 -18
- package/index.ts +49 -40
- 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
|
-
|
|
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.
|
|
404
|
-
.
|
|
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
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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(
|
|
152
|
-
}
|
|
153
|
-
}
|
|
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
|
-
|
|
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.
|
|
450
|
-
.
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
|