From 1476d27514874e9c95002451a81878bd9bec8382 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期六, 14 十二月 2024 15:36:53 +0800
Subject: [PATCH] 多轮对话

---
 src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue |  195 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 126 insertions(+), 69 deletions(-)

diff --git a/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue b/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue
index f45bbc5..6914370 100644
--- a/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue
+++ b/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue
@@ -1,9 +1,9 @@
 <!-- 鏄ㄦ棩渚涙按绠$綉姒傚喌 -->
 <template>
-	<div class="w-full">
-		<div class="flex mb-4 flex-wrap">
+	<div class="w-full flex-column">
+		<div class="flex mb-4 flex-wrap flex-0">
 			<!-- TimeRange v-model 璺� @change 涓殑鍊间細涓嶄竴鏍凤紝浠change 涓负鍑� -->
-			<template v-if="visibleParams && visibleParams.length > 0">
+			<template v-if="visibleParams && visibleParams.length > 0 && showFilter">
 				<component
 					class="flex-0 m-2"
 					v-model="visibleParams[index].value"
@@ -14,7 +14,7 @@
 					:data="item"
 					:originData="originData"
 					@change="(val) => handleQueryChange(val, item)"
-					:disabled="chartLoading"
+					:disabled="chartLoading || disabled"
 				></component>
 			</template>
 			<slot> </slot>
@@ -34,8 +34,20 @@
 			<DisplayMode class="ml-auto" v-model="showMode" @change="displayModeChange" />
 		</div>
 
-		<RecordSetTable :data="tableData" v-if="tableIsShow" :key="tableKey" />
-		<div v-show="!tableIsShow" :style="{ height: chartHeight }" v-resize="chartContainerResize" v-loading="chartLoading">
+		<RecordSetTable
+			:data="tableData"
+			v-if="tableIsShow"
+			:key="tableKey"
+			:tableLimitHeight="tableLimitHeight"
+			:class="{ 'flex-auto': chartHeight == undefined }"
+		/>
+		<div
+			v-show="!tableIsShow"
+			:style="{ height: chartHeight }"
+			:class="{ 'flex-auto': chartHeight == undefined }"
+			v-resize="chartContainerResize"
+			v-loading="chartLoading"
+		>
 			<div ref="chartRef"></div>
 		</div>
 	</div>
@@ -43,7 +55,6 @@
 
 <script setup lang="ts">
 import type * as echarts from 'echarts';
-import _ from 'lodash';
 import moment from 'moment';
 import type { PropType } from 'vue';
 import { computed, ref, shallowRef, watch } from 'vue';
@@ -53,6 +64,7 @@
 import RecordSetTable from '../recordSetTable/RecordSetTable.vue';
 import DisplayMode from './components/DisplayMode.vue';
 import YRange from './components/YRange.vue';
+import { IS_DAY_LIST } from './components/constants';
 import { DisplayModeType } from './components/types';
 import type { RecordSetParamsItem } from './types';
 import { RecordSetParamsType, recordSetMapCom, scoreMap } from './types';
@@ -60,6 +72,7 @@
 import { axisLabelFormatter } from '/@/utils/chart';
 import { deepClone } from '/@/utils/other';
 import { debounce } from '/@/utils/util';
+import { defaultsDeep, groupBy, random } from 'lodash-es';
 const chartRef = ref<HTMLDivElement>(null);
 
 const showMode = ref(DisplayModeType.Chart);
@@ -85,12 +98,24 @@
 	},
 	chartHeight: {
 		type: String,
-		default: '20rem',
+		required: false,
+	},
+	showFilter: {
+		type: Boolean,
+		default: true,
+	},
+	disabled: {
+		type: Boolean,
+		default: false,
 	},
 }) as {
 	data: any;
 	summaryIndex: number;
+	showFilter: Boolean;
 };
+
+const tableLimitHeight = props.chartHeight == undefined ? undefined : document.body.clientHeight * 0.7;
+
 const chartLoading = ref(false);
 
 const stepOptions = [
@@ -160,6 +185,16 @@
 };
 
 const visibleParams = ref(getVisibleParams(props.data));
