From 5982da14e436721a70b893e496ce51f6a797ee3b Mon Sep 17 00:00:00 2001 From: GuoXiCheng <1377994267@qq.com> Date: Sun, 3 Dec 2023 15:09:14 +0800 Subject: [PATCH] update wx-request --- package.json | 2 +- src/request-lib/interfaces.ts | 2 ++ src/request-lib/wx-request.ts | 38 +++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 16 deletions(-) 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 + // } + // }); } }