mirror of
https://gitee.com/dromara/go-view.git
synced 2024-11-29 18:28:28 +08:00
feat: 防止前端编译工具安全警告报错
This commit is contained in:
parent
b7fd270eb9
commit
f0db75f623
@ -314,6 +314,11 @@ export const JSONStringify = <T>(data: T) => {
|
||||
)
|
||||
}
|
||||
|
||||
export const evalFn = (fn: string) => {
|
||||
var Fun = Function // 一个变量指向Function,防止前端编译工具报错
|
||||
return new Fun('return ' + fn)()
|
||||
}
|
||||
|
||||
/**
|
||||
* * JSON反序列化,支持函数和 undefined
|
||||
* @param data
|
||||
@ -329,12 +334,12 @@ export const JSONParse = (data: string) => {
|
||||
}
|
||||
// 还原函数值
|
||||
if (typeof v === 'string' && v.indexOf && (v.indexOf('function') > -1 || v.indexOf('=>') > -1)) {
|
||||
return eval(`(function(){return ${v}})()`)
|
||||
return evalFn(`(function(){return ${v}})()`)
|
||||
} else if (typeof v === 'string' && v.indexOf && v.indexOf('return ') > -1) {
|
||||
const baseLeftIndex = v.indexOf('(')
|
||||
if (baseLeftIndex > -1) {
|
||||
const newFn = `function ${v.substring(baseLeftIndex)}`
|
||||
return eval(`(function(){return ${newFn}})()`)
|
||||
return evalFn(`(function(){return ${newFn}})()`)
|
||||
}
|
||||
}
|
||||
return v
|
||||
|
Loading…
Reference in New Issue
Block a user