mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-25 14:42:47 +00:00
optimise logic
This commit is contained in:
parent
532bfb9d13
commit
61c7cebe76
@ -6,6 +6,35 @@
|
||||
* @type {Class}
|
||||
*/
|
||||
export default class extends think.controller.base {
|
||||
/**
|
||||
* get validate method
|
||||
* @return {} []
|
||||
*/
|
||||
_getValidateItemMethod(itemData){
|
||||
let list = ['get', 'post', 'file'];
|
||||
for(let i = 0, length = list.length; i < length; i++){
|
||||
let item = list[i];
|
||||
if(itemData[list[i]]){
|
||||
delete itemData[item];
|
||||
return item;
|
||||
}
|
||||
}
|
||||
//for rest request
|
||||
let method = this._isRest && this._method;
|
||||
if(method){
|
||||
method = this.get(method);
|
||||
}
|
||||
if(!method){
|
||||
method = this.http.method.toLowerCase();
|
||||
}
|
||||
if(method === 'put' || method === 'patch'){
|
||||
return 'post';
|
||||
}
|
||||
if(list.indexOf(method) > -1){
|
||||
return method;
|
||||
}
|
||||
return 'post';
|
||||
}
|
||||
/**
|
||||
* parse validate data
|
||||
* {
|
||||
@ -29,14 +58,9 @@ export default class extends think.controller.base {
|
||||
itemData = think.extend({}, itemData);
|
||||
}
|
||||
|
||||
let method = this.http.method.toLowerCase();
|
||||
if(itemData.get){
|
||||
method = 'get';
|
||||
delete itemData.get;
|
||||
}else if(itemData.file){
|
||||
method = 'file';
|
||||
itemData.object = true; //when type is file, set data type to `object`
|
||||
delete itemData.file;
|
||||
let method = this._getValidateItemMethod(itemData);
|
||||
if(method === 'file'){
|
||||
itemData.object = true;
|
||||
}
|
||||
itemData._method = method;
|
||||
itemData.value = this[method](name);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user