Skip to content

Commit ab2cd1d

Browse files
committed
feat: predict data display
1 parent 2c824d4 commit ab2cd1d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

frontend/src/views/chat/component/PredictChartBlock.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ChatMessage } from '@/api/chat.ts'
33
import { computed, watch, ref } from 'vue'
44
import type { ChartTypes } from '@/views/chat/component/BaseChart.ts'
55
import DisplayChartBlock from '@/views/chat/component/DisplayChartBlock.vue'
6+
import { concat } from 'lodash-es'
67
78
const props = defineProps<{
89
id?: number | string
@@ -11,21 +12,40 @@ const props = defineProps<{
1112
data: string
1213
}>()
1314
15+
const dataObject = computed<{
16+
fields: Array<string>
17+
data: Array<{ [key: string]: any }>
18+
}>(() => {
19+
if (props.message?.record?.data) {
20+
return JSON.parse(props.message.record.data)
21+
}
22+
return {}
23+
})
24+
1425
const _data = computed(() => {
26+
let _list = []
1527
if (
1628
props.data &&
1729
props.data.length > 0 &&
1830
props.data.trim().startsWith('[') &&
1931
props.data.trim().endsWith(']')
2032
) {
2133
try {
22-
return JSON.parse(props.data)
34+
_list = JSON.parse(props.data)
2335
} catch (e) {
2436
console.error(e)
2537
}
2638
}
2739
28-
return []
40+
if (_list.length == 0) {
41+
return _list
42+
}
43+
44+
if (dataObject.value.data && dataObject.value.data.length > 0) {
45+
return concat(dataObject.value.data, _list)
46+
}
47+
48+
return _list
2949
})
3050
3151
const blockRef = ref()

0 commit comments

Comments
 (0)