Skip to content

Commit d0406a1

Browse files
committed
refactor: dashboard support change view type
1 parent 5e6656e commit d0406a1

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

frontend/src/views/dashboard/components/sq-view/index.vue

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import ChartComponent from '@/views/chat/component/ChartComponent.vue'
33
import icon_window_mini_outlined from '@/assets/svg/icon_window-mini_outlined.svg'
44
import SqViewDisplay from '@/views/dashboard/components/sq-view/index.vue'
5+
import _ from 'lodash'
56
const 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'
2324
import { useI18n } from 'vue-i18n'
2425
import ChartPopover from '@/views/chat/chat-block/ChartPopover.vue'
2526
import ICON_TABLE from '@/assets/svg/chart/icon_form_outlined.svg'
@@ -34,8 +35,9 @@ const currentChartType = ref<ChartTypes | undefined>(undefined)
3435
3536
const 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
4143
const enlargeDialogVisible = ref(false)
@@ -47,7 +49,7 @@ const enlargeView = () => {
4749
const 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+
88102
function 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+
96120
defineExpose({
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"

frontend/src/views/dashboard/editor/Toolbar.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ const backToMain = () => {
136136
137137
const addChatChart = (views: any) => {
138138
views.forEach((view: any) => {
139-
emits('addComponent', 'SQView', cloneDeep(view))
139+
const target = cloneDeep(view)
140+
delete target.chart.sourceType
141+
emits('addComponent', 'SQView', target)
140142
})
141143
ElMessage({
142144
type: 'success',

0 commit comments

Comments
 (0)