From 3c8ba56f8ea1950067fac67f378e0e87bec3a23e Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 14 十月 2024 13:35:34 +0800
Subject: [PATCH] 曲线查询更改

---
 src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue |  301 +++++++++++++++++++++++++++++--------------------
 1 files changed, 178 insertions(+), 123 deletions(-)

diff --git a/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue b/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue
index 52a8709..3c5d8fc 100644
--- a/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue
+++ b/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue
@@ -1,3 +1,4 @@
+<!-- 鏄ㄦ棩渚涙按绠$綉姒傚喌 -->
 <template>
 	<div class="w-full">
 		<div class="flex mb-4 flex-wrap">
@@ -35,16 +36,16 @@
 import { computed, ref } from 'vue';
 import { SCATTER_SYMBOL_SIZE, getChatChartOption } from '../../../common';
 import { useDrawChatChart } from '../../../hooks/useDrawChatChart';
+import { ChartTypeEnum } from '../../../types';
 import YRange from './components/YRange.vue';
-import type { RecordSet, RecordSetParamsItem } from './types';
-import { RecordSetParamsType, recordSetMapCom } from './types';
-import { filterQuery } from '/@/api/ai/chat';
+import type { RecordSetParamsItem } from './types';
+import { RecordSetParamsType, recordSetMapCom, scoreMap } from './types';
+import { curveQuery } from '/@/api/ai/chat';
+import { axisLabelFormatter } from '/@/utils/chart';
 import { deepClone } from '/@/utils/other';
 import { debounce } from '/@/utils/util';
-import { ChartTypeEnum } from '../../../types';
 
 const chartRef = ref<HTMLDivElement>(null);
-const defaultDisplayType = 'line';
 const yRange = ref({
 	min: null as number,
 	max: null as number,
@@ -70,37 +71,52 @@
 		default: '20rem',
 	},
 }) as {
-	data: RecordSet;
+	data: any;
 };
 const chartLoading = ref(false);
 
+const stepOptions = [
+	{ title: '5鍒嗛挓', value: '5 minutes' },
+	{ title: '10鍒嗛挓', value: '10 minutes' },
+	{ title: '鍗婂皬鏃�', value: '30 minutes' },
+	{ title: '1灏忔椂', value: '1 hours' },
+	{ title: '1澶�', value: '1 days' },
+];
+
 const visibleParams = computed(() => {
-	const visibleList = props.data?.params?.filter((item) => !item?.hide) ?? [];
-
+	// const visibleList = props.data?.params?.filter((item) => !item?.hide) ?? [];
+	// index 浣滀负 id
+	const visibleList = (props.data?.filter ?? []).map((item, index) => ({
+		id: index + '',
+		...item,
+	}));
 	const newList: RecordSetParamsItem[] = [];
-	let nextMatchIndex = null;
 	for (let index = 0; index < visibleList.length; index++) {
-		if (nextMatchIndex === index) continue;
 		const current = visibleList[index];
-		const currentAny = current as any;
-		if (index !== visibleList.length - 1 && currentAny.type === RecordSetParamsType.StartTime) {
-			const next = visibleList[index + 1];
-			const nextAny = next as any;
-
-			if (nextAny.group === currentAny.group && nextAny.type === RecordSetParamsType.EndTime) {
+		switch (current.type) {
+			case RecordSetParamsType.TimeRange:
 				newList.push({
+					id: current.id,
 					type: RecordSetParamsType.TimeRange,
-					value: [currentAny.value, nextAny.value],
-					group: currentAny.group,
-					range: [currentAny, nextAny],
-				} as any);
-				nextMatchIndex = index + 1;
-			} else {
-				newList.push(current);
-			}
-		} else {
-			newList.push(current);
+					origin: current,
+					value: [current.start_value, current.end_value],
+					title: current.title,
+				});
+				break;
+			case RecordSetParamsType.Step:
+				newList.push({
+					id: current.id,
+					type: RecordSetParamsType.Step,
+					origin: current,
+					value: current.value,
+					list: stepOptions,
+					title: current.title,
+				});
+				break;
+			default:
+				break;
 		}
+		Reflect.deleteProperty(current,'id')
 	}
 
 	return newList;
@@ -116,7 +132,8 @@
 
 let preData = null;
 
-let activeChartType: ChartTypeEnum = ChartTypeEnum.Line;
+let activeChartType: ChartTypeEnum = props.data?.chart_type ?? ChartTypeEnum.Line;
+const originChartType = activeChartType;
 
 const getChartTypeSeriesOption = (type: ChartTypeEnum) => {
 	let result = {};
@@ -145,6 +162,14 @@
 			};
 
 			break;
+		case ChartTypeEnum.Score:
+			result = {
+				type: 'bar',
+				symbol: 'none',
+			};
+
+			break;
+
 		default:
 			break;
 	}