+
+const checkIsDayTime = () => {
+	if (!props.showFilter) return false;
+	const stepFilter = visibleParams.value.find((item) => item.type === RecordSetParamsType.Step);
+	if (!stepFilter.origin.step_value) return false;
+
+	return IS_DAY_LIST.includes(stepFilter.origin.step_value);
+};
+// 璺ㄥ害鏄惁鏄棩鏈熷舰寮�
+// const isDayTime = checkIsDayTime();
 let groupedValues = null;
 let timeIndex = undefined;
 let valueIndex = undefined;
@@ -253,7 +288,7 @@
 			formatter: yAxisFormatter,
 		},
 	};
-	const combineOption = _.defaultsDeep(
+	const combineOption = defaultsDeep(
 		{
 			grid: {
 				bottom: 20,
@@ -355,7 +390,7 @@
 			nameIndex = 1;
 		}
 		nameCol = data.cols[nameIndex];
-		groupedValues = _.groupBy(data.values, (item) => item[nameIndex]);
+		groupedValues = groupBy(data.values, (item) => item[nameIndex]);
 	} else if (data.chart === 'single_line') {
 		groupedValues = {
 			default: data.values,
@@ -367,7 +402,7 @@
 			nameIndex = 1;
 		}
 		nameCol = data.cols[nameIndex];
-		groupedValues = _.groupBy(data.values, (item) => item[nameIndex]);
+		groupedValues = groupBy(data.values, (item) => item[nameIndex]);
 	}
 };
 
@@ -375,44 +410,88 @@
 	if (!data || !data.cols || !data.values) {
 		return;
 	}
+
 	handleData();
 	setNewOption();
 };
 const { chartContainerResize, chartInstance } = useDrawChatChart({ chartRef, drawChart });
 
