export function dynamicsumFun(script, model, key = "$") {
if (!script) return false;
let reg = /(?<=\.)\w+/g
const match_script = script.match(reg)
let matchObj = {}
match_script.forEach(it=>{
matchObj[it] = model[it]
})
let scriptAction = script
for(let key in matchObj){
let sckey = '\\$\\.' + key
//\\号为转义符转义$和.为普通字符串
scriptAction = scriptAction.replace(new RegExp(sckey,'g'),matchObj[key]+'')
}
return scriptAction
/* const params = {
formula: scriptAction
}
var res = ''
formcalculation(params).then(itm=>{
console.log('return data',itm.data)
res = itm.data
return res
}) */
}
//字符串型的函数使用
export function dynamicFun(script, model, key = "$") {
if (!script) return false;
const func =
script.indexOf("return") >= 0
? "{" + script + "}"
: "return (" + script + ")";
// 截取$.开始到不是数字或字母结尾的字符串
const Fn = new Function(key, func);
return Fn(model);
}
//截取字符串{}中间的字符串
var needredu = /(?<=\{)(.+?)(?=\})/g
let result = ''
result = its.options.maxTotal.match(needredu)