From 44ad1b5e08b68116a688d49b0e036e31d9e526c0 Mon Sep 17 00:00:00 2001 From: alan Date: Tue, 7 Jan 2020 17:50:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Durl=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E6=97=B6=E5=9C=B0=E5=9D=80=E4=BB=A5/=E7=BB=93?= =?UTF-8?q?=E5=B0=BE=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/crud/crud.service.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/modules/crud/crud.service.ts b/src/modules/crud/crud.service.ts index a9282ff..c174421 100644 --- a/src/modules/crud/crud.service.ts +++ b/src/modules/crud/crud.service.ts @@ -3,32 +3,40 @@ import { ReqPath } from '../constants/env'; export function requestGet(url: string, data?: any): Promise { + const requestURL = url ? ReqPath : `${ReqPath}/${url}`; + return new Promise(resolve => { - Dec.reqGet(`${ReqPath}/${url}`, '', re => { + Dec.reqGet(requestURL, '', re => { resolve(re); }); }); } export function requestPost(url: string, data = {}): Promise { + const requestURL = url ? ReqPath : `${ReqPath}/${url}`; + return new Promise(resolve => { - Dec.reqPost(`${ReqPath}/${url}`, data, re => { + Dec.reqPost(requestURL, data, re => { resolve(re); }); }); } export function requestDelete(url: string, data = {}) { + const requestURL = url ? ReqPath : `${ReqPath}/${url}`; + return new Promise(resolve => { - Dec.reqDelete(`${ReqPath}/${url}`, data, re => { + Dec.reqDelete(requestURL, data, re => { resolve(re); }); }); } export function requestPut(url: string, data = {}) { + const requestURL = url ? ReqPath : `${ReqPath}/${url}`; + return new Promise(resolve => { - Dec.reqPut(`${ReqPath}/${url}`, data, re => { + Dec.reqPut(requestURL, data, re => { resolve(re); }); }); From 4c69a4eeb446fd877c1a0d7daa65cbcc29c5aed8 Mon Sep 17 00:00:00 2001 From: alan Date: Tue, 7 Jan 2020 17:53:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/crud/crud.service.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/modules/crud/crud.service.ts b/src/modules/crud/crud.service.ts index c174421..19297e7 100644 --- a/src/modules/crud/crud.service.ts +++ b/src/modules/crud/crud.service.ts @@ -1,42 +1,37 @@ import { ResultType } from './crud.typings.d'; import { ReqPath } from '../constants/env'; +function getFullUrl(url: string) { + return url ? `${ReqPath}/${url}` : ReqPath; +} export function requestGet(url: string, data?: any): Promise { - const requestURL = url ? ReqPath : `${ReqPath}/${url}`; - return new Promise(resolve => { - Dec.reqGet(requestURL, '', re => { + Dec.reqGet(getFullUrl(url), '', re => { resolve(re); }); }); } export function requestPost(url: string, data = {}): Promise { - const requestURL = url ? ReqPath : `${ReqPath}/${url}`; - return new Promise(resolve => { - Dec.reqPost(requestURL, data, re => { + Dec.reqPost(getFullUrl(url), data, re => { resolve(re); }); }); } export function requestDelete(url: string, data = {}) { - const requestURL = url ? ReqPath : `${ReqPath}/${url}`; - return new Promise(resolve => { - Dec.reqDelete(requestURL, data, re => { + Dec.reqDelete(getFullUrl(url), data, re => { resolve(re); }); }); } export function requestPut(url: string, data = {}) { - const requestURL = url ? ReqPath : `${ReqPath}/${url}`; - return new Promise(resolve => { - Dec.reqPut(requestURL, data, re => { + Dec.reqPut(getFullUrl(url), data, re => { resolve(re); }); });