From 6a475521b957b2c3a68ee950704f8f1948bd6cf9 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期四, 09 一月 2025 18:28:59 +0800 Subject: [PATCH] 最新值查询修改 --- src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue | 179 ++++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 109 insertions(+), 70 deletions(-) diff --git a/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue b/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue index 4e4d1d5..23bd8e5 100644 --- a/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue +++ b/src/components/chat/chatComponents/summaryCom/components/recordSet/RecordSet.vue @@ -14,7 +14,7 @@ :data="item" :originData="originData" @change="(val) => handleQueryChange(val, item)" - :disabled="chartLoading ||disabled" + :disabled="chartLoading || disabled" ></component> </template> <slot> </slot> @@ -55,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'; @@ -65,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'; @@ -72,7 +72,7 @@ import { axisLabelFormatter } from '/@/utils/chart'; import { deepClone } from '/@/utils/other'; import { debounce } from '/@/utils/util'; -import { IS_DAY_LIST } from './components/constants'; +import { defaultsDeep, groupBy, random } from 'lodash-es'; const chartRef = ref<HTMLDivElement>(null); const showMode = ref(DisplayModeType.Chart); @@ -100,21 +100,28 @@ type: String, required: false, }, + tableHeight:{ + type:Number, + default:document.body.clientHeight * 0.7, + }, showFilter: { type: Boolean, default: true, }, - disabled:{ - type:Boolean, - default:false, - } -}) as { - data: any; - summaryIndex: number; - showFilter: Boolean; -}; + disabled: { + type: Boolean, + default: false, + }, + reportIndex:{ + type: Number, + default: 0, + }, + historyId: { + type: String, + }, +}); -const tableLimitHeight = props.chartHeight == undefined ? undefined : document.body.clientHeight * 0.7; +const tableLimitHeight = props.chartHeight == undefined ? undefined : props.tableHeight; const chartLoading = ref(false); @@ -129,6 +136,7 @@ const getVisibleParams = (data) => { // const visibleList = props.data?.params?.filter((item) => !item?.hide) ?? []; // index 浣滀负 id + const dataFilter = data?.filter ?? []; const visibleList = (data?.filter ?? []).map((item, index) => { // 涓嶄慨鏀瑰師濮嬪湴鍧� item.id = index + ''; @@ -183,7 +191,6 @@ } }); }; - const visibleParams = ref(getVisibleParams(props.data)); const checkIsDayTime = () => { @@ -260,7 +267,11 @@ const values = groupedValues[item]; return { name: item === 'default' ? '' : item, - data: values.map((item) => [item[timeIndex], item[valueIndex]]), + data: values + .map((item) => [item[timeIndex], item[valueIndex]]) + .toSorted((b, a) => { + return b[timeIndex].localeCompare(a[timeIndex]); + }), ...getChartTypeSeriesOption(activeChartType), }; }); @@ -273,12 +284,12 @@ } : axisLabelFormatter; - const tooltipValueFormatter = - originChartType === ChartTypeEnum.Score - ? (value) => { - return scoreMap[value]; - } - : undefined; + + + const tooltipValueFormatter = (value) => { + const realValue = originChartType === ChartTypeEnum.Score ? scoreMap[value] : value; + return realValue + (props.data.unit ? ` ${props.data.unit}` : ''); + }; const scoreYAxisOption: echarts.YAXisComponentOption = { min: 0, @@ -288,7 +299,7 @@ formatter: yAxisFormatter, }, }; - const combineOption = _.defaultsDeep( + const combineOption = defaultsDeep( { grid: { bottom: 20, @@ -349,7 +360,8 @@ name: timeCol?.title, }, yAxis: { - name: valueCol?.title, + name: props.data.unit ? `${props.data.unit}` : valueCol?.title, + /** @description 涓嶅己鍒朵繚鐣� */ scale: true, ...(originChartType === ChartTypeEnum.Score ? scoreYAxisOption : {}), @@ -390,7 +402,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, @@ -402,7 +414,7 @@ nameIndex = 1; } nameCol = data.cols[nameIndex]; - groupedValues = _.groupBy(data.values, (item) => item[nameIndex]); + groupedValues = groupBy(data.values, (item) => item[nameIndex]); } }; @@ -410,6 +422,7 @@ if (!data || !data.cols || !data.values) { return; } + handleData(); setNewOption(); }; @@ -422,7 +435,7 @@ // 鍙洿鏂� value锛屼笉鐩存帴瑕嗙洊锛岄槻姝涪澶卞搷搴旀�� // updateVisibleParams(res); //#endregion - groupedValues = _.groupBy(values, (item) => item[nameIndex]); + groupedValues = groupBy(values, (item) => item[nameIndex]); if (isMultiCompare.value) { handleMultiCompare(); } else { @@ -435,7 +448,11 @@ const values = groupedValues[item]; return { name: item === 'default' ? '' : item, - data: values.map((item) => [item[timeIndex], item[valueIndex]]), + data: values + .map((item) => [item[timeIndex], item[valueIndex]]) + .toSorted((b, a) => { + return b[timeIndex].localeCompare(a[timeIndex]); + }), }; })), chartInstance.value?.setOption({ @@ -448,10 +465,49 @@ } }; +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; + const historyId = props.historyId; let res = null; // 鏀瑰彉鍘熷鍊� @@ -461,47 +517,15 @@ } 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 涓嶄細鍙� agent_key: props.data.agent_key, filter_json: JSON.stringify(filterList), + result_group_index: props.reportIndex, }; res = await curveQuery(params); chartLoading.value = true; @@ -593,7 +617,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]; @@ -612,7 +636,11 @@ }, []); const series = seriesData.map<echarts.SeriesOption>((item) => ({ name: item[0]?.[nameIndex], - data: item.map((item) => [item[timeIndex], item[valueIndex]]), + data: item + .map((item) => [item[timeIndex], item[valueIndex]]) + .toSorted((b, a) => { + return b[timeIndex].localeCompare(a[timeIndex]); + }), ...getChartTypeSeriesOption(activeChartType), })); setNewOption(series, getSingleDayOption()); @@ -665,11 +693,23 @@ 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 getColName = (name) => { + if (props.data.unit) { + return `${name}锛�${props.data.unit}锛塦; + } + return name; + } const cols = currentSeries.value.map((item, index) => ({ - title: item.name ?? `鍊�${index + 1}`, + title: getColName(item.name ?? `鍊�${index + 1}`), type: 'text', })); + cols.unshift({ title: '鏃堕棿', type: 'time', @@ -682,7 +722,6 @@ cols: cols, values: data, }; - return result; }); //#endregion @@ -691,7 +730,7 @@ watch( () => currentSeries.value, (val) => { - tableKey.value = _.random(0, 100000) + ''; + tableKey.value = random(0, 100000) + ''; } ); -- Gitblit v1.9.3