22import ChartComponent from ' @/views/chat/component/ChartComponent.vue'
33import icon_window_mini_outlined from ' @/assets/svg/icon_window-mini_outlined.svg'
44import SqViewDisplay from ' @/views/dashboard/components/sq-view/index.vue'
5+ import _ from ' lodash'
56const props = defineProps ({
67 viewInfo: {
78 type: Object ,
@@ -19,7 +20,7 @@ const props = defineProps({
1920 },
2021})
2122
22- import { computed , nextTick , ref } from ' vue'
23+ import { computed , nextTick , onMounted , ref } from ' vue'
2324import { useI18n } from ' vue-i18n'
2425import ChartPopover from ' @/views/chat/chat-block/ChartPopover.vue'
2526import ICON_TABLE from ' @/assets/svg/chart/icon_form_outlined.svg'
@@ -34,8 +35,9 @@ const currentChartType = ref<ChartTypes | undefined>(undefined)
3435
3536const renderChart = () => {
3637 // @ts-expect-error eslint-disable-next-line @typescript-eslint/no-unused-expressions
37- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
38- chartRef .value ?.renderChart
38+ chartRef .value ?.destroyChart ()
39+ // @ts-expect-error eslint-disable-next-line @typescript-eslint/no-unused-expressions
40+ chartRef .value ?.renderChart ()
3941}
4042
4143const enlargeDialogVisible = ref (false )
@@ -47,7 +49,7 @@ const enlargeView = () => {
4749const chartTypeList = computed (() => {
4850 const _list = []
4951 if (props .viewInfo .chart ) {
50- switch (props .viewInfo .chart . type ) {
52+ switch (props .viewInfo .chart [ ' sourceType ' ] ) {
5153 case ' table' :
5254 break
5355 case ' column' :
@@ -85,14 +87,36 @@ function changeTable() {
8587 onTypeChange (' table' )
8688}
8789
90+ const chartType = computed <ChartTypes >({
91+ get() {
92+ if (currentChartType .value ) {
93+ return currentChartType .value
94+ }
95+ return props .viewInfo .chart [' sourceType' ] ?? ' table'
96+ },
97+ set(v ) {
98+ currentChartType .value = v
99+ },
100+ })
101+
88102function onTypeChange(val : any ) {
103+ chartType .value = val
89104 // eslint-disable-next-line vue/no-mutating-props
90105 props .viewInfo .chart .type = val
91106 nextTick (() => {
107+ // @ts-expect-error eslint-disable-next-line @typescript-eslint/no-unused-expressions
108+ chartRef .value ?.destroyChart ()
92109 // @ts-expect-error eslint-disable-next-line @typescript-eslint/no-unused-expressions
93110 chartRef .value ?.renderChart ()
94111 })
95112}
113+
114+ onMounted (() => {
115+ // eslint-disable-next-line vue/no-mutating-props
116+ props .viewInfo .chart [' sourceType' ] =
117+ props .viewInfo .chart [' sourceType' ] ?? props .viewInfo .chart .type
118+ })
119+
96120defineExpose ({
97121 renderChart ,
98122 enlargeView ,
@@ -111,7 +135,7 @@ defineExpose({
111135 <ChartPopover
112136 v-if =" chartTypeList.length > 0"
113137 :chart-type-list =" chartTypeList"
114- :chart-type =" viewInfo. chartType"
138+ :chart-type =" chartType"
115139 :title =" t('chat.type')"
116140 @type-change =" onTypeChange"
117141 ></ChartPopover >
@@ -137,7 +161,7 @@ defineExpose({
137161 v-if =" viewInfo.id"
138162 :id =" outerId || viewInfo.id"
139163 ref =" chartRef"
140- :type =" viewInfo.chart.type "
164+ :type =" chartType "
141165 :columns =" viewInfo.chart.columns"
142166 :x =" viewInfo.chart?.xAxis"
143167 :y =" viewInfo.chart?.yAxis"
0 commit comments