From 356a9d58c167c7f0d254ba46039c46fb6e76fd67 Mon Sep 17 00:00:00 2001 From: lzhizhao <790086754@qq.com> Date: Thu, 2 Oct 2025 13:34:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E5=88=86=E6=9E=90=E3=80=81=E5=95=86=E5=93=81=E5=88=86=E6=9E=90?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datacenter/customer-analysis/index.vue | 62 ++++++++++++++++--- .../datacenter/product-analysis/index.vue | 55 ++++++++++++++-- 2 files changed, 101 insertions(+), 16 deletions(-) diff --git a/src/views/modules/datacenter/customer-analysis/index.vue b/src/views/modules/datacenter/customer-analysis/index.vue index 335482e..6a47d14 100644 --- a/src/views/modules/datacenter/customer-analysis/index.vue +++ b/src/views/modules/datacenter/customer-analysis/index.vue @@ -7,12 +7,14 @@ style="margin-right: 20px" v-model="formInline.dateType" placeholder="请选择" + @change="handleDateTypeChange" > + + + + 查询 导出 @@ -139,13 +152,15 @@ import * as XLSX from "xlsx"; import { saveAs } from "file-saver"; import { mapState } from "vuex"; import * as echarts from "echarts"; +import dayjs from "dayjs"; export default { data() { return { value1: "", value: "", formInline: { - dateType: "1", + dateType: "7", + timeRange: [], }, analysis: {}, trend: [], @@ -162,16 +177,19 @@ export default { }); }, methods: { + handleDateTypeChange() { + this.formInline.timeRange = []; + }, getList() { - this.$api.dataCenter - .customerAnalysis({ dateType: this.formInline.dateType }) - .then((res) => { - this.analysis = res.data.data; - }); + let params = this.getParams(); + if (!params) return; + this.$api.dataCenter.customerAnalysis(params).then((res) => { + this.analysis = res.data.data; + }); const elementTypes = ["1", "2", "3", "4"]; const chartPromises = elementTypes.map((type) => - this.$api.dataCenter.customerTrend({ ...this.formInline, elementType: type }) + this.$api.dataCenter.customerTrend({ ...params, elementType: type }) ); Promise.all(chartPromises).then((responses) => { @@ -179,6 +197,30 @@ export default { this.init(chartData); }); }, + getParams() { + let params = {}; + if (this.formInline.dateType === "custom") { + if ( + this.formInline.timeRange && + this.formInline.timeRange.length === 2 + ) { + params.startTime = this.formInline.timeRange[0]; + params.endTime = this.formInline.timeRange[1]; + } else { + this.$message.error("请选择时间范围"); + return null; + } + } else { + const end = dayjs().endOf("day").format("YYYY-MM-DD HH:mm:ss"); + const start = dayjs() + .subtract(this.formInline.dateType - 1, "day") + .startOf("day") + .format("YYYY-MM-DD HH:mm:ss"); + params.startTime = start; + params.endTime = end; + } + return params; + }, init(allData) { // 先销毁旧实例 this.charts.forEach((chart) => { diff --git a/src/views/modules/datacenter/product-analysis/index.vue b/src/views/modules/datacenter/product-analysis/index.vue index f56596c..968d999 100644 --- a/src/views/modules/datacenter/product-analysis/index.vue +++ b/src/views/modules/datacenter/product-analysis/index.vue @@ -7,13 +7,14 @@ style="margin-right: 20px" v-model="formInline.dateType" placeholder="请选择" + @change="handleDateTypeChange" > + + + + 查询 导出 @@ -318,11 +330,13 @@