diff --git a/package.json b/package.json index 15a3716..669d8f4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/request-lib/interfaces.ts b/src/request-lib/interfaces.ts index 27f0995..519f373 100644 --- a/src/request-lib/interfaces.ts +++ b/src/request-lib/interfaces.ts @@ -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 { diff --git a/src/request-lib/wx-request.ts b/src/request-lib/wx-request.ts index 63206a9..3f33e36 100644 --- a/src/request-lib/wx-request.ts +++ b/src/request-lib/wx-request.ts @@ -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 + // } + // }); } }