利用js写函数返回js基本函数代码

不定参数求和

SUM: function (...arg) {
let len = arg.length;
if (len > 0){
var sum = "";

for(let i=0;i<len;i++){
sum += arg[i] + "+"
}
return sum.substr(0,sum.length-1)
}
return ""
},

不定参数求最大值

MAX :function (...arg){
let len = arg.length;
if (len > 0){
var max = "Math.max(";

for(let i=0;i<len;i++){
max += arg[i] + ","
}
return max.substr(0,max.length-1) +")"
}

return "";
},

不定参数求最小值

MIN function (...arg){
let len = arg.length;
if (len > 0){
var min = "Math.min(";

for(let i=0;i<len;i++){
min += arg[i] + ","
}
return min.substr(0,min.length-1) +")"
}

return "";
},

四舍五入精确到固定位小数

ROUND function (...arg){
let len = arg.length;
if (len == 1){
return "Math.round(" + arg[0] + "+\'e\'+ 2) / Math.pow(10, 2)";
} else if (len == 2){
return "Math.round(" + arg[0] + "+\'e\'+ 2) / Math.pow(10, "+ arg[1] + ")";;
} else {
return ""
}
},

获取日期类型参数年份 2006-10-01 12:00:05

YEAR function (...arg){
let len = arg.length;
if (len == 1){
return "new Date(" + "\"" + arg[0] + "\"" + ".replace(/-/g, '/')).getFullYear()";
}
return ""
},

获取日期类型参数月份 2006-10-01 12:00:05

MONTH function (...arg){
let len = arg.length;
if (len == 1){
return "new Date(" + "\"" + arg[0] + "\"" + ".replace(/-/g, '/')).getMonth()";
}
return ""
},

获取日期类型参数日期 2006-10-01 12:00:05

DAY function (...arg){
let len = arg.length;
if (len == 1){
return "new Date(" + "\"" + arg[0] + "\"" + ".replace(/-/g, '/')).getDate()";
}
return ""
},

获取日期类型参数小时 2006-10-01 12:00:05

HOUR function (...arg){
let len = arg.length;
if (len == 1){
return "new Date(" + "\"" + arg[0] + "\"" + ".replace(/-/g, '/')).getHours()";
}
return ""
},

获取日期类型参数分钟 2006-10-01 12:00:05

MINUTE function (...arg){
let len = arg.length;
if (len == 1){
return "new Date(" + "\"" + arg[0] + "\"" + ".replace(/-/g, '/')).getMinutes()";
}
return ""
},

获取日期类型参数秒数 2006-10-01 12:00:05

SECOND function (...arg){
let len = arg.length;
if (len == 1){
return "new Date(" + "\"" + arg[0] + "\"" + ".replace(/-/g, '/')).getSeconds()";
}
return ""
},

返回当前的日期 2006-10-01

CURDATE function (...arg){
return "var date = new Date();\n" +
" var month = date.getMonth() + 1;\n" +
" var strDate = date.getDate();\n" +
"\tif(date.getMonth() + 1 < 10){\n" +
"\t\tmonth = \"0\" + (date.getMonth() + 1)\n" +
"\t}\n" +
"\tif(date.getDate() < 10){\n" +
"\t\tstrDate = \"0\" + date.getDate()\n" +
"\t}\n" +
"\n" +
" return date.getFullYear() + '-' + month + '-' + strDate"
},

返回当前日期时间字符串 2006-10-01 12:00:05

NOW function (...arg){
return " var date = new Date();\n" +
" var month = date.getMonth() + 1;\n" +
" var strDate = date.getDate();\n" +
"\tvar hour = date.getHours();\n" +
" var minute = date.getMinutes();\n" +
" var second = date.getSeconds();\n" +
"\t\n" +
"\tif(date.getMonth() + 1 < 10){\n" +
"\t\tmonth = \"0\" + (date.getMonth() + 1)\n" +
"\t}\n" +
"\tif(date.getDate() < 10){\n" +
"\t\tstrDate = \"0\" + date.getDate()\n" +
"\t}\n" +
"\tif(date.getHours() < 10){\n" +
"\t\thour = \"0\" + date.getHours()\n" +
"\t}\n" +
"\tif(date.getMinutes() < 10){\n" +
"\t\tminute = \"0\" + date.getMinutes()\n" +
"\t}\n" +
"\tif(date.getSeconds() < 10){\n" +
"\t\tsecond = \"0\" + date.getSeconds()\n" +
"\t}\n" +
"\n" +
" return date.getFullYear() + '-' + month + '-' + strDate+ ' ' + hour + ':' + minute + ':' + second"
},

将两个字符串连接为一个字符串

CONCAT function (...arg){
let len = arg.length;
if (len == 2){
return "\""+arg[0] + "\"" + ".concat("+ "\""+ arg[1] + "\"" +")";
}
return ""
},

返回文本字符串中从指定位置开始的特定数目的字符

SUBSTR function (...arg){
if (arg.length == 3){
return "\""+arg[0] + "\"" + ".substr(" + "\""+ arg[1]
+ "\"" +", "+ "\""+ arg[2] + "\"" + ")";
} else if (arg.length == 2){
return "\""+arg[0] + "\"" + ".substr(" + "\""+ arg[1]
+ "\"" +", "+ "\""+ arg[0].toString().length + "\"" + ")";
}
return "";
},

字符串的长度

LEN function (...arg){
if (arg.length == 1){
return "\"" + arg[0] + "\"" + ".length";
}
return "";
},

字符串转大写

UPPER function (...arg){
if (arg.length == 1){
return "\"" + arg[0] + "\"" + ".toUpperCase()";
}
return "";
},

字符串转小写

LOWER function (...arg){
if (arg.length == 1){
return "\"" + arg[0] + "\"" + ".toLowerCase()";
}
return "";
},

替换字符串

REPLACE function (...arg){
if (arg.length == 3){
return "\""+arg[0] + "\"" + ".replace(" + "/" +arg[1] +"/g"
+", "+ "\""+ arg[2] + "\"" + ")";
}
return "";
},

按字符截取字段为数组,并返回数组前n个元素

SPLIT function (...arg){
if (arg.length == 3){
return "\""+arg[0] + "\"" + ".split(" + "\""+ arg[1]
+ "\"" +", "+ "\""+ arg[2] + "\"" + ")";
} else if (arg.length == 2){
return "\""+arg[0] + "\"" + ".split(" + "\""+ arg[1]
+ "\"" +", "+ "\""+ arg[0].length + "\"" + ")";
}
return "";
},

获取当前人账号

CURRENTACCOUNT function (...arg){
return "this.$store.state.user.userInfo.token.account";
},

获取当前人部门ID

CURRENTDEPTID function (...arg){
return "this.$store.state.user.userInfo.token.dept_id";
},

获取当前人职员ID

CURRENTEMPID function (...arg){
return "this.$store.state.user.userInfo.token.emp_id";
},

获取当前人组织编码

CURRENTGROUP function (...arg){
return "this.$store.state.user.userInfo.token.groupOrganId";
},

获取当前人岗位ID

CURRENTPOSTID function (...arg){
return "this.$store.state.user.userInfo.token.post_id";
}