| | |
| | | |
| | | import moment from 'moment'; |
| | | /** |
| | | * 获取距离date的dayCount天数( 年月日) |
| | | * @param {*} dayCount 距离date的天数 |
| | |
| | | if (l) { |
| | | a1 < 2 |
| | | ? (b = |
| | | n / Math.pow(10, a1) - parseInt(n / Math.pow(10, a1)) > 0.5 |
| | | ? Math.round(n / Math.pow(10, a1)) * Math.pow(10, a1) |
| | | : (parseInt(n / Math.pow(10, a1)) + 0.5) * Math.pow(10, a1)) |
| | | n / Math.pow(10, a1) - parseInt(n / Math.pow(10, a1)) > 0.5 |
| | | ? Math.round(n / Math.pow(10, a1)) * Math.pow(10, a1) |
| | | : (parseInt(n / Math.pow(10, a1)) + 0.5) * Math.pow(10, a1)) |
| | | : (b = Math.ceil(n / Math.pow(10, 1)) * Math.pow(10, 1)); |
| | | } else { |
| | | a1 < 2 |
| | | ? (b = |
| | | n / Math.pow(10, a1) - parseInt(n / Math.pow(10, a1)) > 0.5 |
| | | ? (parseInt(n / Math.pow(10, a1)) + 0.5) * Math.pow(10, a1) |
| | | : Math.floor(n / Math.pow(10, a1)) * Math.pow(10, a1)) |
| | | n / Math.pow(10, a1) - parseInt(n / Math.pow(10, a1)) > 0.5 |
| | | ? (parseInt(n / Math.pow(10, a1)) + 0.5) * Math.pow(10, a1) |
| | | : Math.floor(n / Math.pow(10, a1)) * Math.pow(10, a1)) |
| | | : (b = Math.floor(n / Math.pow(10, 1)) * Math.pow(10, 1)); |
| | | } |
| | | return l ? (-20 <= a1 ? +b.toFixed(a1 < 0 ? -a1 + 1 : 0) : b) : b; |
| | |
| | | export const $ = (name) => document.querySelector(name); |
| | | |
| | | export const getContainerSize = (dom) => ({ width: dom.getBoundingClientRect().width, height: dom.getBoundingClientRect().height }); |
| | | export const getDefaultPeriod = (selectedPeriod) => { |
| | | // 根据选择的周期返回相应的日期范围 |
| | | let startDate, endDate; |
| | | switch (selectedPeriod) { |
| | | case '7Days': |
| | | startDate = moment().subtract(7, 'days'); |
| | | endDate = moment(); |
| | | break; |
| | | case 'ThisMonth': |
| | | startDate = moment().startOf('month'); |
| | | endDate = moment(); |
| | | break; |
| | | case 'ThisYear': |
| | | startDate = moment().startOf('year'); |
| | | endDate = moment(); |
| | | break; |
| | | default: |
| | | // 处理未匹配到的情况 |
| | | startDate = moment().subtract(7, 'days'); |
| | | endDate = moment(); |
| | | } |
| | | return { startDate, endDate }; |
| | | }; |