mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-24 16:22:57 +08:00
perf: 优化 JSONParse 过滤函数值表达式写法
This commit is contained in:
parent
a4ec0080e9
commit
62e3d92ed5
@ -7,15 +7,15 @@ export enum BaseEvent {
|
|||||||
// 移入
|
// 移入
|
||||||
ON_MOUSE_ENTER = 'mouseenter',
|
ON_MOUSE_ENTER = 'mouseenter',
|
||||||
// 移出
|
// 移出
|
||||||
ON_MOUSE_LEAVE = 'mouseleave',
|
ON_MOUSE_LEAVE = 'mouseleave'
|
||||||
}
|
}
|
||||||
|
|
||||||
// vue3 生命周期事件
|
// vue3 生命周期事件
|
||||||
export enum EventLife {
|
export enum EventLife {
|
||||||
// 渲染之后
|
// 渲染之后
|
||||||
VNODE_MOUNTED = 'vnodeMounted',
|
VNODE_MOUNTED = 'vnodeMounted',
|
||||||
// 渲染之前
|
// 渲染之前
|
||||||
VNODE_BEFORE_MOUNT = 'vnodeBeforeMount',
|
VNODE_BEFORE_MOUNT = 'vnodeBeforeMount'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 内置字符串函数对象列表
|
// 内置字符串函数对象列表
|
||||||
@ -28,4 +28,9 @@ export const excludeParseEventKeyList = [
|
|||||||
BaseEvent.ON_MOUSE_LEAVE,
|
BaseEvent.ON_MOUSE_LEAVE,
|
||||||
//过滤器
|
//过滤器
|
||||||
'filter'
|
'filter'
|
||||||
]
|
]
|
||||||
|
// 内置字符串函数键值列表
|
||||||
|
export const excludeParseEventValueList = [
|
||||||
|
// 请求里的函数语句
|
||||||
|
'javascript:'
|
||||||
|
]
|
||||||
|
@ -10,7 +10,7 @@ import cloneDeep from 'lodash/cloneDeep'
|
|||||||
import { WinKeyboard } from '@/enums/editPageEnum'
|
import { WinKeyboard } from '@/enums/editPageEnum'
|
||||||
import { RequestHttpIntervalEnum, RequestParamsObjType } from '@/enums/httpEnum'
|
import { RequestHttpIntervalEnum, RequestParamsObjType } from '@/enums/httpEnum'
|
||||||
import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
|
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) => {
|
export const JSONParse = (data: string) => {
|
||||||
return JSON.parse(data, (k, v) => {
|
return JSON.parse(data, (k, v) => {
|
||||||
|
// 过滤函数字符串
|
||||||
if (excludeParseEventKeyList.includes(k)) return v
|
if (excludeParseEventKeyList.includes(k)) return v
|
||||||
if(typeof v === 'string' && v.indexOf('javascript:') > -1){
|
// 过滤函数值表达式
|
||||||
//动态请求json中'javascript:'内容会影响模板content解析,直接返回
|
if (typeof v === 'string') {
|
||||||
return v
|
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)) {
|
if (typeof v === 'string' && v.indexOf && (v.indexOf('function') > -1 || v.indexOf('=>') > -1)) {
|
||||||
return eval(`(function(){return ${v}})()`)
|
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('(')
|
const baseLeftIndex = v.indexOf('(')
|
||||||
if (baseLeftIndex > -1) {
|
if (baseLeftIndex > -1) {
|
||||||
const newFn = `function ${v.substring(baseLeftIndex)}`
|
const newFn = `function ${v.substring(baseLeftIndex)}`
|
||||||
@ -344,4 +347,4 @@ export const JSONParse = (data: string) => {
|
|||||||
*/
|
*/
|
||||||
export const setTitle = (title?: string) => {
|
export const setTitle = (title?: string) => {
|
||||||
title && (document.title = title)
|
title && (document.title = title)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user