12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- /**
- * 工具类
- */
- class Util {
- static parseDate(date){
- var time = date==null?"": Date.parse(date.replace(/-/g, '/'));
- return new Date(time);
- }
- static formatTime(date) {
- let year = date.getFullYear();
- let month = date.getMonth() + 1;
- let day = date.getDate();
- let hour = date.getHours();
- let minute = date.getMinutes();
- let second = date.getSeconds();
- return [year, month, day].map(this.formatNumber).join('/') + ' ' + [hour, minute, second].map(this.formatNumber).join(':');
- };
- static formatTimePicker(date) {
- let year = date.getFullYear();
- let month = date.getMonth() + 1;
- let day = date.getDate();
- let hour = date.getHours();
- let minute = date.getMinutes();
- let second = date.getSeconds();
- return [year, month, day].map(this.formatNumber).join('-') + ' ' + [hour, minute].map(this.formatNumber).join(':');
- };
- static formatNumber(n) {
- n = n.toString();
- return n[1] ? n : '0' + n;
- };
- static distance = (la1, lo1, la2, lo2) => {
- var La1 = la1 * Math.PI / 180.0;
- var La2 = la2 * Math.PI / 180.0;
- var La3 = La1 - La2;
- var Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
- var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));
- s = s * 6378.137; //地球半径
- s = Math.round(s * 1000) / 1000;
- // console.log("计算结果",s)
- return s
- }
- static getIp(){
- // wx.request({
- // url: 'https://ipv4.icanhazip.com/',
- // method: 'POST',
- // success(rrr){
- // console.info(rrr);
- // var query = (rrr == null?'':rrr==null?'':rrr);
- // return query.data;
- // },
- // fail(rrr){
- // return '';
- // }
- // })
- }
- };
- module.exports = Util;
|