You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
306 lines
7.0 KiB
306 lines
7.0 KiB
4 months ago
|
// 获取路径参数
|
||
|
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.passportValid = (val) => {
|
||
|
return /^([a-zA-z]|[0-9]){5,17}$/.test(val);
|
||
|
}
|
||
|
|
||
|
// 台胞证正则
|
||
|
Vue.prototype.taiwanValid = (val) => {
|
||
|
return /^\d{8}|^[a-zA-Z0-9]{10}|^\d{18}$/.test(val);
|
||
|
}
|
||
|
|
||
|
// 港澳通行证正则
|
||
|
Vue.prototype.gangaoValid = (val) => {
|
||
|
return /^([A-Z]\d{6,10}(\(\w{1}\))?)$/.test(val);
|
||
|
}
|
||
|
|
||
|
// 外国人永久居留证正则
|
||
|
Vue.prototype.foreignerValid = (val) => {
|
||
|
return /(^[A-Za-z]{3})([0-9]{12}$)/.test(val);
|
||
|
}
|
||
|
|
||
|
// 军官证正则
|
||
|
Vue.prototype.officerValid = (val) => {
|
||
|
return /^[\u4E00-\u9FA5](字第)([0-9a-zA-Z]{4,8})(号?)$/.test(val);
|
||
|
}
|
||
|
|
||
|
// 邮箱验证正则
|
||
|
Vue.prototype.emailValid = (val) => {
|
||
|
return /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(val)
|
||
|
}
|
||
|
|
||
|
//判断电话号码格式
|
||
|
Vue.prototype.IsTel = tel => {
|
||
|
var pattern = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
|
||
|
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.showImg = img => {
|
||
|
if (!img) return;
|
||
|
let timeStamp = new Date().getTime()
|
||
|
if (img.indexOf('https://') != -1 || img.indexOf('http://') != -1) {
|
||
|
return img+"?timestamp="+timeStamp;
|
||
|
} else {
|
||
|
return Vue.prototype.NEWAPIURL + img +"?timestamp="+timeStamp;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 获取经纬度
|
||
|
Vue.prototype.getLocation = function(callback) {
|
||
|
return
|
||
|
// 检查权限状态
|
||
|
uni.getSetting({
|
||
|
success: (res) => {
|
||
|
if (res.authSetting['scope.userLocation'] === false) {
|
||
|
// 已拒绝权限,引导用户去设置
|
||
|
uni.showModal({
|
||
|
title: '权限申请',
|
||
|
content: '需要位置权限才能获取当前城市',
|
||
|
confirmText: '去设置',
|
||
|
success: (res) => {
|
||
|
if (res.confirm) {
|
||
|
uni.openSetting();
|
||
|
} else {
|
||
|
callback && callback(null, {
|
||
|
errMsg: '用户拒绝授权'
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
// 未授权或已授权,请求位置
|
||
|
this._requestLocation(callback);
|
||
|
}
|
||
|
},
|
||
|
fail: (err) => {
|
||
|
console.error('获取权限状态失败:', err);
|
||
|
callback && callback(null, err);
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
// 私有方法:请求位置
|
||
|
Vue.prototype._requestLocation = function(callback) {
|
||
|
// 直接获取位置(微信小程序不需要先调用startLocationUpdate)
|
||
|
uni.getLocation({
|
||
|
type: 'wgs84', // 坐标系类型
|
||
|
success: (res) => {
|
||
|
console.log('获取位置成功:', res);
|
||
|
const location = {
|
||
|
lat: res.latitude,
|
||
|
lon: res.longitude
|
||
|
};
|
||
|
uni.setStorageSync('location', location);
|
||
|
callback && callback(location);
|
||
|
},
|
||
|
fail: (err) => {
|
||
|
console.error('获取位置失败:', err);
|
||
|
|
||
|
if (err.errMsg.includes('auth deny')) {
|
||
|
// 权限被拒绝,引导用户去设置
|
||
|
uni.showModal({
|
||
|
title: '权限申请',
|
||
|
content: '需要位置权限才能获取当前城市',
|
||
|
confirmText: '去设置',
|
||
|
success: (res) => {
|
||
|
if (res.confirm) {
|
||
|
uni.openSetting();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
callback && callback(null, err);
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
// 路由页面跳转
|
||
|
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.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;
|
||
|
}
|
||
|
|
||
|
// 是否接收订阅消息
|
||
|
Vue.prototype.getSubscribeMessage = () => {
|
||
|
const templateIds = [
|
||
|
// 退款成功通知
|
||
|
'hRZoiEES2BWtKb6Xgsnn8khLQH9un5j_11qu0bwlhfE',
|
||
|
// 订单核销通知
|
||
|
// '7D-JP7o0nQ_NiQk2w8mBs8jdT1_7ofvyBN-G9NLY2Zk',
|
||
|
// 订单支付成功通知
|
||
|
// '6cHez9KDlCDp1_nWUlUSV7qEaahIQWmYVlOCE-J6ODQ',
|
||
|
// 出票失败提醒
|
||
|
// 'G-N85zK2gPwgTRZWQrtHZo_-5TFcdAqBxSk4qsqcvVc',
|
||
|
// 出票结果通知
|
||
|
'YyTCUIYBnrj9CyKks8cOjNX_Rk8a4yVdswMP-zXVbhc'
|
||
|
]
|
||
|
uni.requestSubscribeMessage({
|
||
|
tmplIds: templateIds,
|
||
|
complete(res) {
|
||
|
uni.navigateTo({
|
||
|
url: '/subPackages/order/trades'
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
// 金刚区头图
|
||
|
Vue.prototype.getHeadImg = id => {
|
||
|
return Vue.prototype.Post({id: id},'/api/article/getArticleById').then(res => {
|
||
|
return res.data.image
|
||
|
});
|
||
|
}
|
||
|
// 判断是否去外部链接
|
||
|
Vue.prototype.goOtherDetail = (item,type) => {
|
||
|
if(item.link_type == 1) {
|
||
|
// 外部小程序
|
||
|
uni.navigateToMiniProgram({
|
||
|
shortLink: item.ext_link
|
||
|
})
|
||
|
return true
|
||
|
}else if(item.link_type == 2){
|
||
|
// 外部H5
|
||
|
uni.navigateTo({
|
||
|
url: '/subPackages/webPage/webPage?url=' + item.ext_link
|
||
|
});
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
// 根据类型判断详情页
|
||
|
Vue.prototype.goDetailByType= function(item){
|
||
|
let res = this.goOtherDetail(item)
|
||
|
if (res) {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
uni.navigateTo({
|
||
|
url: `/subPackages/techan/detail?id=?${item.id}`
|
||
|
})
|
||
|
|
||
|
}
|