|
|
|
|
@ -3,7 +3,9 @@
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
import { lang } from 'moment';
|
|
|
|
|
import {
|
|
|
|
|
lang
|
|
|
|
|
} from 'moment';
|
|
|
|
|
|
|
|
|
|
const base64ToFile = (dataurl, filename = 'file') => {
|
|
|
|
|
let arr = dataurl.split(',')
|
|
|
|
|
@ -62,12 +64,12 @@ const isNull = (p) => {
|
|
|
|
|
const isMobile = (phoneNumber) => {
|
|
|
|
|
const regex = /^1[3-9]\d{9}$/;
|
|
|
|
|
return regex.test(phoneNumber);
|
|
|
|
|
}
|
|
|
|
|
// 分享
|
|
|
|
|
const shareInfo = {
|
|
|
|
|
title:"蟹太太",
|
|
|
|
|
imageUrl:"/static/share.jpg"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 分享
|
|
|
|
|
const shareInfo = {
|
|
|
|
|
title: "蟹太太",
|
|
|
|
|
imageUrl: "/static/share.jpg"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算距离
|
|
|
|
|
const getDistance = (la1, lo1, la2, lo2) => { // 当前的纬度,当前的经度,接口拿到的纬度,接口拿到的经度
|
|
|
|
|
@ -91,11 +93,11 @@ const getDistance = (la1, lo1, la2, lo2) => { // 当前的纬度,当前的经
|
|
|
|
|
return distance.toFixed(2) + '公里'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 打开导航
|
|
|
|
|
const toMapAPP = (lat,lng,name) => {
|
|
|
|
|
let that = this
|
|
|
|
|
const lat1 = parseFloat(lat)
|
|
|
|
|
const toMapAPP = (lat, lng, name) => {
|
|
|
|
|
let that = this
|
|
|
|
|
const lat1 = parseFloat(lat)
|
|
|
|
|
const lng1 = parseFloat(lng)
|
|
|
|
|
// 获取用户是否开启 授权获取当前的地理位置、速度的权限。
|
|
|
|
|
uni.getSetting({
|
|
|
|
|
@ -150,8 +152,8 @@ const toMapAPP = (lat,lng,name) => {
|
|
|
|
|
console.log('有授权');
|
|
|
|
|
// 有权限则直接获取
|
|
|
|
|
uni.openLocation({
|
|
|
|
|
latitude: lat1, //到达的纬度
|
|
|
|
|
longitude: lng1, //到达的经度
|
|
|
|
|
latitude: lat1, //到达的纬度
|
|
|
|
|
longitude: lng1, //到达的经度
|
|
|
|
|
name: name, //到达的名字
|
|
|
|
|
scale: 12,
|
|
|
|
|
success() {
|
|
|
|
|
@ -162,18 +164,52 @@ const toMapAPP = (lat,lng,name) => {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// 检查是否空对象
|
|
|
|
|
const isEmptyObject = (obj) => {
|
|
|
|
|
// 检查传入参数是否为一个对象
|
|
|
|
|
if (typeof obj !== 'object' || obj === null) {
|
|
|
|
|
throw new Error('Input must be an object');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 检查是否空对象
|
|
|
|
|
const isEmptyObject = (obj) => {
|
|
|
|
|
// 检查传入参数是否为一个对象
|
|
|
|
|
if (typeof obj !== 'object' || obj === null) {
|
|
|
|
|
throw new Error('Input must be an object');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用Object.keys()方法获取对象的属性键数组,并检查其长度是否为0
|
|
|
|
|
return Object.keys(obj).length === 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const parseAddress = (address) => {
|
|
|
|
|
// 正则表达式匹配省市区和直辖市
|
|
|
|
|
// 直辖市
|
|
|
|
|
const regex = /^(.*?省|.*?市|.*?自治区|.*?特别行政区)(.*?市|.*?自治州|.*?盟|.*?县|.*?区|.*?旗)?/;
|
|
|
|
|
// 省市区
|
|
|
|
|
const regex1 = /^(.*?省|.*?市|.*?自治区|.*?特别行政区)(.*?市|.*?自治州|.*?盟)(.*?区|.*?县|.*?市|.*?旗)/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 使用Object.keys()方法获取对象的属性键数组,并检查其长度是否为0
|
|
|
|
|
return Object.keys(obj).length === 0;
|
|
|
|
|
// 初始化返回数组
|
|
|
|
|
let regionArray = [];
|
|
|
|
|
let match = null
|
|
|
|
|
// 检查是否是直辖市
|
|
|
|
|
const directCities = ['北京市', '天津市', '上海市', '重庆市'];
|
|
|
|
|
if(directCities.some(city => address.includes(city))){
|
|
|
|
|
match = address.match(regex);
|
|
|
|
|
}else{
|
|
|
|
|
match = address.match(regex1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("address",address,match)
|
|
|
|
|
if (match) {
|
|
|
|
|
if (directCities.includes(match[1])) {
|
|
|
|
|
// 直辖市没有省这一级,直接将市名和区名放入数组
|
|
|
|
|
regionArray = [match[1], '市辖区', match[2]];
|
|
|
|
|
} else {
|
|
|
|
|
// 非直辖市,包含省市区
|
|
|
|
|
regionArray = [match[1], match[2], match[3]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return regionArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
base64ToFile,
|
|
|
|
|
toast,
|
|
|
|
|
@ -182,8 +218,9 @@ export {
|
|
|
|
|
isOnlyChinese,
|
|
|
|
|
isNull,
|
|
|
|
|
isMobile,
|
|
|
|
|
getDistance,
|
|
|
|
|
toMapAPP,
|
|
|
|
|
shareInfo,
|
|
|
|
|
isEmptyObject
|
|
|
|
|
getDistance,
|
|
|
|
|
toMapAPP,
|
|
|
|
|
shareInfo,
|
|
|
|
|
isEmptyObject,
|
|
|
|
|
parseAddress
|
|
|
|
|
}
|