Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | 7x 1760x 1760x 1760x 1840x 1840x 1760x 80x 80x 1680x 1680x 80x 1760x 1760x 40x 1760x 1760x 1920x 1760x 1760x 7x 3920x 3440x 480x 360x 360x 360x 360x 120x 120x 120x 3440x 3440x 3440x 3440x 3440x 3440x | import cloneDeep from 'lodash/cloneDeep'; import dayjs from './dayjs'; export const format = function format(value, type) { Iif (!value) return; type = type || 'YYYY-MM-DD HH:mm'; const fix = (str) => { str = '' + (String(str) || ''); return str.padStart(2, '0'); }; const maps = { yyyy(date) { if (process.env.NODE_ENV === 'development') { console.warn('use YYYY instead of yyyy in YYYY-MM-DD'); } return date.getFullYear(); }, YYYY(date) { return date.getFullYear(); }, MM(date) { return fix(date.getMonth() + 1); }, dd(date) { Iif (process.env.NODE_ENV === 'development') { console.warn('use DD instead of dd in YYYY-MM-DD'); } return fix(date.getDate()); }, WWWW(date) { return `W${fix(dayjs(date).isoWeek())}`; }, QQ(date) { return `Q${Math.ceil((date.getMonth() + 1) / 3)}`; }, DD(date) { return fix(date.getDate()); }, HH(date) { return fix(date.getHours()); }, mm(date) { return fix(date.getMinutes()); }, ss(date) { return fix(date.getSeconds()); }, }; const trunk = new RegExp(Object.keys(maps).join('|'), 'g'); if (typeof value === 'string' && !value.includes('T')) value = transformDate(value); value = new Date(value); Iif (value.toString() === 'Invalid Date') return; const result = type.replace(trunk, (capture) => maps[capture] ? maps[capture](value) : ''); // 根据 iOS 周历特殊处理,例如 2018-12-31 应该被解析为 2019-W01 Iif (type.includes('YYYY-WWWW')) { const valueYear = value.getFullYear(); const isoYear = dayjs(value).isoWeekYear(); if (valueYear !== isoYear) { return result.replace(valueYear, isoYear); } } return result; }; export const transformDate = function transformDate(date) { if (!date) return; if (typeof date === 'string') { /** * 因为如果时间格式是 json 的字符串 "2021-06-18T07:55:26.914Z" * 不能做 - 的替换,会导致转化失效 */ Iif (date.includes('Q')) { return new Date(date.replace(/Q1/, '1').replace(/Q2/, '4').replace(/Q3/, '7').replace(/Q4/, '10')); } Iif (date.includes('W')) { return dayjs(date, ['YYYY-WWWW', 'YYYY-WWWW H:mm:ss', 'YYYY-WWWW HH:mm:ss']).toDate(); } date = date.replace(/-/g, '/'); return new Date(date); } else Iif (typeof date === 'number') return new Date(date); else Eif (typeof date === 'object') return date; }; /** 自动去掉最大最小时间的尾数 */ export function ChangeDate(currentDate, picker, flag) { const cloneDate = cloneDeep(currentDate); const date = new Date(cloneDate); Iif (picker === 'month') { date.setDate(1); date.setHours(0, 0, 0, 0); return date; } Iif (picker === 'quarter') { // 更新为当前范围的最小值 const month = date.getMonth(); let currentMonth; /** 2, 7, 10 作为季度的开始第一天 */ if (flag === 'min') { if (0 <= month && month < 3) { currentMonth = 0; } else if (month < 6) { currentMonth = 3; } else if (month < 9) { currentMonth = 6; } else { currentMonth = 9; } } if (flag === 'max') { if (0 <= month && month < 3) { currentMonth = 3; } else if (month <= 6) { currentMonth = 6; } else if (month <= 9) { currentMonth = 9; } } date.setMonth(currentMonth); date.setDate(1); date.setHours(0, 0, 0, 0); return date; } Iif (picker === 'year') { date.setMonth(0); date.setDate(1); date.setHours(0, 0, 0, 0); return date; } return currentDate; } |