import { format , subDays } from 'date-fns' ; desc eg export const sid_obj = ( str_sid ) => { const [ channel , sid ] = ( str_sid || '' ) . trim ( ) . split ( '#' ) ; return { channel , sid } ; } ; desc param str return const isString = ( str ) => { return Object . prototype . toString . call ( str ) === '[object String]' ; } ; desc export const formatTime = ( time , str ) => { if ( ! time ) return '' ; if ( isString ( time ) ) return time ; return format ( time , str || 'yyyy-MM-dd' ) ; } ; desc return { Array } 来源 export const gradientColor = ( startColor , endColor , num ) => { const parseColor = function ( hexStr ) { return hexStr . length === 4 ? hexStr . substr ( 1 ) . split ( '' ) . map ( function ( s ) { return 0x11 * parseInt ( s , 16 ) ; } ) : [ hexStr . substr ( 1 , 2 ) , hexStr . substr ( 3 , 2 ) , hexStr . substr ( 5 , 2 ) ] . map ( function ( s ) { return parseInt ( s , 16 ) ; } ) ; } ; const pad = function ( s ) { return ( s . length === 1 ) ? '0' + s : s ; } ; const gradientColors = function ( start , end , steps , gamma ? ) { let i , j , ms , me , output = [ ] , so = [ ] ; gamma = gamma || 1 ; const normalize = function ( channel ) { return Math . pow ( channel / 255 , gamma || 1 ) ; } ; let startArray = parseColor ( start ) . map ( normalize ) ; let endArray = parseColor ( end ) . map ( normalize ) ; for ( i = 0 ; i < steps ; i ++ ) { ms = i / ( steps - 1 ) ; me = 1 - ms ; for ( j = 0 ; j < 3 ; j ++ ) { so [ j ] = pad ( Math . round ( Math . pow ( startArray [ j ] * me + endArray [ j ] * ms , 1 / gamma ) * 255 ) . toString ( 16 ) ) ; } output . push ( '#' + so . join ( '' ) ) ; } return output ; } ; return gradientColors ( startColor , endColor , num ) ; } ; function _dateFn ( date ) { return format ( date , 'MM-dd' ) ; } desc return export const lastWhatDay = ( num ) => { const whatDayStart = subDays ( new Date ( ) , num ) ; return [ _dateFn ( whatDayStart ) , _dateFn ( new Date ( ) ) ] ; } ; desc export const lastWhatDaysList = ( num ) => { const daysList = [ ] ; for ( let i = 1 ; i < num + 2 ; i ++ ) { daysList . push ( _dateFn ( subDays ( new Date ( ) , i ) ) ) ; } return daysList . sort ( ) ; } ; export const randomColor = ( ) => { return '#' + Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) ; } ;