fix: 解决过滤器的错误处理
This commit is contained in:
parent
5cbd15992a
commit
831ae3a3db
@ -53,7 +53,6 @@ export const useChartDataFetch = (
|
||||
// eCharts 组件配合 vChart 库更新方式
|
||||
if (chartFrame === ChartFrameEnum.ECHARTS) {
|
||||
if (vChartRef.value) {
|
||||
|
||||
vChartRef.value.setOption({ dataset: newFunctionHandle(res.data, filter) })
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import throttle from 'lodash/throttle'
|
||||
import Image_404 from '../assets/images/exception/image-404.png'
|
||||
import html2canvas from 'html2canvas'
|
||||
import { downloadByA } from './file'
|
||||
import { isString } from './type'
|
||||
import { toString } from './type'
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
|
||||
/**
|
||||
@ -196,7 +196,7 @@ export const canvasCut = (html: HTMLElement | null, callback?: Function) => {
|
||||
export const newFunctionHandle = (
|
||||
data: any,
|
||||
funcStr?: string,
|
||||
toString?: boolean,
|
||||
isToString?: boolean,
|
||||
errorCallBack?: Function,
|
||||
successCallBack?: Function
|
||||
) => {
|
||||
@ -204,7 +204,7 @@ export const newFunctionHandle = (
|
||||
if (!funcStr) return data
|
||||
const fn = new Function('data', funcStr)
|
||||
const fnRes = fn( cloneDeep(data))
|
||||
const resHandle = toString && isString(fnRes) ? fnRes : JSON.stringify(fnRes)
|
||||
const resHandle = isToString ? toString(fnRes) : fnRes
|
||||
// 成功回调
|
||||
successCallBack && successCallBack(resHandle)
|
||||
return resHandle
|
||||
|
@ -72,7 +72,7 @@
|
||||
</div>
|
||||
</n-space>
|
||||
<n-card size="small">
|
||||
<n-code :code="filterRes(getSource)" language="json"></n-code>
|
||||
<n-code :code="filterRes(source)" language="json"></n-code>
|
||||
</n-card>
|
||||
</n-space>
|
||||
</n-timeline-item>
|
||||
@ -126,11 +126,6 @@ const isCharts = computed(() => {
|
||||
return targetData.value.chartConfig.package === PackagesCategoryEnum.CHARTS
|
||||
})
|
||||
|
||||
// 获取数据
|
||||
const getSource = computed(() => {
|
||||
return JSON.stringify(source.value)
|
||||
})
|
||||
|
||||
// 处理映射列表状态结果
|
||||
const matchingHandle = (mapping: string) => {
|
||||
let res = DataResultEnum.SUCCESS
|
||||
@ -176,7 +171,7 @@ const filterRes = (data: any) => {
|
||||
const res = fn(cloneDeep(data))
|
||||
return toString(res)
|
||||
}
|
||||
return data
|
||||
return toString(cloneDeep(data))
|
||||
} catch (error) {
|
||||
return '过滤函数错误'
|
||||
}
|
||||
|
@ -68,13 +68,13 @@
|
||||
<div class="editor-data-show">
|
||||
<n-space>
|
||||
<n-text depth="3">目标数据:</n-text>
|
||||
<n-code :code="toString(sourceData)" language="typescript" :word-wrap="true"></n-code>
|
||||
<n-code :code="toString(sourceData)" language="json" :word-wrap="true"></n-code>
|
||||
</n-space>
|
||||
</div>
|
||||
<div class="editor-data-show">
|
||||
<n-space>
|
||||
<n-text depth="3">过滤器结果:</n-text>
|
||||
<n-code :code="filterRes" language="typescript" :word-wrap="true"></n-code>
|
||||
<n-code :code="filterRes" language="json" :word-wrap="true"></n-code>
|
||||
</n-space>
|
||||
</div>
|
||||
</n-space>
|
||||
@ -140,7 +140,6 @@ const fetchTargetData = async () => {
|
||||
const res = await http(requestHttpType)(completePath || '', {})
|
||||
if (res.status === ResultEnum.SUCCESS) {
|
||||
sourceData.value = res.data
|
||||
console.log(sourceData.value)
|
||||
return
|
||||
}
|
||||
} catch (error) {
|
||||
@ -154,7 +153,7 @@ const filterRes = computed(() => {
|
||||
const fn = new Function('data', filter.value)
|
||||
const res = fn(cloneDeep(sourceData.value))
|
||||
errorFlag.value = false
|
||||
return JSON.stringify(res)
|
||||
return toString(res)
|
||||
} catch (error) {
|
||||
errorFlag.value = true
|
||||
return '过滤函数错误'
|
||||
|
Loading…
x
Reference in New Issue
Block a user