|
|
|
// 获取路径参数
|
|
|
|
import Vue from "vue";
|
|
|
|
|
|
|
|
// 格式化富文本
|
|
|
|
Vue.prototype.formateRichText = str => {
|
|
|
|
if (!str) return "";
|
|
|
|
var reg = new RegExp("<img", "g");
|
|
|
|
str = str.replace(reg, "<img class='sz-xcx-fwb-img' width='100%'")
|
|
|
|
reg = new RegExp("<IMG", "g");
|
|
|
|
str = str.replace(reg, "<img class='sz-xcx-fwb-img' width='100%'")
|
|
|
|
reg = new RegExp(" ", "g");
|
|
|
|
str = str.replace(reg, '<span style="width: 8rpx;display: inline-block;"></span>')
|
|
|
|
reg = new RegExp("section", "g");
|
|
|
|
str = str.replace(reg, 'div');
|
|
|
|
reg = new RegExp("↵", "g");
|
|
|
|
str = str.replace(reg, '<br />');
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取路径参数
|
|
|
|
Vue.prototype.getUrlPara = url => {
|
|
|
|
let arrUrl = url.split("?");
|
|
|
|
let para = arrUrl[1];
|
|
|
|
return para ? para.split('&') : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 中文姓名规则
|
|
|
|
Vue.prototype.idChinaName = (val) => {
|
|
|
|
var pattern = /^[\u4E00-\u9FA5]{2,4}$/
|
|
|
|
return pattern.test(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 身份证验证规则
|
|
|
|
Vue.prototype.idCardNumber = (val) => {
|
|
|
|
var pattern = /^\d{17}(\d{1}|[X|x])$/
|
|
|
|
return pattern.test(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 判断电话号码格式
|
|
|
|
Vue.prototype.IsTel = tel => {
|
|
|
|
var pattern = /^1\d{10}$/;
|
|
|
|
return pattern.test(tel);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 判断澳门电话号码格式
|
|
|
|
Vue.prototype.IsTelMacau = tel => {
|
|
|
|
var pattern = /^\d{8}$/;
|
|
|
|
return pattern.test(tel);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 验证码格式
|
|
|
|
Vue.prototype.IsCode = code => {
|
|
|
|
var pattern = /^\d{6}$/;
|
|
|
|
return pattern.test(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 判断邮箱
|
|
|
|
Vue.prototype.IsMail = code => {
|
|
|
|
var pattern = /^\w+@[a-z0-9]+\.[a-z]+$/i;
|
|
|
|
return pattern.test(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 图片显示判断
|
|
|
|
Vue.prototype.showImg = img => {
|
|
|
|
if (img.indexOf('https://') != -1 || img.indexOf('http://') != -1) {
|
|
|
|
return img;
|
|
|
|
} else {
|
|
|
|
return 'https://tongli.sz-trip.com' + img;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取经纬度
|
|
|
|
Vue.prototype.getLocation = () => {
|
|
|
|
uni.startLocationUpdate({
|
|
|
|
success: res => {
|
|
|
|
uni.onLocationChange(data => {
|
|
|
|
uni.setStorageSync('location', {
|
|
|
|
lat: data.latitude,
|
|
|
|
lon: data.longitude
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 金刚区头图
|
|
|
|
Vue.prototype.getHeadImg = type => {
|
|
|
|
return Vue.prototype.Post(
|
|
|
|
{
|
|
|
|
type,
|
|
|
|
},
|
|
|
|
'/api/scene/getKumgangHeadImgList'
|
|
|
|
).then(res => {
|
|
|
|
return res.data[0].image
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// 路由页面跳转
|
|
|
|
Vue.prototype.gotoPath = path => {
|
|
|
|
uni.navigateTo({
|
|
|
|
url: path
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 返回上一页
|
|
|
|
Vue.prototype.goBack = () => {
|
|
|
|
getCurrentPages().length > 1 ? uni.navigateBack({}) : uni.switchTab({
|
|
|
|
url: '/pages/index/index'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 打开地图
|
|
|
|
Vue.prototype.openLocation = (lat,lon) => {
|
|
|
|
uni.openLocation({
|
|
|
|
latitude: Number(lat),
|
|
|
|
longitude: Number(lon),
|
|
|
|
success: function () {
|
|
|
|
console.log('success');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// 列表详情
|
|
|
|
Vue.prototype.goDetail = (item,type) => {
|
|
|
|
if(item.link_type == 0) {
|
|
|
|
// 本小程序页面
|
|
|
|
uni.navigateTo({
|
|
|
|
url: '/subPackages/detail/detail?type=' + type + '&id=' + item.id
|
|
|
|
})
|
|
|
|
}else if(item.link_type == 1) {
|
|
|
|
// 外部小程序
|
|
|
|
uni.navigateToMiniProgram({
|
|
|
|
shortLink: item.ext_link
|
|
|
|
})
|
|
|
|
}else {
|
|
|
|
// 外部H5
|
|
|
|
uni.navigateTo({
|
|
|
|
url: '/subPackages/webPage/webPage?url=' + item.ext_link
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 拨打电话
|
|
|
|
Vue.prototype.clickPhone = (phone) => {
|
|
|
|
uni.makePhoneCall({
|
|
|
|
phoneNumber:phone
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
//周几
|
|
|
|
Vue.prototype.ShowDateDay = day => {
|
|
|
|
let stateTxt = "";
|
|
|
|
switch (day) {
|
|
|
|
case 0:
|
|
|
|
stateTxt = '周日'
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
stateTxt = '周一'
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
stateTxt = '周二'
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
stateTxt = '周三'
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
stateTxt = '周四'
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
stateTxt = '周五'
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
stateTxt = '周六'
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return stateTxt
|
|
|
|
}
|
|
|
|
|
|
|
|
Date.prototype.Format = function(fmt)
|
|
|
|
{ //author: meizz
|
|
|
|
var o = {
|
|
|
|
"Y+" : this.getFullYear(), //月份
|
|
|
|
"M+" : this.getMonth()+1, //月份
|
|
|
|
"d+" : this.getDate(), //日
|
|
|
|
"h+" : this.getHours(), //小时
|
|
|
|
"m+" : this.getMinutes(), //分
|
|
|
|
"s+" : this.getSeconds(), //秒
|
|
|
|
"q+" : Math.floor((this.getMonth()+3)/3), //季度
|
|
|
|
"S" : this.getMilliseconds() //毫秒
|
|
|
|
};
|
|
|
|
if(/(y+)/.test(fmt))
|
|
|
|
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
|
|
|
|
for(var k in o)
|
|
|
|
if(new RegExp("("+ k +")").test(fmt))
|
|
|
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
|
|
|
|
return fmt;
|
|
|
|
}
|