...
|
...
|
@@ -42,7 +42,7 @@ var util={ |
|
|
if (res.code != 200) {
|
|
|
util.__tip(res.message,"danger");
|
|
|
} else {
|
|
|
callback.bind(this,res)();
|
|
|
return callback.bind(this,res)();
|
|
|
}
|
|
|
}
|
|
|
});
|
...
|
...
|
@@ -92,6 +92,69 @@ var util={ |
|
|
}
|
|
|
return result;
|
|
|
},
|
|
|
__template2:function(str,source){
|
|
|
// console.log(str);
|
|
|
//获取参数
|
|
|
var keys=[];
|
|
|
for(var key in source){
|
|
|
if(typeof source[key]=="boolean"){
|
|
|
keys.push(key+"="+source[key]);
|
|
|
}else{
|
|
|
keys.push(key+"="+JSON.stringify(source[key]));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
var result="var "+keys.join(',')+";";
|
|
|
var html="";
|
|
|
html=str.replace(/\{\{(.*?)\}\}/igm,function(name,$1){
|
|
|
var trim=$1.replace(/^\s+|\s+$/,'');
|
|
|
if(/^each/.test(trim))
|
|
|
{
|
|
|
trim=trim.replace(/^each\s+(\w+)\s+as\s+(\w+)\s+(\w+)/,'Util.Fun.each\( $1,function($3,$2){');
|
|
|
return "{{"+trim+"}}";
|
|
|
}else
|
|
|
if(/^\/each/.test(trim)){
|
|
|
trim=trim.replace(/^\/each/,'});')
|
|
|
return "{{"+trim+"}}";
|
|
|
}
|
|
|
else if(/^if/.test(trim)){
|
|
|
trim=trim.replace(/^if(.+)/,'if($1){');
|
|
|
return "{{"+trim+"}}";
|
|
|
}
|
|
|
else if(/^\/if/.test(trim)){
|
|
|
trim=trim.replace(/^\/if/,'};')
|
|
|
return "{{"+trim+"}}";
|
|
|
}
|
|
|
else if(/^else$/.test(trim)){
|
|
|
trim=trim.replace(/else/,'}else{');
|
|
|
return "{{"+trim+"}}";
|
|
|
}
|
|
|
else{
|
|
|
return "{{+"+trim+"+}}";
|
|
|
}
|
|
|
});
|
|
|
html=html.replace(/(^|\}\})(.*?)(\{\{|$)/igm,function(name,$1,$2){
|
|
|
var trim=$2.replace(/^\s+|\s+$/,'');
|
|
|
return trim?Util.String.formstr($2):'';
|
|
|
});
|
|
|
// var result="var result='';result+=";
|
|
|
var arr=html.split(/\n+/igm);
|
|
|
result+="var p=[];\n";
|
|
|
for(var i=0;i<arr.length;i++){
|
|
|
if(/^'/.test(arr[i])){
|
|
|
result+="p.push("+(arr[i])+");\n";
|
|
|
}else{
|
|
|
result+=(arr[i]);
|
|
|
}
|
|
|
}
|
|
|
result+="return p.join('');\n";
|
|
|
|
|
|
|
|
|
var fn=new Function(result);
|
|
|
var b=fn.call(source);
|
|
|
return b;
|
|
|
},
|
|
|
__input:function(id){
|
|
|
return !!~$.trim($('#'+id).val())?$('#'+id).val():""
|
|
|
}
|
...
|
...
|
|