vuetify——根据时间范围下拉选检索数据

在这里插入图片描述
在这里插入图片描述

<span class="pr-4 text-h6">时间范围</span>
<v-select
  :items="dateRanges"
  v-model="dateRange"
  item-text="name"
  item-value="time"
  style="flex: none; background: none"
  @change="dateRangechange(dateRange)"
></v-select>

<script>
import { dateRanges, time_val } from "./util/dateRange";
export default {
	data(){
		return{
			dateRange:24,
			dateRanges
		}
	},
	methods:{
		dateRangechange(dateRange) {
	      let { start_time, end_time } = starttime_val(dateRange);
	      this.dashboardData(start_time, end_time);
	    },
	    dashboardData(start_time, end_time){
			//检索数据处理
		}
	}
}
</script>

util/dataRange.js

import { format } from "date-fns";

const dateRanges = [
  {
    name: "最近1小时",
    time: 1
  },
  {
    name: "最近6小时",
    time: 6
  },
  {
    name: "最近12小时",
    time: 12
  },
  {
    name: "最近24小时",
    time: 24
  },
  {
    name: "今天",
    time: format(new Date(), "HH")
  },
  {
    name: "昨天",
    time: 0
  },
  {
    name: "最近7天",
    time: 7 * 24
  },
  {
    name: "最近30天",
    time: 30 * 24
  },
  {
    name: "最近3个月",
    time: 90 * 24
  },
  {
    name: "最近6个月",
    time: 180 * 24
  }
];

function time_val(h) {
  const d = new Date();
  d.setMinutes(0);
  d.setSeconds(0);

  let hours = d.getHours();
  const timestring = d.getTime();
  let start_time, end_time;
  if (h !== 0) {
    start_time = new Date(timestring - h * 3600 * 1000);
    end_time = new Date(timestring - 3600 * 1000);
  } else {
    start_time = new Date(timestring - 24 * 3600 * 1000 - hours * 3600 * 1000);
    end_time = new Date(timestring - hours * 3600 * 1000);
  }

  return {
    start_time: format(start_time,"yyyy-MM-dd HH:mm-ss"),
    end_time: format(end_time,"yyyy-MM-dd HH:mm-ss")
  };
}


export { dateRanges, time_val };

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值