From f9ffa3b42a98edcb1c901c3ad1fde98c9ad8589a Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期二, 15 十月 2024 10:11:43 +0800
Subject: [PATCH] y轴范围也会影响列表,支持 score,

---
 src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue |  237 ++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 170 insertions(+), 67 deletions(-)

diff --git a/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue b/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue
index 022707c..e0a714b 100644
--- a/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue
+++ b/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue
@@ -5,7 +5,7 @@
 			<!-- TimeRange v-model 璺� @change 涓殑鍊间細涓嶄竴鏍凤紝浠change 涓负鍑� -->
 			<template v-if="visibleParams && visibleParams.length > 0">
 				<component
-					class="flex-0 m-1"
+					class="flex-0 m-2"
 					v-model="paramsValueList[index].value"
 					v-for="(item, index) in visibleParams as any"
 					:key="item.id"
@@ -18,11 +18,24 @@
 				></component>
 			</template>
 			<slot> </slot>
+			<YRange @input="yRangeInput" />
+			<el-tooltip
+				v-if="originChartType === ChartTypeEnum.Score"
+				:content="`${Object.keys(scoreMap)
+					.map((key) => `${key} 琛ㄧず${scoreMap[key]}`)
+					.join(', ')}`"
+				placement="top-start"
+			>
+				<SvgIcon name="fa fa-question-circle-o" :size="15" class="ml-1 cursor-help flex-center" color="#909399" />
+			</el-tooltip>
 
-			<YRange v-model="yRange" @input="yRangeInput" />
-			<el-checkbox class="m-1" v-model="isMultiCompare" label="澶氭棩瀵规瘮" @change="multiCompareChange"></el-checkbox>
+			<el-checkbox class="m-2" v-model="isMultiCompare" label="澶氭棩瀵规瘮" @change="multiCompareChange"></el-checkbox>
+
+			<DisplayMode class="ml-auto" v-model="showMode" @change="displayModeChange" />
 		</div>
-		<div :style="{ height: chartHeight }" v-resize="chartContainerResize" v-loading="chartLoading">
+
+		<RecordSetTable :data="tableData" v-if="tableIsShow" :key="tableKey" />
+		<div v-show="!tableIsShow" :style="{ height: chartHeight }" v-resize="chartContainerResize" v-loading="chartLoading">
 			<div ref="chartRef"></div>
 		</div>
 	</div>
@@ -33,23 +46,23 @@
 import _ from 'lodash';
 import moment from 'moment';
 import type { PropType } from 'vue';
-import { computed, ref } from 'vue';
+import { computed, ref, shallowRef, watch } from 'vue';
 import { SCATTER_SYMBOL_SIZE, getChatChartOption } from '../../../common';
 import { useDrawChatChart } from '../../../hooks/useDrawChatChart';
 import { ChartTypeEnum } from '../../../types';
+import RecordSetTable from '../recordSetTable/RecordSetTable.vue';
+import DisplayMode from './components/DisplayMode.vue';
 import YRange from './components/YRange.vue';
-import type { RecordSet, RecordSetParamsItem } from './types';
+import { DisplayModeType } from './components/types';
+import type { RecordSetParamsItem } from './types';
 import { RecordSetParamsType, recordSetMapCom, scoreMap } from './types';
-import { filterQuery } from '/@/api/ai/chat';
+import { curveQuery } from '/@/api/ai/chat';
+import { axisLabelFormatter } from '/@/utils/chart';
 import { deepClone } from '/@/utils/other';
 import { debounce } from '/@/utils/util';
-import { axisLabelFormatter } from '/@/utils/chart';
-
 const chartRef = ref<HTMLDivElement>(null);
-const yRange = ref({
-	min: null as number,
-	max: null as number,
-});
+
+const showMode = ref(DisplayModeType.Chart);
 // const props = defineProps({
 // 	data: {
 // 		type: Object as PropType<RecordSet>,
@@ -71,37 +84,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;
@@ -117,9 +145,11 @@
 
 let preData = null;
 
-
 let activeChartType: ChartTypeEnum = props.data?.chart_type ?? ChartTypeEnum.Line;
 const originChartType = activeChartType;
+
+// 缁欒〃鏍肩敤鐨� series
+const currentSeries = shallowRef<any[]>(null);
 
 const getChartTypeSeriesOption = (type: ChartTypeEnum) => {
 	let result = {};
@@ -175,15 +205,16 @@
 			};
 		});
 	}
+	currentSeries.value = series;
 	const yAxisFormatter =
-	originChartType === ChartTypeEnum.Score
+		originChartType === ChartTypeEnum.Score
 			? (value) => {
 					return scoreMap[value];
 			  }
 			: axisLabelFormatter;
 
 	const tooltipValueFormatter =
-	originChartType === ChartTypeEnum.Score
+		originChartType === ChartTypeEnum.Score
 			? (value) => {
 					return scoreMap[value];
 			  }
@@ -327,31 +358,29 @@
 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;
@@ -364,20 +393,26 @@
 	if (isMultiCompare.value) {
 		handleMultiCompare();
 	} else {
-		chartInstance.value.setOption({
-			title: {
-				text: title,
-			},
-			series:
-				groupedValues &&
-				Object.keys(groupedValues).map((item) => {
-					const values = groupedValues[item];
-					return {
-						data: values.map((item) => [item[timeIndex], item[valueIndex]]),
-					};
-				}),
-		});
+		(currentSeries.value =
+			groupedValues &&
+			Object.keys(groupedValues).map((item) => {
+				const values = groupedValues[item];
+				return {
+					data: values.map((item) => [item[timeIndex], item[valueIndex]]),
+				};
+			})),
+			chartInstance.value.setOption({
+				title: {
+					text: title,
+				},
+				series: currentSeries.value,
+			});
 	}
+};
+
+let realRange = {
+	min: null,
+	max: null,
 };
 
 const getSingleDayOption = (day = COMMON_DAY) =>
@@ -429,12 +464,12 @@
 	} as echarts.EChartsOption);
 //#region ====================== 璁剧疆Y鑼冨洿 ======================
 const debounceSetYRange = debounce((val) => {
+	(realRange.min = val.min), (realRange.max = val.max);
 	chartInstance.value.setOption({
-		yAxis: {
-			min: val.min,
-			max: val.max,
-		},
+		yAxis: realRange,
 	});
+
+	currentSeries.value = currentSeries.value.concat([]);
 });
 
 const yRangeInput = (val) => {
@@ -487,6 +522,74 @@
 	}
 };
 //#endregion
+//#region ====================== 鍒囨崲鏄剧ず妯″紡 ======================
+
+const tableIsShow = ref(false);
+const displayModeChange = (val: DisplayModeType) => {
+	if (val === DisplayModeType.List) {
+		tableIsShow.value = true;
+	} else {
+		tableIsShow.value = false;
+	}
+};
+
+const tableData = computed(() => {
+	if (!currentSeries.value) return [];
+	const min = realRange.min == null ? -Infinity : realRange.min;
+	const max = realRange.max == null ? Infinity : realRange.max;
+	const timeDataMap = currentSeries.value.reduce((preVal, curVal, index) => {
+		for (const item of curVal.data) {
+			let [time, value] = item;
+			// 澶氭棩瀵规瘮锛屽彧鏄剧ず鏃跺垎绉�
+			if (isMultiCompare.value) {
+				time = time.slice(11);
+			}
+			if (value < min || value > max) {
+				continue;
+			}
+			if (!preVal[time]) {
+				preVal[time] = [];
+			}
+
+			// score 绫诲瀷锛寁alue 鍊硷紝闇�瑕佹槧灏勬垚鍙︿竴涓��
+			if (originChartType === ChartTypeEnum.Score) {
+				value = scoreMap[value];
+			}
+			preVal[time][index] = value;
+		}
+
+		return preVal;
+	}, {});
+
+	const data = Object.keys(timeDataMap).map((item) => [item, ...timeDataMap[item]]);
+	const cols = currentSeries.value.map((item, index) => ({
+		title: item.name ?? `鍊�${index + 1}`,
+		type: 'text',
+	}));
+	cols.unshift({
+		title: '鏃堕棿',
+		type: 'time',
+	});
+	const result = {
+		type: 'recordset',
+		chart: 'table',
+		title: props.data?.title,
+		max_cols: 5,
+		cols: cols,
+		values: data,
+	};
+
+	return result;
+});
+//#endregion
+
+const tableKey = ref('-999');
+watch(
+	() => currentSeries.value,
+	(val) => {
+		tableKey.value = _.random(0, 100000) + '';
+	}
+);
 
 defineExpose({
 	drawChart,

--
Gitblit v1.9.3