// 参数名称:authCode 值: 所有:0 化工销售:HXXT; 炼油销售:LXXT; 江苏石油:CPYXT; 销售华东:XSHD let SysAuthCode = '0' /** * Created by liangruizhe on 2019/01/14 */ // ==============时间=============== // 获取当前时间 function GetCurrentTime() { var today = new Date() var year = today.getFullYear() var month = today.getMonth() + 1 var day = today.getDate() > 9 ? today.getDate() : '0' + today.getDate() var hours = today.getHours() > 9 ? today.getHours() : '0' + today.getHours() var minutes = today.getMinutes() > 9 ? today.getMinutes() : '0' + today.getMinutes() var seconds = today.getSeconds() > 9 ? today.getSeconds() : '0' + today.getSeconds() return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds } // 获取当天零点时间 function GetCurrentDayTime() { var today = new Date() var year = today.getFullYear() var month = today.getMonth() + 1 var day = today.getDate() > 9 ? today.getDate() : '0' + today.getDate() return year + '-' + month + '-' + day + ' 00:01:01' } // UtcToDateTime function UtcToDateTime(time) { var date = new Date(time) var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate() var hour = date.getHours() var minute = date.getMinutes() var second = date.getSeconds() return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second } // UtcToMonDate function UtcToMonDate(time) { var date = new Date(time) var month = date.getMonth() + 1 var day = date.getDate() var hour = date.getHours() var minute = date.getMinutes() var second = date.getSeconds() return month + '/' + day + ' ' + hour + ':' + minute + ':' + second } // yyyy-MM-dd function convertDateFromString(dateString) { if (dateString) { var date = new Date(dateString.replace(/-/, '/')) return date } } // yyyy-MM-dd hh:mm:ss function convertDateTimeFromString(dateString) { if (dateString) { var arr1 = dateString.split(' ') var sdate = arr1[0].split('-') var stime = arr1[1].split(':') var date = new Date(sdate[0], sdate[1] - 1, sdate[2], stime[0], stime[1], stime[2]) return date } } // ==============空间计算=============== // 计算点串距离 function getLength(arrPnts, isJwd) { var dist = 0 var length = 0 var offset = 103133.845 var fntPnt = null var lastPnt = null if (isJwd === undefined) isJwd = true if (arrPnts.length < 2) { return 0 } for (var i = 0; i < arrPnts.length - 1; i++) { fntPnt = arrPnts[i] lastPnt = arrPnts[i + 1] if (lastPnt) { var xD = Math.abs(fntPnt.x - lastPnt.x) var yD = Math.abs(fntPnt.y - lastPnt.y) if (isJwd) { if (Math.abs(fntPnt.x) > 180) { xD = xD / 3600 yD = yD / 3600 } dist = (Math.sqrt(Math.pow(xD, 2) + Math.pow(yD, 2))) * offset } else { dist = (Math.sqrt(Math.pow(xD, 2) + Math.pow(yD, 2))) } length += dist } } return length } // 计算点到线段的距离 function getDistance(point, lineP1, lineP2) { var a = Number((lineP1.y - lineP2.y) / (lineP1.x - lineP2.x)) var b = -1 var c = Number(lineP2.y - a * lineP2.x) var td = Math.abs(a * point.x + b * point.y + c) / Math.sqrt(a * a + b * b) return td } export default { SysAuthCode, getDistance, getLength, GetCurrentTime, GetCurrentDayTime, UtcToDateTime, UtcToMonDate, convertDateFromString, convertDateTimeFromString }