From e792d4d46e406da8d0a4ae8ad97db34a95f1c66a Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期一, 10 二月 2025 17:31:08 +0800 Subject: [PATCH] 高亮问题 --- src/components/chat/chatComponents/recordSetCom/RecordSetCom.vue | 206 ++++++++++++++++----------------------------------- 1 files changed, 65 insertions(+), 141 deletions(-) diff --git a/src/components/chat/chatComponents/recordSetCom/RecordSetCom.vue b/src/components/chat/chatComponents/recordSetCom/RecordSetCom.vue index fc29950..6aec4cd 100644 --- a/src/components/chat/chatComponents/recordSetCom/RecordSetCom.vue +++ b/src/components/chat/chatComponents/recordSetCom/RecordSetCom.vue @@ -1,20 +1,12 @@ <template> - <el-tabs v-model="activeName" class="demo-tabs min-w-[38rem] flex-column" @tab-click="handleClick"> + <el-tabs v-model="activeName" class="demo-tabs min-w-[38rem] flex-column"> <el-tab-pane class="h-full" label="Chart" name="first"> - <!-- <el-select class="flex-0 w-36" v-model="selectChartType" @change="selectChartTypeChange"> - <el-option - v-for="item in Object.keys(chartTypeMapName)" - :key="item" - :value="parseInt(item)" - :label="chartTypeMapName[item]" - ></el-option> - </el-select> --> - <div class="flex-auto"> + <div class="flex-auto" v-resize="chartContainerResize"> <div ref="chartRef" class="h-full"></div> </div> </el-tab-pane> <el-tab-pane class="h-full" label="Data" name="second"> - <el-table :data="data.values" style="width: 100%"> + <el-table :data="data.values" style="width: 100%" cellClassName="" headerCellClassName=""> <el-table-column v-for="(item, index) in data?.names" :label="item" :key="index"> <template #default="scope"> {{ scope.row[index] }} @@ -25,150 +17,82 @@ </el-tabs> </template> <script lang="ts" setup> -import * as echarts from 'echarts'; -import type { TabsPaneContext } from 'element-plus'; -import type { PropType } from 'vue'; -import { onMounted, ref } from 'vue'; -import { ChartTypeEnum, chartTypeMapEchart, chartTypeMapName } from '../types'; -import type { RecordSetValues } from '/@/api/ai/chat'; -import { dateRegex } from '/@/utils/toolsValidate'; -import { PATH_ICON, SCATTER_SYMBOL_SIZE, chatComProps, timeDataOptionToContent } from '../common'; +import type * as echarts from 'echarts'; +import { defaultsDeep } from 'lodash-es'; +import { ref } from 'vue'; +import { SCATTER_SYMBOL_SIZE, chatComProps, getChatChartOption } from '../common'; +import { useDrawChatChart } from '../hooks/useDrawChatChart'; const activeName = ref('first'); const chartRef = ref<HTMLDivElement>(null); -const selectChartType = ref<ChartTypeEnum>(ChartTypeEnum.Line); +const defaultChartType = 'line'; const props = defineProps(chatComProps); - -const selectChartTypeChange = () => { - drawChart(); -}; - -const handleClick = (tab: TabsPaneContext, event: Event) => {}; - -let chartInstance: echarts.ECharts = null; - -const getXType = (xData?: any[]) => { - const xValue = xData?.[0]; - if (xValue == null) return 'value'; - if (typeof xValue === 'number') { - return 'value'; - } else if (typeof xValue === 'string') { - const isValidDate = dateRegex.test(xValue); - return isValidDate ? 'time' : 'category'; - } else { - throw '鍥捐〃x杞存暟鎹被鍨嬪紓甯�'; - } -}; - const drawChart = () => { - const xData = props.data.values?.map((item) => item[0]); - const xType = getXType(xData); - chartInstance.setOption({ - grid: { - // bottom: 120, - right: '15%', - bottom: '5%', - }, - tooltip: { - show: true, - trigger: 'axis', - }, - toolbox: { - show: true, - feature: { - dataZoom: { - yAxisIndex: 'none', - }, - myBar: { - title: '杞寲涓烘煴鐘跺浘', - show: true, - icon: PATH_ICON.bar, - onclick: () => { - chartInstance.setOption({ - series: { + chartInstance.value.setOption( + defaultsDeep(getChatChartOption(), { + grid: { + bottom: '5%', + }, + + toolbox: { + feature: { + myBar: { + onclick: () => { + chartInstance.value.setOption({ + series: { + data: props.data.values, + type: 'bar', + symbol: 'none', + }, + }); + }, + }, + + myScatter: { + onclick: () => { + chartInstance.value.setOption({ data: props.data.values, - type: 'bar', + type: 'scatter', + symbol: 'circle', + symbolSize: SCATTER_SYMBOL_SIZE, + }); + }, + }, + myLine: { + onclick: () => { + chartInstance.value.setOption({ + data: props.data.values, + type: 'line', symbol: 'none', - }, - }); + smooth: true, + }); + }, }, }, - - myScatter: { - title: '杞寲涓烘暎鐐瑰浘', - show: true, - icon: PATH_ICON.scatter, - onclick: () => { - chartInstance.setOption({ - data: props.data.values, - type: 'scatter', - symbol: 'circle', - symbolSize: SCATTER_SYMBOL_SIZE, - }); - }, - }, - myLine: { - title: '杞寲涓烘洸绾垮浘', - show: true, - icon: PATH_ICON.line, - onclick: () => { - chartInstance.setOption({ - data: props.data.values, - type: 'line', - symbol: 'none', - smooth: true, - }); - }, - }, - dataView: { - readOnly: true, - optionToContent: timeDataOptionToContent, - }, - saveAsImage: {}, }, - }, - title: { - text: props.data.title, - left: 'center', - }, - xAxis: { - name: props.data?.names[0], - type: xType, - }, - yAxis: { - name: props.data?.names[1], - type: 'value', - }, - series: [ - { - data: props.data.values, - symbol: 'none', - smooth: true, - type: chartTypeMapEchart[selectChartType.value], + title: { + text: props.data.title, }, - ], - dataZoom: { - type: 'inside', - }, - }); + xAxis: { + name: props.data?.names[0], + }, + yAxis: { + name: props.data?.names[1], + }, + series: [ + { + data: props.data.values, + symbol: 'none', + smooth: true, + type: defaultChartType, + }, + ], + } as echarts.EChartsOption) + ); }; - -onMounted(() => { - setTimeout(() => { - const parent = chartRef.value.parentElement; - if (!parent) { - } - const parentBound = parent.getBoundingClientRect(); - chartInstance = echarts.init(chartRef.value, undefined, { - width: parentBound.width, - height: parentBound.height, - }); - - drawChart(); - }, 300); -}); +const { chartContainerResize, chartInstance } = useDrawChatChart({ chartRef, drawChart }); </script> <style scoped lang="scss"> -- Gitblit v1.9.3