export const repeat = ( str = '0' , times ) => ( new Array ( times + 1 ) ) . join ( str ) ; export const pad = ( num , maxLength = 2 ) => repeat ( '0' , maxLength - num . toString ( ) . length ) + num ; /** 时间格式的转换 */ export const formatTime = time => `${ pad ( time . getHours ( ) ) }:${ pad ( time . getMinutes ( ) ) }:${ pad ( time . getSeconds ( ) ) }.${ pad ( time . getMilliseconds ( ) , 3 ) }` ; export var globalData = { } ; param phone export const verifyPhone = ( phone ) => { const reg = /^1[34578][0-9]{9}$/ ; const _phone = phone . toString ( ) . trim ( ) ; let toastStr = _phone === '' ? '手机号不能为空~' : ! reg . test ( _phone ) && '请输入正确手机号~' ; return { errMsg : toastStr , done : ! toastStr , value : _phone } ; } ; export const verifyStr = ( str , text ) => { const _str = str . toString ( ) . trim ( ) ; const toastStr = _str . length ? false : `请填写${ text }～` ; return { errMsg : toastStr , done : ! toastStr , value : _str } ; } ; export const sliceStr = ( str , sliceLen ) => { if ( ! str ) { return '' ; } let realLength = 0 ; const len = str . length ; let charCode = - 1 ; for ( var i = 0 ; i < len ; i ++ ) { charCode = str . charCodeAt ( i ) ; if ( charCode >= 0 && charCode <= 128 ) { realLength += 1 ; } else { realLength += 2 ; } if ( realLength > sliceLen ) { return `${ str . slice ( 0 , i ) }...` ; } } return str ; } ; param { Object | Json } jsonObj return { Object | Json } export function objClone ( jsonObj ) { var buf ; if ( jsonObj instanceof Array ) { buf = [ ] ; var i = jsonObj . length ; while ( i -- ) { buf [ i ] = objClone ( jsonObj [ i ] ) ; } return buf ; } else if ( jsonObj instanceof Object ) { buf = { } ; for ( var k in jsonObj ) { buf [ k ] = objClone ( jsonObj [ k ] ) ; } return buf ; } else { return jsonObj ; } }