weekCodeing / interview-answe

🌍 前端程序员训练 求星星 ✨ 各位同学可以在issues中提问,无论是实际项目中遇到的问题,或者是技术问题都可以, 大家一起解决💯 👍 😄。
http://www.dadaqianduan.cn/
76 stars 9 forks source link

116.前天,昨天,今天,前一小时更新优化 #116

Open webVueBlog opened 4 years ago

webVueBlog commented 4 years ago

[js]

webVueBlog commented 4 years ago
timeBtn(e) {
    this.query.type = e.currentTarget.dataset.time
    const date = new Date()
    if(this.query.type==1) {
        // 前天
        this.query.end_time = ( new Date(date.toLocaleDateString()).getTime() - 60*60*24*1*1000 - 1*1000 ) / 1000
        this.query.start_time = ( new Date(date.toLocaleDateString()).getTime() - 60*60*24*2*1000 ) / 1000
    }else if(this.query.type==2) {
        // 昨天
        this.query.end_time = (new Date(date.toLocaleDateString()).getTime() - 1*1000)/1000
        this.query.start_time = (new Date(date.toLocaleDateString()).getTime() - 60*60*24*1000)/1000
    }else if(this.query.type==3) {
        // 今天
        this.query.end_time = (Date.parse(date))/1000
        this.query.start_time = (new Date(date.toLocaleDateString()).getTime())/1000
    }else if(this.query.type==4) {
        // 前一小时
        this.query.end_time = (Date.parse(date))/1000
        this.query.start_time = (Date.parse(date) - 1*60*60*1000)/1000
    }
    this.$emit('callback', this.query)
    this.modalName = null
},