@@ -160,75 +185,103 @@
 			return {
 				name: item === 'default' ? '' : item,
 				data: values.map((item) => [item[timeIndex], item[valueIndex]]),
-				type: defaultDisplayType,
-				symbol: 'none',
-				smooth: true,
+				...getChartTypeSeriesOption(activeChartType),
 			};
 		});
 	}
-	const combineOption = _.defaultsDeep(extraOption, getChatChartOption(), {
-		grid: {
-			bottom: 20,
-		},
-		legend: {
-			top: 19,
-			show: series?.length > 1,
-			type: 'scroll',
-		},
-		toolbox: {
-			show: true,
-			feature: {
-				myBar: {
-					onclick: () => {
-						activeChartType = ChartTypeEnum.Bar;
-						chartInstance.value.setOption({
-							series: series.map((item) => ({
-								...item,
-								...getChartTypeSeriesOption(activeChartType),
-							})),
-						});
-					},
-				},
+	const yAxisFormatter =
+		originChartType === ChartTypeEnum.Score
+			? (value) => {
+					return scoreMap[value];
+			  }
+			: axisLabelFormatter;
 
-				myScatter: {
-					onclick: () => {
-						activeChartType = ChartTypeEnum.Scatter;
+	const tooltipValueFormatter =
+		originChartType === ChartTypeEnum.Score
+			? (value) => {
+					return scoreMap[value];
+			  }
+			: undefined;
 
-						chartInstance.value.setOption({
-							series: series.map((item) => ({
-								...item,
-								...getChartTypeSeriesOption(activeChartType),
-							})),
-						});
+	const scoreYAxisOption: echarts.YAXisComponentOption = {
+		min: 0,
+		max: 4,
+		interval: 1,
+		axisLabel: {
+			formatter: yAxisFormatter,
+		},
+	};
+	const combineOption = _.defaultsDeep(
+		{
+			grid: {
+				bottom: 20,
+			},
+			legend: {
+				top: 19,
+				show: true,
+				type: 'scroll',
+			},
+			tooltip: {
+				valueFormatter: tooltipValueFormatter,
+			},
+			toolbox: {
+				show: true,
+				feature: {
+					myBar: {
+						onclick: () => {
+							activeChartType = originChartType === ChartTypeEnum.Score ? ChartTypeEnum.Score : ChartTypeEnum.Bar;
+							chartInstance.value.setOption({
+								series: series.map((item) => ({
+									...item,
+									...getChartTypeSeriesOption(activeChartType),
+								})),
+							});
+						},
 					},
-				},
-				myLine: {
-					onclick: () => {
-						activeChartType = ChartTypeEnum.Line;
-						chartInstance.value.setOption({
-							series: series.map((item) => ({
-								...item,
-								...getChartTypeSeriesOption(activeChartType),
-							})),
-						});
+
+					myScatter: {
+						onclick: () => {
+							activeChartType = ChartTypeEnum.Scatter;
+
+							chartInstance.value.setOption({
+								series: series.map((item) => ({
+									...item,
+									...getChartTypeSeriesOption(activeChartType),
+								})),
+							});
+						},
+					},
+					myLine: {
+						onclick: () => {
+							activeChartType = ChartTypeEnum.Line;
+							chartInstance.value.setOption({
+								series: series.map((item) => ({
+									...item,
+									...getChartTypeSeriesOption(activeChartType),
+								})),
+							});
+						},
 					},
 				},
 			},
-		},
 
-		title: {
-			text: preData?.title,
-		},
-		xAxis: {
-			name: timeCol?.title,
-		},
-		yAxis: {
-			name: valueCol?.title,
-			/** @description 涓嶅己鍒朵繚鐣�0 */
-			scale: true,
-		},
-		series: series,
-	} as echarts.EChartsOption);
+			title: {
+				text: preData?.title,
+			},
+			xAxis: {
+				name: timeCol?.title,
+			},
+			yAxis: {
+				name: valueCol?.title,
+				/** @description 涓嶅己鍒朵繚鐣� */
+				scale: true,
+				...(originChartType === ChartTypeEnum.Score ? scoreYAxisOption : {}),
+			},
+			series: series,
+		} as echarts.EChartsOption,
+		extraOption,
+		getChatChartOption()
+	);
 	chartInstance.value.setOption(combineOption, {
 		notMerge: true,
 	});
@@ -288,31 +341,30 @@
 const { chartContainerResize, chartInstance } = useDrawChatChart({ chartRef, drawChart });
 
 // 鏇存崲鍒楄〃
-const changeMap = new Map<string, string>(null);
-
+const changeMap = new Map<string, any>(null);
 const handleQueryChange = async (val: any, item: RecordSetParamsItem) => {
 	if (!val) return;
-
 	const historyId = (props as any).originData.historyId;
-	const summaryIndex = (props as any).summaryIndex;
 	let res = null;
 
 	try {
 		if (item.type === RecordSetParamsType.TimeRange) {
-			changeMap.set(item.range[0].id, val[0]), changeMap.set(item.range[1].id, val[1]);
+			item.origin.start_value = val[0];
+			item.origin.end_value = val[1];
+			changeMap.set(item.id, item.origin);
 		} else {
-			changeMap.set(item.id, val);
+			item.origin.value = val;
+			changeMap.set(item.id, item.origin);
 		}
-		const paramsObj = {};
-		for (const [key, value] of changeMap) {
-			paramsObj[key] = value;
-		}
+
+
+		const filterObj = Array.from(changeMap.values());
 		const params = {
 			history_id: historyId,
-			query_index: summaryIndex,
-			param_json: JSON.stringify(paramsObj),
+			agent_key: props.data.agent_key,
+			filter_json: JSON.stringify(filterObj),
 		};
-		res = await filterQuery(params);
+		res = await curveQuery(params);
 		chartLoading.value = true;
 	} finally {
 		chartLoading.value = false;
@@ -341,24 +393,27 @@
 	}
 };
 
-const getSingleDayOption = (day=COMMON_DAY) => ({
-	tooltip: {
-		show: true,
-		trigger: 'axis',
-		formatter(params) {
-			const itemList = params.map((item, index) => {
-				return `<div style="margin: ${index === 0 ? 0 : 10}px 0 0; line-height: 1">
+const getSingleDayOption = (day = COMMON_DAY) =>
+	({
+		tooltip: {
+			show: true,
+			trigger: 'axis',
+			formatter(params) {
+				const itemList = params.map((item, index) => {
+					return `<div style="margin: ${index === 0 ? 0 : 10}px 0 0; line-height: 1">
 				<div style="margin: 0px 0 0; line-height: 1">
 					${item.marker}<span style="font-size: 14px; color: #666; font-weight: 400; margin-left: 2px"
 						>${item.seriesName}</span
-					><span style="float: right; margin-left: 20px; font-size: 14px; color: #666; font-weight: 900">${item.data[1]}</span>
+					><span style="float: right; margin-left: 20px; font-size: 14px; color: #666; font-weight: 900">${
+						originChartType === ChartTypeEnum.Score ? scoreMap[item.data[1]] : item.data[1]
+					}</span>
 					<div style="clear: both"></div>
 				</div>
 				<div style="clear: both"></div>
 			</div>`;
-			});
+				});
 
-			const result = `<div style="margin: 0px 0 0; line-height: 1">
+				const result = `<div style="margin: 0px 0 0; line-height: 1">
 				<div style="margin: 0px 0 0; line-height: 1">
 					<div style="font-size: 14px; color: #666; font-weight: 400; line-height: 1">${params?.[0]?.data[0]?.slice(10, 16)}</div>
 					<div style="margin: 10px 0 0; line-height: 1">
@@ -369,22 +424,22 @@
 				</div>
 				<div style="clear: both"></div>
 			</div>`;
-			return result;
-		},
-	},
-	xAxis: {
-		min: day + ' 00:00:00',
-		max: day + ' 23:59:59',
-		splitNumber: 10,
-		axisLabel: {
-			formatter: (val) => {
-				const newVal = moment(val).format('HH:mm');
-				return newVal;
+				return result;
 			},
-			showMaxLabel: true,
 		},
-	},
-} as echarts.EChartsOption);
+		xAxis: {
+			min: day + ' 00:00:00',
+			max: day + ' 23:59:59',
+			splitNumber: 10,
+			axisLabel: {
+				formatter: (val) => {
+					const newVal = moment(val).format('HH:mm');
+					return newVal;
+				},
+				showMaxLabel: true,
+			},
+		},
+	} as echarts.EChartsOption);
 //#region ====================== 璁剧疆Y鑼冨洿 ======================
 const debounceSetYRange = debounce((val) => {
 	chartInstance.value.setOption({

--
Gitblit v1.9.3