@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.
- package/dist/index.js +23 -17
- package/index.ts +46 -41
- 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.
|
|
409
|
-
.
|
|
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
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
-
|
|
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,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.
|
|
454
|
-
.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
|