获取时间差
function timeDiff ( newTime, oldTime, type ) {
let dateBegin = new Date ( oldTime. replace ( / - / g , "/" ) ) ;
let dateEnd
if ( type == 1 ) {
dateEnd = new Date ( newTime. replace ( / - / g , "/" ) ) ;
}
if ( type == 2 ) {
dateEnd = newTime
}
let leave1 = dateEnd. getTime ( ) - dateBegin. getTime ( ) ;
let hours = Math. floor ( leave1 / ( 3600 * 1000 ) )
hours < 10 ? hours = '0' + hours : ''
let leave2 = leave1 % ( 3600 * 1000 )
let minutes = Math. floor ( leave2 / ( 60 * 1000 ) )
minutes < 10 ? minutes = '0' + minutes : ''
let leave3 = leave2 % ( 60 * 1000 )
let seconds = Math. round ( leave3 / 1000 )
seconds < 10 ? seconds = '0' + seconds : ''
return ( hours + ":" + minutes + ":" + seconds)
}
小程序判断指定手机型号
function checkModel ( ) {
let info = '' ;
uni. getSystemInfo ( {
success : function ( res ) {
info = res. model
}
} ) ;
if ( / iPhone X / i . test ( info) || info. search ( 'iPhone 11' ) != - 1 || info. search ( 'iPhone 11 Pro' ) != - 1 || info. search ( 'iPhone 11 Pro Max' ) != - 1 || info. search ( 'iPhone 12' ) != - 1 || info. search ( 'iPhone 12 Pro' ) != - 1 || info. search ( 'iPhone 12 Pro Max' ) != - 1 ) {
return true ;
} else {
return false ;
}
}
根据两个地址的经纬度获取两地的距离
function gainDistance ( lat1, lng1, lat2, lng2 ) {
console. log ( '根据两个地址的经纬度获取两地的距离' , lat1, lng1, lat2, lng2)
lat1 = lat1 - 0
lng1 = lng1 - 0
lat2 = lat2 - 0
lng2 = lng2 - 0
let radLat1 = lat1 * Math. PI / 180.0
let radLat2 = lat2 * Math. PI / 180.0
let a = radLat1 - radLat2
let b = lng1 * Math. PI / 180.0 - lng2 * Math. PI / 180.0
let s = 2 * Math. asin ( Math. sqrt ( Math. pow ( Math. sin ( a / 2 ) , 2 ) + Math. cos (
radLat1) * Math. cos ( radLat2) * Math. pow ( Math. sin ( b / 2 ) , 2 ) ) )
s = s * 6378.137
s = Math. round ( s * 10000 ) / 10000
return s
}
将百度地图经纬度转换为腾讯/高德地图经纬度
function BMapTransqqMap ( lng, lat ) {
let x_pi = 3.14159265358979324 * 3000.0 / 180.0 ;
let x = lng - 0.0065 ;
let y = lat - 0.006 ;
let z = Math. sqrt ( x * x + y * y) - 0.00002 * Math. sin ( y * x_pi) ;
let theta = Math. atan2 ( y, x) - 0.000003 * Math. cos ( x * x_pi) ;
let lngs = z * Math. cos ( theta) ;
let lats = z * Math. sin ( theta) ;
return {
lng : lngs,
lat : lats
} ;
}
腾讯地图转换成百度地图坐标
function qqMapToBMap ( lng, lat ) {
if ( lng == null || lng == '' || lat == null || lat == '' )
return [ lng, lat] ;
var x_PI = 3.14159265358979324 ;
var z = Math. sqrt ( lng * lng + lat * lat) + 0.00002 * Math. sin ( lat * x_PI) ;
var theta = Math. atan2 ( lat, lng) + 0.000003 * Math. cos ( lng * x_PI) ;
var bd_lng = z * Math. cos ( theta) + 0.0065 ;
var bd_lat = z * Math. sin ( theta) + 0.006 ;
return {
lng : bd_lng,
lat : bd_lat
} ;
}
身份证校验
function checkIDCard ( idcode ) {
var weight_factor = [ 7 , 9 , 10 , 5 , 8 , 4 , 2 , 1 , 6 , 3 , 7 , 9 , 10 , 5 , 8 , 4 , 2 ] ;
var check_code = [ '1' , '0' , 'X' , '9' , '8' , '7' , '6' , '5' , '4' , '3' , '2' ] ;
var code = idcode + "" ;
var last = idcode[ 17 ] ;
var seventeen = code. substring ( 0 , 17 ) ;
var arr = seventeen. split ( "" ) ;
var len = arr. length;
var num = 0 ;
for ( var i = 0 ; i < len; i++ ) {
num = num + arr[ i] * weight_factor[ i] ;
}
var resisue = num % 11 ;
var last_no = check_code[ resisue] ;
var idcard_patter = / ^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$ / ;
var format = idcard_patter. test ( idcode) ;
return last === last_no && format ? true : false ;
}
网页检查是否在微信环境
function checkWechat ( ) {
const ua = navigator. userAgent. toLowerCase ( ) ;
if ( ua. match ( / MicroMessenger / i ) == "micromessenger" ) {
return true ;
} else {
return false ;
}
}