|
|
import aes from "@/common/aes.js";
|
|
|
// #ifdef H5
|
|
|
import wechat from './wechat'
|
|
|
// #endif
|
|
|
import param from './param'
|
|
|
//工具方法
|
|
|
module.exports = {
|
|
|
//GPS定位业务vue对象
|
|
|
gpsObject: null,
|
|
|
|
|
|
bindGpsObj: function(obj) {
|
|
|
// uni.showModal({
|
|
|
// title: "util的bindgpsobj方法:"
|
|
|
// })
|
|
|
this.gpsObject = obj;
|
|
|
//this.callBackGpsResult("200","",0,0);
|
|
|
},
|
|
|
unbindGpsObj: function() {
|
|
|
// uni.showModal({
|
|
|
// title: "util的取消bindgpsobj方法:"
|
|
|
// })
|
|
|
this.gpsObject = null;
|
|
|
},
|
|
|
getNetworkType: function(successCallbck, failCallback) {
|
|
|
uni.getNetworkType({
|
|
|
success: function(res) {
|
|
|
if (successCallbck) {
|
|
|
successCallbck(res);
|
|
|
}
|
|
|
},
|
|
|
fail: function() {
|
|
|
if (failCallback) {
|
|
|
failCallback(res);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
hideLoadingByTime: function() {
|
|
|
setTimeout(function() {
|
|
|
uni.hideLoading();
|
|
|
}, 10000);
|
|
|
},
|
|
|
receiveFile: function(code, object) {
|
|
|
if (code == "200") {
|
|
|
this.gpsObject.receiveSuccess(object);
|
|
|
} else {
|
|
|
this.gpsObject.receiveFail();
|
|
|
}
|
|
|
},
|
|
|
callBackGpsResult: function(code, mes, lat, lng) {
|
|
|
if (code == "200") {
|
|
|
param.clat = lat;
|
|
|
param.clng = lng;
|
|
|
// var that = this.gpsObject;
|
|
|
if (this.gpsObject) {
|
|
|
this.gpsObject.callGpsSuccess(lat, lng);
|
|
|
}
|
|
|
} else {
|
|
|
param.clat = param.lat;
|
|
|
param.clng = param.lng;
|
|
|
if (this.gpsObject) {
|
|
|
uni.showToast({
|
|
|
title: "为了您的良好体验请打开GPS功能",
|
|
|
icon: "none",
|
|
|
duration: 2000
|
|
|
})
|
|
|
this.gpsObject.callGpsFail();
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
iosCallBackGpsResult: function(code, mes, lat, lng) {
|
|
|
console.log('iosCallBackGpsResult>>>');
|
|
|
if (code == "200") {
|
|
|
param.clat = lat;
|
|
|
param.clng = lng;
|
|
|
|
|
|
if (this.gpsObject) {
|
|
|
this.gpsObject.callGpsSuccess(lat, lng);
|
|
|
}
|
|
|
} else {
|
|
|
param.clat = param.lat;
|
|
|
param.clng = param.lng;
|
|
|
|
|
|
if (this.gpsObject) {
|
|
|
uni.showToast({
|
|
|
title: "为了您的良好体验请打开GPS功能",
|
|
|
icon: "none",
|
|
|
duration: 2000
|
|
|
})
|
|
|
this.gpsObject.callGpsFail();
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
//获取安卓内容
|
|
|
getAndroidData: function(code, mes, type, data) {
|
|
|
/* mes += "---------"+type+"-------"+code+"------"+data;
|
|
|
uni.showModal({
|
|
|
title:"提示",
|
|
|
content:mes,
|
|
|
showCancel:false,
|
|
|
success() {
|
|
|
}
|
|
|
}) */
|
|
|
if (code == "200") {
|
|
|
if (type == "WxUserInfo") {
|
|
|
var wx_data = JSON.parse(data);
|
|
|
// var unionid = "oaxUrw1nI4vDQ1ihKWlrDWIXHea0";
|
|
|
// uni.setStorageSync("unionid","oaxUrw1nI4vDQ1ihKWlrDWIXHea0");
|
|
|
// uni.setStorageSync("openid","oA5vYww6QNBd5Y8sqM9Ss0AVvhl8");
|
|
|
// uni.setStorageSync("nickname","你怎么了");
|
|
|
// uni.setStorageSync("headimgurl","http://thirdwx.qlogo.cn/mmopen/vi_32/0sUibCSJ47ia4mjIib7Xs2MTVxdMyr7jhq1kj0PDnuHOd5vUbibn7MrGekMqfFjUWXLGPZurvRlKRyZc5awpA1Sa7g/132");
|
|
|
var unionid = wx_data.unionid;
|
|
|
var url = wx_data.headimgurl;
|
|
|
url = url.substring(url.indexOf(":") + 1);
|
|
|
uni.setStorageSync("oauthTime", new Date().getTime())
|
|
|
uni.setStorageSync("unionid", aes.aesMinEncrypt(unionid));
|
|
|
uni.setStorageSync("openid", aes.aesMinEncrypt(wx_data.openid));
|
|
|
uni.setStorageSync("nickname", aes.aesMinEncrypt(wx_data.nickname));
|
|
|
uni.setStorageSync("headimgurl", aes.aesMinEncrypt(url));
|
|
|
var that = this.gpsObject;
|
|
|
wx_data.headimgurl = url;
|
|
|
data = JSON.stringify(wx_data);
|
|
|
//Android
|
|
|
// this.getUserInfo(that,unionid,function(){
|
|
|
that.$util.saveWxUser(that, data);
|
|
|
that.callBackMethod();
|
|
|
// });
|
|
|
} else if (type == "DEVICEID") {
|
|
|
this.gpsObject.imgPushTest(data);
|
|
|
} else if (type == "GetVersionInfo") {
|
|
|
this.gpsObject.version = data;
|
|
|
} else if (type == "QRCODE") {
|
|
|
if (data.indexOf("userid") == 1) {
|
|
|
uni.showToast({
|
|
|
title: "二维码错误",
|
|
|
mask: true,
|
|
|
icon: "none"
|
|
|
})
|
|
|
return;
|
|
|
}
|
|
|
var map = JSON.parse(data);
|
|
|
var userid = map.userid;
|
|
|
//扫码结果
|
|
|
uni.navigateTo({
|
|
|
url: "/sunPackIndex/scenic/subscribe/qrcode/reserve_detail_2?userid=" + userid
|
|
|
})
|
|
|
}
|
|
|
} else if (code == "0" && mes == "未安装微信_小程序跳转") {
|
|
|
uni.navigateTo({
|
|
|
url: "/sunPackIndex/scenic/subscribe/yuyue/yue_list_js"
|
|
|
})
|
|
|
} else if (code == "0" && mes == "未安装微信_授权登陆") {
|
|
|
uni.navigateTo({
|
|
|
url: "/pages/index/an_login/an_login"
|
|
|
})
|
|
|
} else {
|
|
|
if (!mes == '失败') {
|
|
|
uni.showToast({
|
|
|
title: mes,
|
|
|
icon: "none",
|
|
|
duration: 2000
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
//传入数字 返回其公里数 例如传入3500 返回3.5km
|
|
|
formatDistance: function(num) {
|
|
|
var reg = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 ,判断正整数用/^[1-9]+[0-9]*]*$/
|
|
|
if (reg.test(num)) {
|
|
|
var fomatFloat = parseFloat(num);
|
|
|
|
|
|
if (fomatFloat < 1000) {
|
|
|
return fomatFloat.toFixed(0) + 'm';
|
|
|
} else if (fomatFloat > 1000) {
|
|
|
return (fomatFloat / 1000).toFixed(1) + 'km';
|
|
|
}
|
|
|
} else {
|
|
|
return "未知";
|
|
|
}
|
|
|
},
|
|
|
//格式化字符串(将携带html标签的内容将标签去掉)
|
|
|
returnString: function(data) {
|
|
|
return data.replace(/<[^>]+>/g, "");
|
|
|
},
|
|
|
showPosition: function(position) {
|
|
|
uni.showToast({
|
|
|
title: "允许定位"
|
|
|
})
|
|
|
console.log("获取到的信息:" + JSON.stringify(position));
|
|
|
console.log("Latitude: " + position.coords.latitude + "<br />Longitude: " + position.coords.longitude);
|
|
|
},
|
|
|
showError: function(error) {
|
|
|
uni.showToast({
|
|
|
title: "不允许定位"
|
|
|
})
|
|
|
switch (error.code) {
|
|
|
case error.PERMISSION_DENIED:
|
|
|
alert("定位失败,用户拒绝请求地理定位");
|
|
|
break;
|
|
|
case error.POSITION_UNAVAILABLE:
|
|
|
alert("定位失败,位置信息是不可用");
|
|
|
break;
|
|
|
case error.TIMEOUT:
|
|
|
alert("定位失败,请求获取用户位置超时");
|
|
|
break;
|
|
|
case error.UNKNOWN_ERROR:
|
|
|
alert("定位失败,定位系统失效");
|
|
|
break;
|
|
|
}
|
|
|
},
|
|
|
userLocation: function() {
|
|
|
if (wechat.isWechat()) {
|
|
|
wechat.getLocation(successCallbck, failCallback);
|
|
|
} else {
|
|
|
switch (uni.getSystemInfoSync().platform) {
|
|
|
case 'android':
|
|
|
console.log('运行Android上')
|
|
|
var jwd = Android.getLocation();
|
|
|
// var jwd = "38.042836,114.496002";
|
|
|
if (jwd != '' && jwd != null && jwd != undefined) {
|
|
|
return jwd;
|
|
|
}
|
|
|
return "";
|
|
|
break;
|
|
|
case 'ios':
|
|
|
console.log('运行iOS上')
|
|
|
window.location.href = "https://www.baidu.com";
|
|
|
break;
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
getUser: function(that, obj, value, guid) {
|
|
|
console.log(obj, )
|
|
|
var url = that.$config.getOauthWxUser + "?type=" + obj + "&value=" + value + "&guid=" + guid;
|
|
|
console.log(url)
|
|
|
window.location.href = url;
|
|
|
},
|
|
|
getUserInfo: function(that, unionid, successCallMethod) {
|
|
|
var method = "LoginUN";
|
|
|
var sendData = {
|
|
|
"api_token": that.$md5.hexMD5("API" + method + "lvyou"),
|
|
|
"unionid": unionid
|
|
|
}
|
|
|
var data = {
|
|
|
"data": JSON.stringify(sendData),
|
|
|
"url": that.$config.LoginUN
|
|
|
}
|
|
|
that.$Request.post(that.$config.getAittoData, data).then(res => {
|
|
|
if (res.code == 0) {
|
|
|
uni.setStorageSync("user_token", aes.aesMinEncrypt(res.data.user_token));
|
|
|
uni.setStorageSync("user_info", res.data.userInfo);
|
|
|
successCallMethod();
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
icon: "none",
|
|
|
title: res.msg
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
saveWxUser: function(that, obj) {
|
|
|
var data = {
|
|
|
"data": obj,
|
|
|
userkey: that.$param.userkey
|
|
|
}
|
|
|
that.$Request.post(that.$config.saveUser, data).then(res => {
|
|
|
var flag = that.$util.isSuccess(res);
|
|
|
if (!flag) {
|
|
|
return;
|
|
|
}
|
|
|
var userid = res.data;
|
|
|
uni.setStorageSync("userid", aes.aesMinEncrypt(userid));
|
|
|
})
|
|
|
},
|
|
|
pay: function(obj, successCallbck) {
|
|
|
//是否在微信
|
|
|
if (wechat.isWechat()) {
|
|
|
wechat.pay(obj, successCallbck);
|
|
|
} else {
|
|
|
|
|
|
}
|
|
|
},
|
|
|
setLocation: function(lng, lat) {
|
|
|
this.$param.clng = lng;
|
|
|
this.$param.clat = lat;
|
|
|
},
|
|
|
getCurrentTime: function() {
|
|
|
let yyyy = new Date().getFullYear();
|
|
|
let mm = new Date().getMonth() + 1;
|
|
|
let dd = new Date().getDate();
|
|
|
let hh = new Date().getHours();
|
|
|
let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
|
|
|
let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
|
|
|
return yyyy + '/' + mm + '/' + dd + ' ' + hh + ':' + mf + ':' + ss;
|
|
|
},
|
|
|
getCurrentTime2: function() {
|
|
|
let yyyy = new Date().getFullYear();
|
|
|
let mm = new Date().getMonth() + 1;
|
|
|
let dd = new Date().getDate();
|
|
|
let hh = new Date().getHours();
|
|
|
let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
|
|
|
let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
|
|
|
return yyyy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
|
|
|
},
|
|
|
getCurrentTime3: function() {
|
|
|
let yyyy = new Date().getFullYear();
|
|
|
let mm = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1;
|
|
|
let dd = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate();
|
|
|
let hh = new Date().getHours() < 10 ? '0' + new Date().getHours() : new Date().getHours();
|
|
|
let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
|
|
|
let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
|
|
|
return yyyy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf;
|
|
|
},
|
|
|
getLocation: function(successCallbck, failCallback) {
|
|
|
// #ifdef H5
|
|
|
if (wechat.isWechat()) {
|
|
|
wechat.getLocation(successCallbck, failCallback);
|
|
|
} else {
|
|
|
switch (uni.getSystemInfoSync().platform) {
|
|
|
case 'android':
|
|
|
console.log('运行Android上');
|
|
|
// successCallbck("");
|
|
|
Android.getLocation();
|
|
|
break;
|
|
|
case 'ios':
|
|
|
console.log('运行iOS上');
|
|
|
// successCallbck("");
|
|
|
window.location.href = "https://www.baidu.com";
|
|
|
// this.$bridge.callHandler('getLocation', {}, function(response) {
|
|
|
// console.log('运行iOS上11');
|
|
|
// log('JS got response', response);
|
|
|
// });
|
|
|
// this.$bridge.callhandler('getLocation', params, (data) => {
|
|
|
// uni.showModal({
|
|
|
// title: '提示',
|
|
|
// content: 'ios进入getLocation方法'
|
|
|
// });
|
|
|
// console.log('getLocation>>>');
|
|
|
// });
|
|
|
// this.$bridge.registerhandler('iosCallBackGpsResult', (data, responseCallback) => {
|
|
|
// uni.showModal({
|
|
|
// title: '提示',
|
|
|
// content: 'ios进入iosCallBackGpsResult方法'
|
|
|
// });
|
|
|
// console.log('registerhandler>>>');
|
|
|
// // alert('JS Echo called with:', data) ;
|
|
|
// responseCallback(data);
|
|
|
// });
|
|
|
// window.webkit.messageHandlers.getLocation.postMessage();
|
|
|
break;
|
|
|
default:
|
|
|
// successCallbck("");
|
|
|
Android.getLocation();
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
// #endif
|
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
console.log("----util---getLocation---");
|
|
|
uni.getLocation({
|
|
|
type: 'gcj02',
|
|
|
success: function(res) {
|
|
|
console.log(res);
|
|
|
if (successCallbck) {
|
|
|
successCallbck(res);
|
|
|
}
|
|
|
},
|
|
|
fail: function(res) {
|
|
|
if (failCallback) {
|
|
|
failCallback(res);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
// #endif
|
|
|
},
|
|
|
/**
|
|
|
* 根据平台类型调用不同的方式打开地图
|
|
|
*/
|
|
|
openLocation: function(mapParam) {
|
|
|
// #ifdef H5
|
|
|
if (wechat.isWechat()) {
|
|
|
wechat.openLocation(mapParam);
|
|
|
} else {
|
|
|
|
|
|
}
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
|
uni.openLocation({
|
|
|
latitude: mapParam.latitude,
|
|
|
longitude: mapParam.longitude,
|
|
|
scale: mapParam.scale,
|
|
|
name: mapParam.name,
|
|
|
address: mapParam.address,
|
|
|
success: function() {
|
|
|
console.log('success');
|
|
|
}
|
|
|
|
|
|
});
|
|
|
// #endif
|
|
|
},
|
|
|
secsToStr: function($secs) {
|
|
|
var $r = "";
|
|
|
var $hours = "";
|
|
|
var $minutes = "";
|
|
|
if ($secs >= 3600) {
|
|
|
$hours = parseInt($secs / 3600);
|
|
|
$secs = $secs % 3600;
|
|
|
$r += $hours + ':';
|
|
|
}
|
|
|
if ($secs >= 60) {
|
|
|
$minutes = parseInt($secs / 60);
|
|
|
if ($minutes < 10) {
|
|
|
$secs = $secs % 60;
|
|
|
$r += "0" + $minutes + ':';
|
|
|
} else {
|
|
|
$secs = $secs % 60;
|
|
|
$r += $minutes + ':';
|
|
|
}
|
|
|
} else {
|
|
|
$r += '00:';
|
|
|
}
|
|
|
if ($secs < 10) {
|
|
|
$r += "0" + $secs;
|
|
|
} else {
|
|
|
$r += $secs;
|
|
|
}
|
|
|
return $r;
|
|
|
},
|
|
|
getCurrentTime: function() {
|
|
|
let yyyy = new Date().getFullYear();
|
|
|
let mm = new Date().getMonth() + 1;
|
|
|
let dd = new Date().getDate();
|
|
|
return yyyy + '-' + mm + '-' + dd;
|
|
|
},
|
|
|
isBlack: function(obj) {
|
|
|
return obj == undefined || obj == null || obj == "";
|
|
|
},
|
|
|
isSuccess: function(res) {
|
|
|
if (res.status == 200) {
|
|
|
return true;
|
|
|
} else if (res.status == 400) {
|
|
|
uni.showToast({
|
|
|
title: res.msg,
|
|
|
icon: "none"
|
|
|
})
|
|
|
return false;
|
|
|
} else if (res.status == 500) {
|
|
|
uni.showToast({
|
|
|
title: res.msg,
|
|
|
icon: "none"
|
|
|
})
|
|
|
return false;
|
|
|
}
|
|
|
},
|
|
|
/*
|
|
|
参数解释:
|
|
|
that:当前页的this对象,使用var that = this;的方式将that传递到这个方法
|
|
|
usertype:操作类型,是功能还是数据
|
|
|
功能:FUN
|
|
|
数据:
|
|
|
例如:SCENIC---景区
|
|
|
FOOD---美食
|
|
|
usefun: 如果usertype=FUN,则usefun为:
|
|
|
例如:景区
|
|
|
美食
|
|
|
如果usertype=SCENIC等其他值时,usefun为:对应数据的主键id
|
|
|
*/
|
|
|
saveOperatorLog: function(that, usertype, usefun) {
|
|
|
var data = {
|
|
|
"unionid": aes.aesDecrypt(uni.getStorageSync("unionid")),
|
|
|
"userkey": that.$param.userkey,
|
|
|
"usertype": usertype,
|
|
|
"usefun": usefun
|
|
|
}
|
|
|
that.$Request.post(that.$config.saveOperatorLog, data).then(res => {
|
|
|
if (res.code == 200) {
|
|
|
console.log("保存日志成功")
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
convertDateFromString: function(dateString) {
|
|
|
var ddd = new Date(dateString);
|
|
|
return ddd;
|
|
|
},
|
|
|
phone: function(TEL) {
|
|
|
var strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
|
|
|
if (strTemp.test(TEL)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
},
|
|
|
// 表情转码
|
|
|
utf16toEntities(str) {
|
|
|
const patt = /[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则
|
|
|
str = str.replace(patt, (char) => {
|
|
|
let H;
|
|
|
let L;
|
|
|
let code;
|
|
|
let s;
|
|
|
|
|
|
if (char.length === 2) {
|
|
|
H = char.charCodeAt(0); // 取出高位
|
|
|
L = char.charCodeAt(1); // 取出低位
|
|
|
code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00; // 转换算法
|
|
|
s = `&#${code};`;
|
|
|
} else {
|
|
|
s = char;
|
|
|
}
|
|
|
|
|
|
return s;
|
|
|
});
|
|
|
|
|
|
return str;
|
|
|
},
|
|
|
// 表情解码
|
|
|
entitiestoUtf16(strObj) {
|
|
|
const patt = /&#\d+;/g;
|
|
|
const arr = strObj.match(patt) || [];
|
|
|
|
|
|
let H;
|
|
|
let L;
|
|
|
let code;
|
|
|
|
|
|
for (let i = 0; i < arr.length; i += 1) {
|
|
|
code = arr[i];
|
|
|
code = code.replace('&#', '').replace(';', '');
|
|
|
// 高位
|
|
|
H = Math.floor((code - 0x10000) / 0x400) + 0xD800;
|
|
|
// 低位
|
|
|
L = ((code - 0x10000) % 0x400) + 0xDC00;
|
|
|
code = `&#${code};`;
|
|
|
const s = String.fromCharCode(H, L);
|
|
|
strObj = strObj.replace(code, s);
|
|
|
}
|
|
|
return strObj;
|
|
|
}
|
|
|
} |