Skip to content

Commit

Permalink
Merge pull request #25 from GuoXiCheng/dev-h
Browse files Browse the repository at this point in the history
update wx-request
  • Loading branch information
GuoXiCheng authored Dec 3, 2023
2 parents aebba2c + 5982da1 commit 4f1ae11
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiny-crud",
"version": "1.0.13",
"version": "1.0.14",
"description": "",
"main": "dist/bundle.cjs.js",
"module": "dist/bundle.esm.js",
Expand Down
2 changes: 2 additions & 0 deletions src/request-lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface WxRequestOptions {
url: string;
method: 'GET' | 'POST';
header?: object;
success: (res: {data: string | Object | ArrayBuffer, statusCode: number}) => void;
fail: (errMsg: string, errNo: number) => void;
}

export interface TinyRequest {
Expand Down
38 changes: 23 additions & 15 deletions src/request-lib/wx-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@ export class WxRequest implements TinyRequest {
constructor(private wx: WxInstance, private accessToken: string) { }

async get(url: string) {
return this.wx.request({
url,
method: 'GET',
header: {
'Authorization': this.accessToken,
'PRIVATE-TOKEN': this.accessToken
}
return new Promise((resolve, reject) => {
this.wx.request({
url,
method: 'GET',
header: {
'Authorization': this.accessToken,
'PRIVATE-TOKEN': this.accessToken
},
success: (res: {data: string | Object | ArrayBuffer, statusCode: number}) => {
resolve(res);
},
fail: (errMsg: string, errNo: number) => {
reject(errMsg);
}
});
});
}

post(url: string) {
this.wx.request({
url,
method: 'POST',
header: {
'Authorization': this.accessToken,
'PRIVATE-TOKEN': this.accessToken
}
});
// this.wx.request({
// url,
// method: 'POST',
// header: {
// 'Authorization': this.accessToken,
// 'PRIVATE-TOKEN': this.accessToken
// }
// });
}
}

0 comments on commit 4f1ae11

Please sign in to comment.