WXL (wul)
6 天以前 40382035e2e87b5c6813efd7e669b17a6a27be17
src/views/index.vue
@@ -94,15 +94,30 @@
                style="margin-left: 390px"
                @change="changes"
              >
                <el-radio-button label="周" @click="dyat = 7"></el-radio-button>
                <el-radio-button
                  label="月"
                  @click="dyat = 30"
                  label="近一周"
                  @click="dyat = 7"
                ></el-radio-button>
                <el-radio-button
                  label="年"
                  @click="dyat = 360"
                  label="近一月"
                  @click="dyat = 31"
                ></el-radio-button>
                <el-radio-button
                  label="近一年"
                  @click="dyat = 365"
                ></el-radio-button>
                <el-radio-button label="自定义">
                  <el-date-picker
                    v-if="radio1 === '自定义'"
                    v-model="customDateRange"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd"
                    @change="handleCustomDateChange"
                  ></el-date-picker>
                </el-radio-button>
              </el-radio-group>
            </div>
            <!-- 中部线性柱状图 -->
@@ -306,7 +321,7 @@
      mypPieCharts: null,
      lastWidth: window.innerWidth,
      lastHeight: window.innerHeight,
      radio1: "周",
      radio1: "近一周",
      ticketStatistics: {},
      timeTypeMap: {
        周: "day",
@@ -330,6 +345,7 @@
      SkuTop: [],
      cylinderSeries: [],
      cylinderXAxis: [],
      customDateRange: [], // 自定义日期范围
      dyat: 6,
      intervalId: null,
    };
@@ -344,16 +360,22 @@
      return dayjs().subtract(this.dyat, "day").format("YYYY-MM-DD HH:mm:ss");
    },
    statd() {
      if (this.radio1 === "自定义" && this.customDateRange.length > 0) {
        return this.customDateRange[1];
      }
      return dayjs().format("YYYY-MM-DD");
    },
    endatd() {
      if (this.radio1 === "自定义" && this.customDateRange.length > 0) {
        return this.customDateRange[0];
      }
      return dayjs().subtract(this.dyat, "day").format("YYYY-MM-DD");
    },
  },
  created() {
    this.getTopdata();
    this.getgraphdata();
    this.getranking();
    // this.getranking();
    this.$nextTick(function () {
      this.myEcharts2();
      this.getnodeCollect();
@@ -372,15 +394,35 @@
  methods: {
    // 改变时间事件
    changes() {
      if (this.radio1 == "周") {
        this.dyat = 6;
      } else if (this.radio1 == "月") {
      switch (this.radio1) {
        case "近一周":
          this.dyat = 7;
          break;
        case "近一月":
        this.dyat = 30;
      } else {
        this.dyat = 364;
          break;
        case "近一年":
          this.dyat = 365;
          break;
        case "自定义":
          // 自定义日期处理在handleCustomDateChange方法中
          return;
      }
      this.refreshData();
    },
    // 处理自定义日期变化
    handleCustomDateChange(range) {
      if (!range || range.length !== 2) return;
      this.customDateRange = range;
      this.refreshData();
    },
    // 统一刷新数据的方法
    refreshData() {
      this.getgraphdata();
      this.getranking();
      // this.getranking();
      this.getTopdata();
      this.myEcharts2();
      this.getnodeCollect();
@@ -461,12 +503,7 @@
      let params = {
        startDate: this.endatd,
        endDate: this.statd,
        timeType:
          this.radio1 === "周"
            ? "day"
            : this.radio1 === "月"
            ? "month"
            : "year",
        timeType: this.getTimeType()
      };
      try {
@@ -477,6 +514,28 @@
      } catch (error) {
        console.error("获取图表数据失败:", error);
      }
    },
    // 获取时间类型
    getTimeType() {
      if (this.radio1 === "近一周" || this.radio1 === "近一月") {
        return "day";
      }
      if (this.radio1 === "近一年") {
        return "month";
      }
      // 自定义日期范围
      if (this.radio1 === "自定义" && this.customDateRange.length === 2) {
        const start = dayjs(this.customDateRange[0]);
        const end = dayjs(this.customDateRange[1]);
        const diffDays = end.diff(start, 'day');
        return diffDays > 60 ? "month" : "day";
      }
      return "day"; // 默认返回day类型
    },
    processChartData(data) {
      // 按时间排序确保数据顺序正确
@@ -492,14 +551,10 @@
      sortedData.forEach((item) => {
        // 根据时间类型格式化显示
        let timeLabel = item.timePeriod;
        if (this.radio1 === "周") {
          timeLabel = dayjs(item.timePeriod).format("MM-DD");
        } else if (this.radio1 === "月") {
          timeLabel = item.timePeriod.split("-")[1] + "月";
        } else {
          timeLabel = item.timePeriod.split("-")[0] + "年";
        }
  const timeType = this.getTimeType();
  const timeLabel = timeType === "day"
    ? dayjs(item.timePeriod).format("MM-DD")
    : dayjs(item.timePeriod).format("YYYY-MM");
        xAxisData.push(timeLabel);
        dischargeFollowData.push(item.dischargeFollowCount);