123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- const { default: api } = require("../js/api")
- const formatTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
- }
- const formatDateNotSecond = isoString => {
- if (isoString == undefined) return '';
- const date = new Date(isoString);
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, '0');
- const day = String(date.getDate()).padStart(2, '0');
- const hours = String(date.getHours()).padStart(2, '0');
- const minutes = String(date.getMinutes()).padStart(2, '0');
- return `${year}-${month}-${day} ${hours}:${minutes}`;
- }
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : `0${n}`
- }
- const formatPhone = phone => {
-
- if (!phone || phone.length !== 11) {
- return phone;
- }
-
- const start = phone.substring(0, 3);
- const end = phone.substring(7);
-
- const hidden = '****';
-
- return start + hidden + end;
- }
- const formatDiNumber = number => {
- var numberStr = number.toString()
- if(!numberStr.includes(".")){
- numberStr += ".00"
- }
- return numberStr
- }
- const haversine = (lat1, lon1, lat2, lon2) => {
- const R = 6371;
- const toRadians = (degrees) => degrees * (Math.PI / 180);
-
- const phi1 = toRadians(lat1);
- const phi2 = toRadians(lat2);
- const deltaPhi = toRadians(lat2 - lat1);
- const deltaLambda = toRadians(lon2 - lon1);
-
- const a = Math.sin(deltaPhi / 2) ** 2 + Math.cos(phi1) * Math.cos(phi2) * Math.sin(deltaLambda / 2) ** 2;
- const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
-
- const distance = R * c;
- return distance * 1000;
- }
- function subAndsendMessage(id,type) {
- return new Promise((resolve,reject)=>{
- wx.requestSubscribeMessage({
- tmplIds: ['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'],
- success(res) {
- sendMessage(id,type,resolve,reject)
-
- if (res['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'] === 'accept') {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- },
- fail(err) {
- sendMessage(id,type,resolve,reject)
- }
- })
- })
-
- }
- function sendMessage(id,type,resolve,reject) {
- const message = {
- trxid:id,
- orderType:type
- }
- api.request_sendMessage(message).then(res => {
- console.log("发送消息模板结果",res)
- resolve()
- }).catch(err => {
- console.log("发送消息模板失败",err)
- reject()
- })
- }
- module.exports = {
- formatTime,
- formatDateNotSecond,
- formatPhone,
- formatDiNumber,
- haversine,
- subAndsendMessage
- }
|