zoukankan      html  css  js  c++  java
  • 使用按钮触发element 时间事件 --时间戳

    本日 本周 本月 本年  时间按钮   date 组件内添加

    pickerOptions2: {
    shortcuts: [
    {
    text: '今日',
    onClick(picker) {
    picker.$emit('pick', new Date());
    }
    },{
    text: '本周',
    onClick(picker) {
    let oneDayLong = 24*60*60*1000 ;
    let now = new Date();
    let mondayTime = now.getTime() - (now.getDay()-1)*oneDayLong;
    let sundayTime = now.getTime() + (7-now.getDay())*oneDayLong;
    let monday = new Date(mondayTime);
    let sunday = new Date(sundayTime);
    picker.$emit('pick', [monday,sunday]);
    }
    }, {
    text: '本月',
    onClick(picker) {
    let oneDayLong = 24*60*60*1000;
    let now = new Date();
    let year = now.getFullYear();
    let monthStartDate = new Date(year, now.getMonth()+1, 1);//当前月1号
    let nextMonthStartDate = new Date(year, now.getMonth()+2, 1);//下个月1号
    let days = (nextMonthStartDate.getTime() -
    monthStartDate.getTime())/oneDayLong;//计算当前月份的天数
    let monthEndDate = new Date(year, now.getMonth()+1, days);
    picker.$emit('pick', [monthStartDate, monthEndDate]);
    }
    }, {
    text: '本年',
    onClick(picker) {
    let now=new Date()
    let year = now.getFullYear();
    let start= new Date(year, 0, 1)
    let end= new Date(year, 11, 31)
    picker.$emit('pick', [start, end])
    }
    }]
    },
    //触发时间选择
    radioDataChange(val){
    console.log(val)
    this.$emit('daterange', new Date());
    const now = new Date();
    const end = new Date().getTime()-3600*365;
    const start = new Date().getTime()-3600*365;
    const oneDayLong = 24*60*60*1000
    const year = now.getFullYear();
    switch(val){
    case '今日':
    this.value7=[end,start];
    break;
    case '本周':
    let mondayTime = now.getTime() - (now.getDay()-1)*oneDayLong;
    let sundayTime = now.getTime() + (7-now.getDay())*oneDayLong;
    this.value7=[mondayTime,sundayTime];
    break;
    case '本月':
    console.log(now+","+year);
    let monthStartDate = new Date(year, now.getMonth()+1, 1).getTime();//当前月1号
    let nextMonthStartDate = new Date(year, now.getMonth()+2, 1);//下个月1号
    let days = (nextMonthStartDate.getTime() -monthStartDate)/oneDayLong;//计算当前月份的天数
    let monthEndDate = new Date(year, now.getMonth()+1, days).getTime();
    this.value7= [monthStartDate, monthEndDate];
    break;
    case '全年':
    let Ystart= new Date(year, 0, 1).getTime();
    let Yend= new Date(year, 11, 31).getTime();
    this.value7= [Ystart, Yend];
    break;

    }
    },
  • 相关阅读:
    使用git bash提交代码到github托管
    eclipse中将java项目变成web项目
    程序员的兼职网站
    python 文件内容修改替换操作
    简单介绍下python中函数的基础语法
    python lambda简单介绍
    微信小程序 --01
    微信小程序开发 --02
    弹性盒模型flex
    HTML基础
  • 原文地址:https://www.cnblogs.com/Quxiya/p/10488468.html
Copyright © 2011-2022 走看看