mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-24 08:12:49 +08:00
perf: 优化 JSONParse 过滤函数值表达式写法
This commit is contained in:
parent
134b44944e
commit
00a4c752ed
@ -7,7 +7,7 @@ export enum BaseEvent {
|
||||
// 移入
|
||||
ON_MOUSE_ENTER = 'mouseenter',
|
||||
// 移出
|
||||
ON_MOUSE_LEAVE = 'mouseleave',
|
||||
ON_MOUSE_LEAVE = 'mouseleave'
|
||||
}
|
||||
|
||||
// vue3 生命周期事件
|
||||
@ -15,7 +15,7 @@ export enum EventLife {
|
||||
// 渲染之后
|
||||
VNODE_MOUNTED = 'vnodeMounted',
|
||||
// 渲染之前
|
||||
VNODE_BEFORE_MOUNT = 'vnodeBeforeMount',
|
||||
VNODE_BEFORE_MOUNT = 'vnodeBeforeMount'
|
||||
}
|
||||
|
||||
// 内置字符串函数对象列表
|
||||
@ -29,3 +29,8 @@ export const excludeParseEventKeyList = [
|
||||
//过滤器
|
||||
'filter'
|
||||
]
|
||||
// 内置字符串函数键值列表
|
||||
export const excludeParseEventValueList = [
|
||||
// 请求里的函数语句
|
||||
'javascript:'
|
||||
]
|
||||
|
@ -10,7 +10,7 @@ import cloneDeep from 'lodash/cloneDeep'
|
||||
import { WinKeyboard } from '@/enums/editPageEnum'
|
||||
import { RequestHttpIntervalEnum, RequestParamsObjType } from '@/enums/httpEnum'
|
||||
import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
|
||||
import { excludeParseEventKeyList } from '@/enums/eventEnum'
|
||||
import { excludeParseEventKeyList, excludeParseEventValueList } from '@/enums/eventEnum'
|
||||
|
||||
/**
|
||||
* * 判断是否是开发环境
|
||||
@ -320,14 +320,17 @@ export const JSONStringify = <T>(data: T) => {
|
||||
*/
|
||||
export const JSONParse = (data: string) => {
|
||||
return JSON.parse(data, (k, v) => {
|
||||
// 过滤函数字符串
|
||||
if (excludeParseEventKeyList.includes(k)) return v
|
||||
if(typeof v === 'string' && v.indexOf('javascript:') > -1){
|
||||
//动态请求json中'javascript:'内容会影响模板content解析,直接返回
|
||||
return v
|
||||
// 过滤函数值表达式
|
||||
if (typeof v === 'string') {
|
||||
const someValue = excludeParseEventValueList.some(excludeValue => v.indexOf(excludeValue) > -1)
|
||||
if (someValue) return v
|
||||
}
|
||||
// 还原函数值
|
||||
if (typeof v === 'string' && v.indexOf && (v.indexOf('function') > -1 || v.indexOf('=>') > -1)) {
|
||||
return eval(`(function(){return ${v}})()`)
|
||||
} else if (typeof v === 'string' && v.indexOf && (v.indexOf('return ') > -1)) {
|
||||
} else if (typeof v === 'string' && v.indexOf && v.indexOf('return ') > -1) {
|
||||
const baseLeftIndex = v.indexOf('(')
|
||||
if (baseLeftIndex > -1) {
|
||||
const newFn = `function ${v.substring(baseLeftIndex)}`
|
||||
|
Loading…
Reference in New Issue
Block a user