-const updateCurrent = (res) => {
+const updateCurrent = (res, isNew = false) => {
 	const title = res?.title;
 	const values = res?.values ?? [];
 	//#region ====================== 鍒锋柊褰撳墠 filter ======================
 	// 鍙洿鏂� value锛屼笉鐩存帴瑕嗙洊锛岄槻姝涪澶卞搷搴旀��
-	updateVisibleParams(res);
+	// updateVisibleParams(res);
 	//#endregion
-	groupedValues = _.groupBy(values, (item) => item[nameIndex]);
+	groupedValues = groupBy(values, (item) => item[nameIndex]);
 	if (isMultiCompare.value) {
 		handleMultiCompare();
 	} else {
-		(currentSeries.value =
-			groupedValues &&
-			Object.keys(groupedValues).map((item, index) => {
-				const values = groupedValues[item];
-				return {
-					name: currentSeries.value[index].name,
-					data: values.map((item) => [item[timeIndex], item[valueIndex]]),
-				};
-			})),
-			chartInstance.value.setOption({
-				title: {
-					text: title,
-				},
-				series: currentSeries.value,
-			});
+		if (isNew) {
+			setNewOption();
+		} else {
+			(currentSeries.value =
+				groupedValues &&
+				Object.keys(groupedValues).map((item, index) => {
+					const values = groupedValues[item];
+					return {
+						name: item === 'default' ? '' : item,
+						data: values.map((item) => [item[timeIndex], item[valueIndex]]),
+					};
+				})),
+				chartInstance.value?.setOption({
+					title: {
+						text: title,
+					},
+					series: currentSeries.value,
+				});
+		}
 	}
 };
 
+const getFilterList = () => {
+	const curAgentKey = props.data.agent_key;
+
+	// 鐩稿悓 agent_key 涓嬫墍鏈� filter 璇锋眰鍙傛暟
+	const filterList = ((props as any).originData?.content?.origin?.summary ?? []).reduce((preVal, curVal) => {
+		if (curVal.agent_key !== curAgentKey) return preVal;
+
+		const filter = (curVal.filter ?? []).reduce((subPreVal, subCurVal) => {
+			if (subCurVal.type === RecordSetParamsType.TimeRange) {
+				subPreVal.push(
+					...[
+						{
+							update: subCurVal.update,
+							value: subCurVal.start_value,
+							path: subCurVal.start_path,
+						},
+						{
+							update: subCurVal.update,
+							value: subCurVal.end_value,
+							path: subCurVal.end_path,
+						},
+					]
+				);
+			} else {
+				subPreVal.push({
+					update: subCurVal.update,
+					value: subCurVal.step_value,
+					path: subCurVal.step_path,
+				});
+			}
+
+			return subPreVal;
+		}, []);
+
+		preVal = preVal.concat(filter);
+
+		return preVal;
+	}, []);
+	return filterList;
+};
 const handleQueryChange = async (val: any, item: RecordSetParamsItem) => {
 	if (!val) return;
 	const historyId = (props as any).originData.historyId;
-	const curAgentKey = props.data.agent_key;
 	let res = null;
 
 	// 鏀瑰彉鍘熷鍊�
@@ -422,42 +501,9 @@
 	} else {
 		item.origin.step_value = val;
 	}
+
+	const filterList = getFilterList();
 	try {
-		// 鐩稿悓 agent_key 涓嬫墍鏈� filter 璇锋眰鍙傛暟
-		const filterList = ((props as any).originData?.content?.origin?.summary ?? []).reduce((preVal, curVal) => {
-			if (curVal.agent_key !== curAgentKey) return preVal;
-
-			const filter = (curVal.filter ?? []).reduce((subPreVal, subCurVal) => {
-				if (subCurVal.type === RecordSetParamsType.TimeRange) {
-					subPreVal.push(
-						...[
-							{
-								update: subCurVal.update,
-								value: subCurVal.start_value,
-								path: subCurVal.start_path,
-							},
-							{
-								update: subCurVal.update,
-								value: subCurVal.end_value,
-								path: subCurVal.end_path,
-							},
-						]
-					);
-				} else {
-					subPreVal.push({
-						update: subCurVal.update,
-						value: subCurVal.step_value,
-						path: subCurVal.step_path,
-					});
-				}
-
-				return subPreVal;
-			}, []);
-
-			preVal = preVal.concat(filter);
-
-			return preVal;
-		}, []);
 		const params = {
 			history_id: historyId,
 			// 鏌ヨ鍓嶅悗 agent_key 涓嶄細鍙�
@@ -554,7 +600,7 @@
 	const seriesData = Object.keys(cloneData).reduce((preVal, curVal, curIndex, arr) => {
 		const values = cloneData[curVal];
 		const isMulti = arr.length > 1;
-		const groupByDateValues = _.groupBy(values, (item) => moment(item[timeIndex]).format('YYYY-MM-DD'));
+		const groupByDateValues = groupBy(values, (item) => moment(item[timeIndex]).format('YYYY-MM-DD'));
 		for (const key in groupByDateValues) {
 			if (Object.prototype.hasOwnProperty.call(groupByDateValues, key)) {
 				const val = groupByDateValues[key];
@@ -626,11 +672,17 @@
 		return preVal;
 	}, {});
 
-	const data = Object.keys(timeDataMap).map((item) => [item, ...timeDataMap[item]]);
+	// 鏃堕棿鏈�鏃╁埌鏈�鏅氭帓搴�
+	const data = Object.keys(timeDataMap)
+		.map((item) => [item, ...timeDataMap[item]])
+		.toSorted((b, a) => {
+			return b[0].localeCompare(a[0]);
+		});
 	const cols = currentSeries.value.map((item, index) => ({
 		title: item.name ?? `鍊�${index + 1}`,
 		type: 'text',
 	}));
+
 	cols.unshift({
 		title: '鏃堕棿',
 		type: 'time',
@@ -643,7 +695,6 @@
 		cols: cols,
 		values: data,
 	};
-
 	return result;
 });
 //#endregion
@@ -652,7 +703,7 @@
 watch(
 	() => currentSeries.value,
 	(val) => {
-		tableKey.value = _.random(0, 100000) + '';
+		tableKey.value = random(0, 100000) + '';
 	}
 );
 
@@ -685,12 +736,18 @@
 	updateCurrent(newSummary);
 };
 
+const updateIndexSummary = (summary) => {
+	updateCurrent(summary?.[props.summaryIndex], true);
+};
+
 defineExpose({
 	drawChart,
 	isMultiCompare,
 	handleMultiCompare,
 	handleData,
 	updateAll,
+
+	updateIndexSummary,
 });
 </script>
 <style scoped lang="scss"></style>

--
Gitblit v1.9.3