11<script setup lang="ts">
22
33import type {ChatMessage } from " @/api/chat.ts" ;
4- import {computed , ref } from " vue" ;
4+ import {computed , nextTick , ref } from " vue" ;
55import type {TabsPaneContext } from ' element-plus'
66import {Loading } from " @element-plus/icons-vue" ;
7+ import Component from " ./component/Component.vue"
78
89const props = defineProps <{
910 message? : ChatMessage
@@ -53,9 +54,22 @@ const chartObject = computed<{
5354 return {}
5455})
5556
56- const currentChartType = ref <" table" | " bar" | " line" | " pie" | undefined >(undefined )
57+ const xAxis = computed (() => {
58+ if (chartObject .value ?.axis ?.x ) {
59+ return [chartObject .value .axis .x ]
60+ }
61+ return []
62+ })
63+ const yAxis = computed (() => {
64+ if (chartObject .value ?.axis ?.y ) {
65+ return [chartObject .value .axis .y ]
66+ }
67+ return []
68+ })
5769
58- const chartType = computed <" table" | " bar" | " line" | " pie" >({
70+ const currentChartType = ref <" table" | " bar" | ' column' | " line" | " pie" | undefined >(undefined )
71+
72+ const chartType = computed <" table" | " bar" | ' column' | " line" | " pie" >({
5973 get() {
6074 if (currentChartType .value ) {
6175 return currentChartType .value
@@ -67,19 +81,30 @@ const chartType = computed<"table" | "bar" | "line" | "pie">({
6781 }
6882})
6983
84+ const chartRef = ref ()
85+
86+ function onTypeChange(type : string ) {
87+ console .log (type )
88+ nextTick (()=> {
89+ chartRef .value ?.destroyChart ()
90+ chartRef .value ?.renderChart ()
91+ })
92+ }
93+
7094
7195 </script >
7296
7397<template >
74- <div v-if =" message" >
75- <div >
76- <div v-if =" message.isTyping" >Thinking ...</div >
77- <div v-if =" chartObject.title && !message.isTyping" >{{ chartObject.title }}</div >
78- <el-tabs v-model =" settings.type" class =" demo -tabs" @tab-click =" handleClick" tab-position =" top" >
98+ <el-container v-if =" message" >
99+ <el-header style = " display : flex ; align-items : center ; flex-direction : row ; " >
100+ <div style = " flex : 1 " v-if =" message.isTyping" >Thinking ...</div >
101+ <div style = " flex : 1 " v-if =" chartObject.title && !message.isTyping" >{{ chartObject.title }}</div >
102+ <el-tabs v-model =" settings.type" class =" type -tabs" @tab-click =" handleClick" tab-position =" top" >
79103 <el-tab-pane label =" Chart" name =" chart" >
80104 <template #label >
81- <el-select v-model =" chartType" style =" width : 80px " :disabled =" settings.type!== 'chart'" >
105+ <el-select v-model =" chartType" style =" width : 80px " :disabled =" settings.type!== 'chart'" @change = " onTypeChange " >
82106 <el-option value =" table" >table</el-option >
107+ <el-option value =" cloumn" >cloumn</el-option >
83108 <el-option value =" bar" >bar</el-option >
84109 <el-option value =" line" >line</el-option >
85110 <el-option value =" pie" >pie</el-option >
@@ -88,59 +113,61 @@ const chartType = computed<"table" | "bar" | "line" | "pie">({
88113 </el-tab-pane >
89114 <el-tab-pane label =" SQL" name =" sql" ></el-tab-pane >
90115 </el-tabs >
91- </div >
92- <template v-if =" message .record " >
93- <el-collapse expand-icon-position =" left" >
94- <el-collapse-item name =" 1" >
95- <template #title >
96- Inference process
97- <el-icon v-if =" props.message?.isTyping" >
98- <Loading />
99- </el-icon >
100- </template >
101- <div >
102- <template v-if =" message .record .sql_answer " >
103- <div >SQL Generation:</div >
104- <div v-if =" message.record.sql_answer" v-html =" renderSqlThinking" ></div >
105- </template >
106- <template v-if =" message .record .chart_answer " >
107- <el-divider ></el-divider >
108- <div >Chart Generation:</div >
109- <div v-html =" renderChartThinking" ></div >
116+ </el-header >
117+ <el-container direction =" vertical" >
118+ <template v-if =" message .record " >
119+ <el-collapse expand-icon-position =" left" >
120+ <el-collapse-item name =" 1" >
121+ <template #title >
122+ Inference process
123+ <el-icon v-if =" props.message?.isTyping" >
124+ <Loading />
125+ </el-icon >
110126 </template >
111- </div >
112- </el-collapse-item >
113- </el-collapse >
114- <div class =" answer-content" >
115- <template v-if =" settings .type === ' sql' " >
116- <div >
117- <div v-if =" message.record.sql" >
118- {{ message.record.sql }}
127+ <div >
128+ <template v-if =" message .record .sql_answer " >
129+ <div >SQL Generation:</div >
130+ <div v-if =" message.record.sql_answer" v-html =" renderSqlThinking" ></div >
131+ </template >
132+ <template v-if =" message .record .chart_answer " >
133+ <el-divider ></el-divider >
134+ <div >Chart Generation:</div >
135+ <div v-html =" renderChartThinking" ></div >
136+ </template >
119137 </div >
120- </div >
121- </template >
122- <template v-else-if =" settings .type === ' chart' " >
123- <div >
124-
125- <div v-if =" message.record.chart" >
126- {{ chartObject }}
138+ </el-collapse-item >
139+ </el-collapse >
140+ <div class =" answer-content" >
141+ <template v-if =" settings .type === ' sql' " >
142+ <div >
143+ <div v-if =" message.record.sql" >
144+ {{ message.record.sql }}
145+ </div >
146+ </div >
147+ </template >
148+ <template v-else-if =" settings .type === ' chart' " >
149+ <div >
150+ <div v-if =" message.record.chart" >
151+ <Component
152+ ref =" chartRef"
153+ v-if =" message.record.id"
154+ :id =" message.record.id"
155+ :type =" chartType"
156+ :columns =" chartObject?.columns"
157+ :x =" xAxis"
158+ :y =" yAxis"
159+ :data =" dataObject.data" />
160+ </div >
127161 </div >
128- </div >
129- <div v-if =" message.record.error" style =" color : red " >
130- {{ message.record.error }}
131- </div >
132- </template >
133- <template v-else >
134- <div >
135- <div v-if =" dataObject.fields" >
136- {{ dataObject.fields }}
137- {{ dataObject.data }}
162+ <div v-if =" message.record.error" style =" color : red " >
163+ {{ message.record.error }}
138164 </div >
139- </div >
140- </template >
141- </div >
142- </template >
143- </div >
165+ </template >
166+ </div >
167+ </template >
168+ </el-container >
169+ <!-- <el-footer></el-footer>-->
170+ </el-container >
144171</template >
145172
146173<style scoped lang="less">
@@ -152,4 +179,8 @@ const chartType = computed<"table" | "bar" | "line" | "pie">({
152179.answer-content {
153180 padding : 12px ;
154181}
182+
183+ .type-tabs {
184+ margin-right : 24px ;
185+ }
155186 </style >
0 commit comments