@farris/bef
Advanced tools
Comparing version 0.0.11-201903031340 to 0.0.11-201903031600
@@ -1147,3 +1147,3 @@ (function (global, factory) { | ||
var options = this.addBodyToOptions({}, body); | ||
return this.request(this.baseUri, PUT, options); | ||
return this.request(this.baseUri, PUT, null, options); | ||
}; | ||
@@ -1254,6 +1254,41 @@ /** | ||
// 3、返回老的结构:兼容老的代码 | ||
return result ? result.returnValue : result; | ||
return _this.unWrapResponseInfo(result); | ||
} | ||
})); | ||
}; | ||
/** | ||
* 纠正body | ||
* 问题描述:自定义动作只有一个参数时,由于API给加了一个RequestInfo,导致变成两个了,但参数名不知道,导致无法兼容。 | ||
* 1、老的写法:{body: 参数值} | ||
* 2、新的写法:body = { 参数名: 参数值 } | ||
* 解决方案: | ||
* 1、检测body是不是简单类型,如果是,则视为只有一个参数,进行纠正; | ||
* 2、body是对象:无法区分对象是整体作为参数,还是里面的key作为参数,无法纠正。(无法兼容) | ||
*/ | ||
BefRestService.prototype.correctBody = function (body) { | ||
}; | ||
/** | ||
* 处理返回值,兼容老版本 | ||
*/ | ||
BefRestService.prototype.unWrapResponseInfo = function (result) { | ||
// 兼容cancel没有返回值的情况 | ||
if (!result) { | ||
return result; | ||
} | ||
// 没有returnValue的情况下,兼容query取数的的格式 | ||
if (result.hasOwnProperty('returnValue') === false) { | ||
if (result.hasOwnProperty('result') && result.hasOwnProperty('pagination')) { | ||
// 兼容返回带分页的列表数据 | ||
return result.result; | ||
} | ||
return result; | ||
} | ||
// 其他:返回RequestInfo.returnValue的情况 | ||
var returnValue = result.returnValue; | ||
if (returnValue && returnValue.hasOwnProperty('result') && returnValue.hasOwnProperty('pagination')) { | ||
// 兼容返回带分页的列表数据 | ||
return returnValue.result; | ||
} | ||
return result.returnValue; | ||
}; | ||
// #region 工具方法 | ||
@@ -1260,0 +1295,0 @@ BefRestService.prototype.hasResponseInfo = function (options) { |
@@ -1105,3 +1105,3 @@ import { InjectionToken, Injectable, Injector } from '@angular/core'; | ||
const options = this.addBodyToOptions({}, body); | ||
return this.request(this.baseUri, PUT, options); | ||
return this.request(this.baseUri, PUT, null, options); | ||
} | ||
@@ -1211,6 +1211,41 @@ /** | ||
// 3、返回老的结构:兼容老的代码 | ||
return result ? result.returnValue : result; | ||
return this.unWrapResponseInfo(result); | ||
} | ||
})); | ||
} | ||
/** | ||
* 纠正body | ||
* 问题描述:自定义动作只有一个参数时,由于API给加了一个RequestInfo,导致变成两个了,但参数名不知道,导致无法兼容。 | ||
* 1、老的写法:{body: 参数值} | ||
* 2、新的写法:body = { 参数名: 参数值 } | ||
* 解决方案: | ||
* 1、检测body是不是简单类型,如果是,则视为只有一个参数,进行纠正; | ||
* 2、body是对象:无法区分对象是整体作为参数,还是里面的key作为参数,无法纠正。(无法兼容) | ||
*/ | ||
correctBody(body) { | ||
} | ||
/** | ||
* 处理返回值,兼容老版本 | ||
*/ | ||
unWrapResponseInfo(result) { | ||
// 兼容cancel没有返回值的情况 | ||
if (!result) { | ||
return result; | ||
} | ||
// 没有returnValue的情况下,兼容query取数的的格式 | ||
if (result.hasOwnProperty('returnValue') === false) { | ||
if (result.hasOwnProperty('result') && result.hasOwnProperty('pagination')) { | ||
// 兼容返回带分页的列表数据 | ||
return result.result; | ||
} | ||
return result; | ||
} | ||
// 其他:返回RequestInfo.returnValue的情况 | ||
const returnValue = result.returnValue; | ||
if (returnValue && returnValue.hasOwnProperty('result') && returnValue.hasOwnProperty('pagination')) { | ||
// 兼容返回带分页的列表数据 | ||
return returnValue.result; | ||
} | ||
return result.returnValue; | ||
} | ||
// #region 工具方法 | ||
@@ -1217,0 +1252,0 @@ hasResponseInfo(options) { |
@@ -1151,3 +1151,3 @@ import { InjectionToken, Injectable, Injector } from '@angular/core'; | ||
var options = this.addBodyToOptions({}, body); | ||
return this.request(this.baseUri, PUT, options); | ||
return this.request(this.baseUri, PUT, null, options); | ||
}; | ||
@@ -1258,6 +1258,41 @@ /** | ||
// 3、返回老的结构:兼容老的代码 | ||
return result ? result.returnValue : result; | ||
return _this.unWrapResponseInfo(result); | ||
} | ||
})); | ||
}; | ||
/** | ||
* 纠正body | ||
* 问题描述:自定义动作只有一个参数时,由于API给加了一个RequestInfo,导致变成两个了,但参数名不知道,导致无法兼容。 | ||
* 1、老的写法:{body: 参数值} | ||
* 2、新的写法:body = { 参数名: 参数值 } | ||
* 解决方案: | ||
* 1、检测body是不是简单类型,如果是,则视为只有一个参数,进行纠正; | ||
* 2、body是对象:无法区分对象是整体作为参数,还是里面的key作为参数,无法纠正。(无法兼容) | ||
*/ | ||
BefRestService.prototype.correctBody = function (body) { | ||
}; | ||
/** | ||
* 处理返回值,兼容老版本 | ||
*/ | ||
BefRestService.prototype.unWrapResponseInfo = function (result) { | ||
// 兼容cancel没有返回值的情况 | ||
if (!result) { | ||
return result; | ||
} | ||
// 没有returnValue的情况下,兼容query取数的的格式 | ||
if (result.hasOwnProperty('returnValue') === false) { | ||
if (result.hasOwnProperty('result') && result.hasOwnProperty('pagination')) { | ||
// 兼容返回带分页的列表数据 | ||
return result.result; | ||
} | ||
return result; | ||
} | ||
// 其他:返回RequestInfo.returnValue的情况 | ||
var returnValue = result.returnValue; | ||
if (returnValue && returnValue.hasOwnProperty('result') && returnValue.hasOwnProperty('pagination')) { | ||
// 兼容返回带分页的列表数据 | ||
return returnValue.result; | ||
} | ||
return result.returnValue; | ||
}; | ||
// #region 工具方法 | ||
@@ -1264,0 +1299,0 @@ BefRestService.prototype.hasResponseInfo = function (options) { |
{ | ||
"name": "@farris/bef", | ||
"version": "0.0.11-201903031340", | ||
"version": "0.0.11-201903031600", | ||
"description": "Farris Bef", | ||
@@ -5,0 +5,0 @@ "main": "./bundles/index.umd.js", |
@@ -104,2 +104,16 @@ import { HttpClient } from '@angular/common/http'; | ||
request(url: string, method: string, params?: any, options?: any): Observable<any>; | ||
/** | ||
* 纠正body | ||
* 问题描述:自定义动作只有一个参数时,由于API给加了一个RequestInfo,导致变成两个了,但参数名不知道,导致无法兼容。 | ||
* 1、老的写法:{body: 参数值} | ||
* 2、新的写法:body = { 参数名: 参数值 } | ||
* 解决方案: | ||
* 1、检测body是不是简单类型,如果是,则视为只有一个参数,进行纠正; | ||
* 2、body是对象:无法区分对象是整体作为参数,还是里面的key作为参数,无法纠正。(无法兼容) | ||
*/ | ||
private correctBody; | ||
/** | ||
* 处理返回值,兼容老版本 | ||
*/ | ||
private unWrapResponseInfo; | ||
private hasResponseInfo; | ||
@@ -106,0 +120,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
481019
19
4770