...
|
...
|
@@ -26,7 +26,7 @@ Controller.prototype.__parseReq=function(req){ |
|
|
}
|
|
|
}
|
|
|
|
|
|
Controller.prototype.__define=function(method,router,view,apis,callback,clientmodel){
|
|
|
Controller.prototype.__define=function(method,router,view,apis,callback,clientmodel,clientsrc){
|
|
|
var me=this,isObj=false;
|
|
|
if(typeof apis=="string"){
|
|
|
apis=[apis];
|
...
|
...
|
@@ -34,34 +34,34 @@ Controller.prototype.__define=function(method,router,view,apis,callback,clientmo |
|
|
}
|
|
|
/*参数验证*/
|
|
|
var guid=md5(router+":"+method)
|
|
|
|
|
|
|
|
|
me.on(guid,function(){
|
|
|
var args=[].slice.call(arguments, 0);
|
|
|
var req = args[0], res = args[1];
|
|
|
var req = args[0], res = args[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var local = { __session__: req.session, $extend: {} };
|
|
|
|
|
|
var local = { __session__: req.session, $extend: {} };
|
|
|
/*如果接口不存在 就实现express 原来的方法*/
|
|
|
if(!apis.length){
|
|
|
var model={};
|
|
|
if(callback){
|
|
|
model=callback.apply(local, args);
|
|
|
model=callback.apply(local, args);
|
|
|
}
|
|
|
if(view){
|
|
|
res.render(view,local,me.client(res,view,model,clientmodel));
|
|
|
res.render(view,local,me.client(res,clientsrc,model,clientmodel));
|
|
|
}
|
|
|
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
args.push(function (err, interfaces, names){
|
|
|
if (err) {
|
|
|
res.json({code:500,message:"接口异常"});
|
|
|
return;
|
|
|
}
|
|
|
args.push(function (err, interfaces, names){
|
|
|
if (err) {
|
|
|
res.json({code:500,message:err.message||'接口异常'});
|
|
|
return;
|
|
|
}
|
|
|
//callback
|
|
|
var model={};
|
|
|
if (typeof callback == "function") {
|
|
|
if (typeof callback == "function") {
|
|
|
model=callback.apply(local,interfaces.concat(args));
|
|
|
}else{
|
|
|
interfaces.forEach(function(item,index){
|
...
|
...
|
@@ -70,18 +70,18 @@ Controller.prototype.__define=function(method,router,view,apis,callback,clientmo |
|
|
}else{
|
|
|
model[names[index]]=item;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
if(res.__complete__){
|
|
|
return;
|
|
|
}
|
|
|
if (model&&model.readable) {
|
|
|
model.pipe(res);
|
|
|
}else if (view && method == "get" && !req.xhr) {
|
|
|
res.render(view, local, me.client(res, view, model,clientmodel));
|
|
|
} else {
|
|
|
res.json(model);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
if(res.__complete__){
|
|
|
return;
|
|
|
}
|
|
|
if (model&&model.readable) {
|
|
|
model.pipe(res);
|
|
|
}else if (view && method == "get" && !req.xhr) {
|
|
|
res.render(view, local, me.client(res, clientsrc, model,clientmodel));
|
|
|
} else {
|
|
|
res.json(model);
|
|
|
}
|
|
|
});
|
|
|
//调用接口获取数据
|
|
|
me.interfaces.require.apply(me.interfaces,[apis].concat(args));
|
...
|
...
|
@@ -91,8 +91,8 @@ Controller.prototype.__define=function(method,router,view,apis,callback,clientmo |
|
|
guid:guid,
|
|
|
url:router,
|
|
|
method:method
|
|
|
});
|
|
|
//console.log(me.routers);
|
|
|
});
|
|
|
//console.log(me.routers);
|
|
|
}
|
|
|
Controller.prototype.vue=function(router,views,apis,callback){
|
|
|
var me=this;
|
...
|
...
|
@@ -106,7 +106,7 @@ Controller.prototype.vue=function(router,views,apis,callback){ |
|
|
apis=[];
|
|
|
}
|
|
|
apis=apis||[];
|
|
|
me.__define("get",router,views,apis,callback,"vue");
|
|
|
me.__define("get",router,"common.Vue",apis,callback,"vue",views);
|
|
|
}
|
|
|
Controller.prototype.get=function(router,views,apis,callback){
|
|
|
var me=this;
|
...
|
...
|
@@ -120,7 +120,7 @@ Controller.prototype.get=function(router,views,apis,callback){ |
|
|
apis=[];
|
|
|
}
|
|
|
apis=apis||[];
|
|
|
me.__define("get",router,views,apis,callback,"jquery");
|
|
|
me.__define("get",router,views,apis,callback,"jquery",views);
|
|
|
}
|
|
|
Controller.prototype.post=function(router,apis,callback){
|
|
|
var me=this;
|
...
|
...
|
|