From c3cb967255a394a1f5eb4fc2213d45fb81c2be02 Mon Sep 17 00:00:00 2001 From: Befend <18814382464@163.com> Date: Sun, 16 Mar 2025 11:20:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=85=BB=E6=8A=A4?= =?UTF-8?q?=E5=92=8C=E9=98=B2=E6=B2=BB=E7=9A=84tab=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/dike/index.ts | 12 + src/utils/echartsUtils.ts | 252 +++++++++++ .../Main/Dike/components/DataStatistics.vue | 2 +- .../Dike/components/PestAnimalAnalysis.vue | 406 ++++++++++++++++++ .../Dike/components/StatisticsAnalysis.vue | 406 ++++++++++++++++++ src/views/Main/Dike/index.vue | 15 +- .../Reservoir/components/DataStatistics.vue | 2 +- src/views/Main/Reservoir/index.vue | 2 +- .../Main/Sluice/components/DataStatistics.vue | 2 +- .../Sluice/components/StatisticsAnalysis.vue | 406 ++++++++++++++++++ src/views/Main/Sluice/index.vue | 12 +- src/views/Main/index.vue | 18 +- 12 files changed, 1514 insertions(+), 21 deletions(-) create mode 100644 src/utils/echartsUtils.ts create mode 100644 src/views/Main/Dike/components/PestAnimalAnalysis.vue create mode 100644 src/views/Main/Dike/components/StatisticsAnalysis.vue create mode 100644 src/views/Main/Sluice/components/StatisticsAnalysis.vue diff --git a/src/api/dike/index.ts b/src/api/dike/index.ts index 3dab396..9f52c83 100644 --- a/src/api/dike/index.ts +++ b/src/api/dike/index.ts @@ -97,3 +97,15 @@ export function exportSwtz(query: any) { } }); } + +// 获取巡查统计分析数据/run/statistic/chart +export function getV2PatrolStatisticChart(data: any) { + return request({ + url: `/run/statistic/chart`, + method: "post", + data, + headers: { + shuili: 'water ' + shuili + } + }); +} \ No newline at end of file diff --git a/src/utils/echartsUtils.ts b/src/utils/echartsUtils.ts new file mode 100644 index 0000000..ca3c3d4 --- /dev/null +++ b/src/utils/echartsUtils.ts @@ -0,0 +1,252 @@ +// 通用接口结构,渲染折线图或柱形图 +export const initCommonBarLineOptions = ({ + data = {} as any, + type = "line" as any, + colors = ["#36b29e", "#29CCCC", "#0099df", "#81b84a"] as any, + seriesOptions = {} as any, +}) => { + const { markLine, xaxis, yaxis } = data as any; + let series: any = []; + let yAxis: any = []; + if (yaxis && yaxis.length) { + yAxis = yaxis.map((v: any) => { + return { + type: "value", + name: `${v.name}(${v.unit})`, + nameLocation: "end", + }; + }); + yaxis.forEach((v: any, i: any) => { + if (v.series?.length) { + v.series.forEach((v2: any) => { + series.push({ + type: type || "line", + smooth: true, + yAxisIndex: i, + name: v2.name, + data: v2.data, + ...seriesOptions, + }); + }); + } + }); + } + + if (markLine && markLine.length && series.length) { + let seriesItem = series.find((v: any) => v.yAxisIndex === 1) || series[0]; + let markLineData = markLine.map((v: any, i: any) => { + return { + name: v.name, + yAxis: v.value, + label: { + color: colors[i] || "red", + }, + lineStyle: { + color: colors[i] || "red", + }, + }; + }); + seriesItem.markLine = { + symbol: "none", + label: { + show: true, + position: "insideEndTop", + formatter: "{b}", + }, + lineStyle: { + width: 2, + type: "solid", + color: colors[0] || "red", + }, + data: markLineData, + }; + } + + return { + color: colors, + title: { + // text: "统计", + }, + legend: { + orient: "horizontal", + top: "2%", + }, + grid: { + left: "5%", + right: "10%", + bottom: "10%", + top: "20%", + containLabel: true, + }, + tooltip: { + trigger: "axis", + axisPointer: { + type: "cross", + label: { + backgroundColor: "#283b56", + }, + }, + }, + xAxis: [ + { + type: "category", + name: "", + position: "bottom", + axisLine: { + onZero: false, + show: true, + }, + axisTick: { + alignWithLabel: true, + }, + data: xaxis || [], + }, + ], + yAxis: yAxis, + series: series, + }; +}; +// 通用接口结构,渲染饼图环形图 +export const initCommonPieRingOptions = ({ + data = {} as any, + colors = ["#36b29e", "#29CCCC", "#0099df", "#81b84a"] as any, + seriesOptions = {} as any, +}) => { + const { title, yaxis } = data as any; + let series: any = []; + let currentSum: any = 0; + if (yaxis && yaxis.length) { + let newSeries = yaxis.flatMap((v: any) => v.series); + let data = newSeries.map((v: any) => { + currentSum += Number(v.sum ?? null); + return { + name: v.name, + value: v.sum, + }; + }); + series.push({ + type: "pie", + center: ["50%", "50%"], + radius: ["55%", "65%"], + name: title, + data: data, + label: { + show: false, + }, + ...seriesOptions, + }); + } + return { + color: colors, + title: { + text: currentSum, + top: "center", + left: "center", + textStyle: { + fontSize: 16, + fontWeight: "bold", + }, + subtext: title, + subtextStyle: { + fontSize: 12, + }, + }, + tooltip: { + trigger: "item", + }, + legend: { + orient: "horizontal", + top: "2%", + }, + grid: { + left: "10%", + right: "10%", + bottom: "10%", + top: "30%", + }, + series: series, + }; +}; +// 极坐标 +export const initCommonAngleAxisOptions = ({ + data = {} as any, + colors = ["#36b29e", "#29CCCC", "#0099df", "#81b84a"] as any, + seriesOptions = {} as any, +}) => { + const { title, yaxis } = data as any; + let radiusAxisData: any = []; + let seriesData: any = []; + let maxVal = 0; + if (yaxis && yaxis.length) { + let newSeries = yaxis.flatMap((v: any) => v.series); + newSeries.forEach((v: any, i: any) => { + radiusAxisData.push(v.name); + seriesData.push({ + value: Number(v.sum ?? null), + itemStyle: { + color: colors[i], + }, + }); + }); + // 设置这个极坐标的最大值,防止占满 + maxVal = Math.max(...newSeries.map((v: any) => Number(v.sum ?? null))) * 1.25; + } + return { + color: colors, + title: [ + { + show: false, + text: title || "", + }, + ], + polar: { + radius: ["50%", "80%"], + }, + angleAxis: { + max: maxVal, + startAngle: 90, + axisLine: { + show: false, + }, + axisTick: { + show: false, + }, + axisLabel: { + show: false, + }, + splitLine: { + show: false, + }, + }, + radiusAxis: { + show: true, + zlevel: 10, + type: "category", + data: radiusAxisData, + axisLabel: { + interval: 0, // 强制显示所有标签 + }, + axisTick: { + show: false, + }, + axisLine: { + show: false, + }, + splitLine: { + show: false, + }, + }, + tooltip: {}, + series: { + type: "bar", + data: seriesData, + coordinateSystem: "polar", + label: { + show: false, + position: "middle", + formatter: "{b}: {c}", + }, + ...seriesOptions, + }, + }; +}; diff --git a/src/views/Main/Dike/components/DataStatistics.vue b/src/views/Main/Dike/components/DataStatistics.vue index 5a0858b..c1fc999 100644 --- a/src/views/Main/Dike/components/DataStatistics.vue +++ b/src/views/Main/Dike/components/DataStatistics.vue @@ -1,4 +1,4 @@ - +