element里面时间选择器快捷时间选择器的优化

这两天的bug疯狂的不要不要的,所以抽空换个脑子,写个改bug的记录

这是element里面的一个组件,产品要求快捷选项上面要今天,昨天,七天前。。。。。反正有啥都让写着,但是这个组件里面的昨天显示时间是今天的时间减去24小时的时间段,但是我们测试说这是个bug,点击昨天要显示前一天00:00:00到23:59:59才对,所以我这里粘贴一下我改过的,保证正确的代码

pickerOptions: {
              shortcuts: [
                {
                  text: '今天',
                  onClick(picker) {
                    const end = new Date()
                    const start = new Date(
                      new Date(new Date().toLocaleDateString()).getTime()
                    ) // 当天0点
                    picker.$emit('pick', [start, end])
                  }
                }, {
                  text: '昨天',
                  onClick(picker) {
                    const end = new Date()
                    end.setTime(end.getTime() - 3600 * 1000 * 24 * 1)
                    end.setHours(23); end.setMinutes(59); end.setSeconds(59)
                    const start = new Date()
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 1)
                    start.setHours(0); start.setMinutes(0); start.setSeconds(0)
                    picker.$emit('pick', [start, end])
                  }
                }, {
                  text: '最近7天',
                  onClick(picker) {
                    const end = new Date()
                    end.setHours(23); end.setMinutes(59); end.setSeconds(59)
                    const start = new Date()
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 6)
                    start.setHours(0); start.setMinutes(0); start.setSeconds(0)
                    picker.$emit('pick', [start, end])
                  }
                }, {
                  text: '最近一个月',
                  onClick(picker) {
                    const end = new Date()
                    end.setHours(23); end.setMinutes(59); end.setSeconds(59)
                    const start = new Date()
                    start.setHours(0); start.setMinutes(0); start.setSeconds(0)
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 29)
                    picker.$emit('pick', [start, end])
                  }
                }, {
                  text: '最近三个月',
                  onClick(picker) {
                    const end = new Date()
                    end.setHours(23); end.setMinutes(59); end.setSeconds(59)
                    const start = new Date()
                    start.setHours(0); start.setMinutes(0); start.setSeconds(0)
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
                    picker.$emit('pick', [start, end])
                  }
                }, {
                  text: '最近一年',
                  onClick(picker) {
                    const end = new Date()
                    end.setHours(23); end.setMinutes(59); end.setSeconds(59)
                    const start = new Date()
                    start.setHours(0); start.setMinutes(0); start.setSeconds(0)
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 365)
                    picker.$emit('pick', [start, end])
                  }
                }
              ]
            },
            clearable: true,
            filterable: true,
            value: [],
            key: ['expectedOrderDateStart', 'expectedOrderDateEnd']
          }
        ]
      },

这样子就可以实现获取昨天00:00:00到23:59:59的时间需求了,全部的献上

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值