2022-04-07 10:14:28 +00:00
|
|
|
|
const app = getApp();
|
2022-03-28 10:40:02 +00:00
|
|
|
|
const tools = {
|
|
|
|
|
timer:'',
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 埋点倒计时
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
daoTime(){
|
|
|
|
|
let daoTime = uni.getStorageSync('daoTime')
|
|
|
|
|
if(daoTime==''){//初次判断倒计时是否为空
|
|
|
|
|
uni.setStorageSync('daoTime',60)//设置倒计时
|
|
|
|
|
daoTime = uni.getStorageSync('daoTime')
|
|
|
|
|
this.timer = setInterval(()=>{
|
|
|
|
|
uni.setStorageSync('daoTime',daoTime--)//设置倒计时
|
|
|
|
|
if(uni.getStorageSync('daoTime')<=0 || uni.getStorageSync('maiList').length==5){
|
|
|
|
|
uni.removeStorageSync('daoTime')//清空倒计时
|
|
|
|
|
clearInterval(this.timer)//关闭倒计时
|
|
|
|
|
// console.log('上/报,埋点');
|
|
|
|
|
uni.removeStorageSync('maiList')//清空上报参数
|
|
|
|
|
this.daoTime()//重新倒计时
|
|
|
|
|
}
|
|
|
|
|
},1000)
|
|
|
|
|
} else {//继续当前倒计时倒计
|
|
|
|
|
this.timer = setInterval(()=>{
|
|
|
|
|
uni.setStorageSync('daoTime',daoTime--)//设置倒计时
|
|
|
|
|
if(uni.getStorageSync('daoTime')<=0 || uni.getStorageSync('maiList').length==5){
|
|
|
|
|
uni.removeStorageSync('daoTime')//清空倒计时
|
|
|
|
|
clearInterval(this.timer)//关闭倒计时
|
|
|
|
|
// console.log('上报,埋点');
|
|
|
|
|
uni.removeStorageSync('maiList')//清空上报参数
|
|
|
|
|
this.daoTime()//重新倒计时
|
|
|
|
|
}
|
|
|
|
|
},1000)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
closeTimer(){
|
|
|
|
|
clearInterval(this.timer)//关闭倒计时
|
|
|
|
|
console.log('倒计时清空了');
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 手机号验证
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
isPhone:function(phone){
|
|
|
|
|
// 手机号正则表达式
|
|
|
|
|
let reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
|
|
|
|
|
return !reg_tel.test(phone);
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 电子邮箱验证
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
isEmail(email){
|
|
|
|
|
let reg_email = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
|
|
|
|
|
return !reg_email.test(email);
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 身份证验证
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
isIdentity(identity) {
|
|
|
|
|
let reg_identity = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
|
|
|
|
|
return !reg_identity.test(identity);
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 手机号中间四位用"****"带替
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
hideMPhone(phone){
|
|
|
|
|
return `${phone.substr(0, 3)}****${phone.substr(7)}`
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 手机号中间加字符
|
|
|
|
|
*/
|
|
|
|
|
phoneAddChat(phone,character=' ',startNum=3,endNum=7){
|
2022-04-07 10:14:28 +00:00
|
|
|
|
let phoneStr = phone;
|
|
|
|
|
phoneStr = phoneStr.replace(/\s*/g, "");
|
|
|
|
|
var phoneArr = [];
|
|
|
|
|
for(var i = 0; i < phoneStr.length; i++){
|
|
|
|
|
if (i==startNum||i==endNum){
|
|
|
|
|
phoneArr.push(`${character}` + phoneStr.charAt(i));
|
|
|
|
|
} else {
|
|
|
|
|
phoneArr.push(phoneStr.charAt(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
phone = phoneArr.join("");
|
|
|
|
|
return phone;
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 昵称从第一个字开始,后面的都用"*"代替
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
hideName(name,num){
|
|
|
|
|
return `${name.substr(0, 1)}****${name.substr(name.length-1)}`
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 金额转换各三位数使用英文","隔开
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
changeNum(num){
|
|
|
|
|
if (num) {
|
|
|
|
|
// 针对整数部分进行格式化处理,这是此方法的核心,也是稍难理解的一个地方,逆向的来思考或者采用简单的事例来实现就容易多了
|
|
|
|
|
/*
|
|
|
|
|
也可以这样想象,现在有一串数字字符串在你面前,如果让你给他家千分位的逗号的话,你是怎么来思考和操作的?
|
|
|
|
|
字符串长度为0/1/2/3时都不用添加
|
|
|
|
|
字符串长度大于3的时候,从右往左数,有三位字符就加一个逗号,然后继续往前数,直到不到往前数少于三位字符为止
|
|
|
|
|
*/
|
|
|
|
|
num = num+''; // 数字转换为字符串,数字是没有.length属性的
|
|
|
|
|
for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
|
|
|
|
|
num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3))
|
|
|
|
|
}
|
|
|
|
|
// 将数据(符号、整数部分、小数部分)整体组合返回
|
|
|
|
|
return num;
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 整数添加.00,小数就不添加
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
addXiaoShu(num){
|
|
|
|
|
console.log(num,120);
|
|
|
|
|
let str = num.toString();
|
|
|
|
|
if(str.length > 9){
|
|
|
|
|
str = str*1;
|
|
|
|
|
str = str.toFixed(2);
|
|
|
|
|
str = str+'';
|
|
|
|
|
}
|
2022-04-07 10:14:28 +00:00
|
|
|
|
return str.includes('.') ? str : str = num + '.00';
|
2022-03-28 10:40:02 +00:00
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* type:+加、-减、*乘、/除
|
|
|
|
|
* len:小数后保留几位
|
|
|
|
|
* @description 数字换算
|
|
|
|
|
*/
|
|
|
|
|
operationEv(num1,num2,type,len=2){
|
2022-03-28 10:40:02 +00:00
|
|
|
|
// 将数字转化成字符串
|
|
|
|
|
num1 = num1.toString();
|
|
|
|
|
num2 = num2.toString();
|
|
|
|
|
// 获取小数点的位置
|
|
|
|
|
var index1 = num1.indexOf(".");
|
|
|
|
|
var index2 = num2.indexOf(".");
|
|
|
|
|
// 如果小数点存在,那么就再获取各自的小数位数
|
|
|
|
|
var ws1 = 0;
|
|
|
|
|
var ws2 = 0;
|
|
|
|
|
if(index1 != -1){
|
|
|
|
|
ws1 = num1.split(".")[1].length;
|
|
|
|
|
}
|
|
|
|
|
if(index2 != -1){
|
|
|
|
|
ws2 = num2.split(".")[1].length;
|
|
|
|
|
}
|
|
|
|
|
// 看谁的小数位数大,谁的小数位数小
|
|
|
|
|
var bigger = (ws1 > ws2) ? ws1 : ws2;
|
|
|
|
|
var smaller = (ws1 < ws2) ? ws1 : ws2;
|
|
|
|
|
// 计算得到需要补齐的0的个数
|
|
|
|
|
var zerosCount = bigger - smaller;
|
|
|
|
|
// 好了,现在不管三七二十,全部去除小数点
|
|
|
|
|
num1 = num1.replace(".","");
|
|
|
|
|
num2 = num2.replace(".","");
|
|
|
|
|
// 比较num1和num2谁大,比较方法就是看谁是smaller,是smaller的一方就补0
|
|
|
|
|
if(ws1 == smaller){
|
|
|
|
|
for (var i = 0; i < zerosCount; i++) {
|
|
|
|
|
num1 += "0";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (var i = 0; i < zerosCount; i++) {
|
|
|
|
|
num2 += "0";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 开始计算
|
|
|
|
|
var sum = "";
|
|
|
|
|
if(type=="+"){
|
|
|
|
|
// 加
|
|
|
|
|
sum = parseInt(num1) + parseInt(num2);
|
|
|
|
|
}
|
|
|
|
|
if(type=="-"){
|
|
|
|
|
// 减
|
|
|
|
|
sum = parseInt(num1) - parseInt(num2);
|
|
|
|
|
}
|
|
|
|
|
if(type=="*"){
|
|
|
|
|
// 乘
|
|
|
|
|
sum = parseInt(num1) * parseInt(num2);
|
|
|
|
|
}
|
|
|
|
|
if(type=="/"){
|
|
|
|
|
// 除
|
|
|
|
|
sum = parseInt(num1) / parseInt(num2);
|
|
|
|
|
}
|
|
|
|
|
// 根据较大的小数位数计算倍数
|
|
|
|
|
var beishu = 1;
|
|
|
|
|
for (var i = 0; i < bigger; i++) {
|
|
|
|
|
beishu = beishu*10;
|
|
|
|
|
}
|
|
|
|
|
sum = sum/beishu;
|
|
|
|
|
if(type=="*"){
|
|
|
|
|
switch (bigger){
|
|
|
|
|
case 1:
|
|
|
|
|
sum = sum / 10;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
sum = sum / 100;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
sum = sum / 1000;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(type=="/"){
|
|
|
|
|
switch (bigger){
|
|
|
|
|
case 1:
|
|
|
|
|
sum = sum * 10;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
sum = sum * 100;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
sum = sum * 1000;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
len!=0 ? sum = sum.toFixed(len) : '';
|
|
|
|
|
return sum;
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 金额输入框验证
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
checkPrice(number,zong){
|
|
|
|
|
let reg = /^[0-9]*$/;//数字正则表达式
|
|
|
|
|
let newObj = {}
|
|
|
|
|
zong = parseInt(zong).toString()//取小数点左边的整数
|
|
|
|
|
if(!reg.test(number)){//不是数字时
|
|
|
|
|
newObj = {
|
|
|
|
|
len:zong.length,//动态设置长度
|
|
|
|
|
val:zong//动态设置值正整数的总金额
|
|
|
|
|
}
|
|
|
|
|
} else {//是数字时
|
|
|
|
|
newObj = {
|
|
|
|
|
len:zong.length,
|
|
|
|
|
val:number//动态设置当前输入的值
|
|
|
|
|
}
|
|
|
|
|
if(number*1 > zong*1){//输入的金额大于总金额
|
|
|
|
|
newObj.val = zong//赋值总金额
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return newObj
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 提示方法
|
|
|
|
|
*/
|
2022-04-07 10:14:28 +00:00
|
|
|
|
showToast: function(msg, icon='none',time) {
|
2022-03-28 10:40:02 +00:00
|
|
|
|
// 弹框显示时间:默认2秒
|
|
|
|
|
var newTime = 2000
|
|
|
|
|
if (time) {newTime = time;}
|
|
|
|
|
return uni.showToast({
|
|
|
|
|
title: msg,
|
2022-04-07 10:14:28 +00:00
|
|
|
|
icon: icon,
|
2022-03-28 10:40:02 +00:00
|
|
|
|
duration:newTime
|
|
|
|
|
})
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @param {Object} str
|
|
|
|
|
* @description 富文本
|
|
|
|
|
*/
|
2022-04-07 10:14:28 +00:00
|
|
|
|
escape2Html(str) {
|
2022-03-28 10:40:02 +00:00
|
|
|
|
var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
|
|
|
|
|
return str.replace(/&(lt|gt|nbsp|amp|quot|src);/ig, function (all, t) {
|
|
|
|
|
return arrEntities[t];
|
|
|
|
|
})
|
|
|
|
|
.replace('<section', '<div')
|
|
|
|
|
.replace(/\<img/g, '<img @tap="pre" style="max-width:100%!important;height:auto" ')
|
|
|
|
|
.replace(/src=\"/g,'src="https://oss.hmzfyy.cn');
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 检查网络状态
|
|
|
|
|
*/
|
2022-04-07 10:14:28 +00:00
|
|
|
|
networkStatus(){
|
2022-03-28 10:40:02 +00:00
|
|
|
|
uni.getNetworkType({
|
2022-04-07 10:14:28 +00:00
|
|
|
|
success: (res)=> {
|
2022-03-28 10:40:02 +00:00
|
|
|
|
console.log('当前网络状态:',res.networkType);//none:当前无网络连接
|
|
|
|
|
if(res.networkType=='none'){
|
|
|
|
|
uni.setStorageSync('isNet',false)
|
|
|
|
|
} else {
|
|
|
|
|
uni.setStorageSync('isNet',true);
|
|
|
|
|
// 微信小程序原生API性能优化
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
// 连网下,检测小程序是否有更新
|
2022-04-07 10:14:28 +00:00
|
|
|
|
this.checkUpdate();
|
2022-03-28 10:40:02 +00:00
|
|
|
|
// #endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description app、小程序的检测版本并更新
|
|
|
|
|
*/
|
2022-04-07 10:14:28 +00:00
|
|
|
|
checkUpdate(){
|
|
|
|
|
// 检测app
|
|
|
|
|
// #ifdef APP-PLUS
|
|
|
|
|
|
|
|
|
|
// #endif
|
|
|
|
|
//检测小程序
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
var self = this;
|
|
|
|
|
// 获取小程序更新机制兼容
|
|
|
|
|
if (wx.canIUse('getUpdateManager')) {
|
|
|
|
|
const updateManager = wx.getUpdateManager();//1. 检查小程序是否有新版本发布
|
|
|
|
|
updateManager.onCheckForUpdate(function(res) {// 请求完新版本信息的回调
|
|
|
|
|
if (res.hasUpdate) {
|
|
|
|
|
//检测到新版本,需要更新,给出提示
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '更新提示',
|
|
|
|
|
content: '检测到新版本,是否下载新版本并重启小程序?',
|
|
|
|
|
success: function(res) {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
//2. 用户确定下载更新小程序,小程序下载及更新静默进行
|
|
|
|
|
self.downLoadAndUpdate(updateManager)
|
|
|
|
|
// 清除所有缓存
|
|
|
|
|
uni.clearStorage();
|
|
|
|
|
uni.clearStorageSync();
|
|
|
|
|
} else if (res.cancel) {
|
|
|
|
|
//用户点击取消按钮的处理,如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '温馨提示~',
|
|
|
|
|
content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦~',
|
|
|
|
|
showCancel:false,//隐藏取消按钮
|
|
|
|
|
confirmText:"确定更新",//只保留确定更新按钮
|
|
|
|
|
success: function(res) {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
//下载新版本,并重新应用
|
|
|
|
|
self.downLoadAndUpdate(updateManager)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else { // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '提示',
|
|
|
|
|
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 下载小程序新版本并重启应用
|
|
|
|
|
* */
|
|
|
|
|
downLoadAndUpdate(updateManager){
|
|
|
|
|
var self = this;
|
|
|
|
|
wx.showLoading(); //静默下载更新小程序新版本
|
|
|
|
|
updateManager.onUpdateReady(function () {
|
|
|
|
|
wx.hideLoading(); //新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
|
|
|
updateManager.applyUpdate();
|
|
|
|
|
// 清除缓存
|
|
|
|
|
uni.clearStorageSync();
|
|
|
|
|
uni.clearStorage();
|
|
|
|
|
})
|
|
|
|
|
updateManager.onUpdateFailed(function () { // 新的版本下载失败
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '已经有新版本了哟~',
|
|
|
|
|
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @param {Object} data
|
|
|
|
|
* @description 文本复制
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
clickCopy(data){
|
|
|
|
|
uni.setClipboardData({
|
|
|
|
|
data: data,
|
|
|
|
|
success: ()=> {
|
|
|
|
|
uni.showToast({title: '复制成功',duration: 2000,icon: 'none'});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 刷新token
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
refreshToken(){
|
|
|
|
|
console.log('进入检测token是否过期');
|
|
|
|
|
var date = new Date();
|
|
|
|
|
var timestamp = date.getTime();//精确到毫秒
|
|
|
|
|
// 如果过期时间 减 10分钟 小于当前时间,刷新token
|
|
|
|
|
if((uni.getStorageSync('expire')*1000 - 600000) < timestamp) {
|
|
|
|
|
uni.login({
|
|
|
|
|
provider: 'weixin',
|
|
|
|
|
success: (res)=> {
|
|
|
|
|
if (res.code) {
|
|
|
|
|
var params = {code:res.code}
|
|
|
|
|
uni.request({
|
2022-04-07 10:14:28 +00:00
|
|
|
|
url: `${app.globalData.hostapi}/api/user/login`,
|
2022-03-28 10:40:02 +00:00
|
|
|
|
method: 'post',
|
|
|
|
|
data: params,
|
|
|
|
|
header: {
|
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
|
'Authorization': 'Bearer '+uni.getStorageSync('token') || ''
|
|
|
|
|
},
|
|
|
|
|
success: res => {
|
|
|
|
|
if(res.data.data.token!=''){
|
|
|
|
|
uni.setStorageSync('token',res.data.data.token)//缓存token
|
|
|
|
|
uni.setStorageSync('openid',res.data.data.openid)//缓存Openid
|
|
|
|
|
uni.setStorageSync('expire',res.data.data.expire)//缓存失效时间(时间戳格式)
|
|
|
|
|
uni.setStorageSync('is_active',res.data.data.is_active)//是否第一次授权
|
|
|
|
|
uni.setStorageSync('phone_active',res.data.data.phone_active)//是否绑定手机号
|
|
|
|
|
uni.setStorageSync('userId',res.data.data.account_id)//用户id
|
|
|
|
|
uni.setStorageSync('invite_code',res.data.data.invite_code)//邀请码
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 判断是否授权,没授权,前往登录页面授权
|
|
|
|
|
*/
|
2022-04-07 10:14:28 +00:00
|
|
|
|
authTimer:null,
|
2022-03-28 10:40:02 +00:00
|
|
|
|
judgeAuth(){
|
2022-04-07 10:14:28 +00:00
|
|
|
|
let auth = false;
|
|
|
|
|
clearTimeout(this.authTimer);
|
|
|
|
|
if(!uni.getStorageSync('token')) {
|
|
|
|
|
this.showToast('请登录');
|
|
|
|
|
this.authTimer = setTimeout(()=>{
|
|
|
|
|
uni.navigateTo({url:'/pages/login/login'});
|
|
|
|
|
},2000)
|
|
|
|
|
} else {
|
|
|
|
|
auth = true;
|
2022-03-28 10:40:02 +00:00
|
|
|
|
}
|
|
|
|
|
return auth;
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 判断当前环境、清空日志、设置全局域名
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
currentContext(){
|
|
|
|
|
// #ifdef APP-PLUS
|
|
|
|
|
if(uni.getSystemInfoSync().platform != "devtools"){//devtools:开发版 值域为:ios、android、mac(3.1.10+)、windows(3.1.10+)、linux(3.1.10+)
|
|
|
|
|
// console.log = () =>{}
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
// 微信小程序原生API性能优化
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
let hInfo = wx.getAccountInfoSync();
|
|
|
|
|
// console.log(hInfo.envVersion);//develop:开发版 trial:体验版 release:正式版
|
|
|
|
|
// if(hInfo.miniProgram.envVersion == "develop"){
|
|
|
|
|
if(hInfo.miniProgram.envVersion == "develop" || hInfo.miniProgram.envVersion == "trial"){
|
2022-04-07 10:14:28 +00:00
|
|
|
|
|
2022-03-28 10:40:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
// 清除所有输出日志
|
|
|
|
|
console.log = () =>{};
|
|
|
|
|
// 开启埋点倒计时
|
|
|
|
|
this.daoTime();//开启埋点倒计时
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 禁止小程序使用分享
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
disableShareEv(){
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
wx.hideShareMenu({
|
|
|
|
|
menus: ['shareAppMessage', 'shareTimeline']
|
|
|
|
|
})
|
|
|
|
|
// #endif
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 获取当前页面url
|
|
|
|
|
*/
|
2022-04-14 10:30:07 +00:00
|
|
|
|
obtainPagePath(){
|
2022-03-28 10:40:02 +00:00
|
|
|
|
let pages = getCurrentPages();
|
2022-04-14 10:30:07 +00:00
|
|
|
|
// 获取纯页面路径
|
2022-03-28 10:40:02 +00:00
|
|
|
|
let route = pages[pages.length - 1].route;
|
2022-04-14 10:30:07 +00:00
|
|
|
|
uni.setStorageSync('url',route);
|
|
|
|
|
// 获取当前页面url,带参数
|
2022-03-28 10:40:02 +00:00
|
|
|
|
let routeParam = pages[pages.length - 1].$page.fullPath;
|
2022-04-14 10:30:07 +00:00
|
|
|
|
console.log(routeParam.options,'获取当前url参数');
|
|
|
|
|
uni.setStorageSync('page-path-options',routeParam);
|
|
|
|
|
console.log(uni.getStorageSync('page-path-options'),'当前页面完整路径');
|
2022-03-28 10:40:02 +00:00
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 拨打电话
|
|
|
|
|
*/
|
2022-03-28 10:40:02 +00:00
|
|
|
|
countCustomer(phone){
|
|
|
|
|
const res = uni.getSystemInfoSync();
|
|
|
|
|
if(res.platform=='ios'){
|
|
|
|
|
uni.makePhoneCall({
|
2022-04-07 10:14:28 +00:00
|
|
|
|
phoneNumber:phone*1,
|
2022-03-28 10:40:02 +00:00
|
|
|
|
success: () => {},
|
|
|
|
|
fail: () => {}
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
uni.showActionSheet({
|
|
|
|
|
itemList:[phone,'立即呼叫'],
|
|
|
|
|
itemColor:'#3875F6',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
if(res.tapIndex==1){
|
|
|
|
|
uni.makePhoneCall({
|
|
|
|
|
phoneNumber:phone
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @description 图片上传
|
|
|
|
|
*/
|
2022-04-10 13:59:38 +00:00
|
|
|
|
uploadImg(count) {
|
|
|
|
|
let imgArr = [];
|
|
|
|
|
uni.chooseImage({
|
|
|
|
|
count:count,
|
|
|
|
|
sizeType:['compressed'],
|
|
|
|
|
sourceType:['album','camera'],
|
|
|
|
|
success: (res) => {
|
|
|
|
|
let files = res.tempFilePaths
|
|
|
|
|
console.log(files);
|
|
|
|
|
files.forEach(item=>{
|
|
|
|
|
imgArr.push(item);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return imgArr;
|
2022-04-15 10:46:03 +00:00
|
|
|
|
},
|
2022-04-17 11:57:56 +00:00
|
|
|
|
|
2022-03-28 10:40:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
tools
|
|
|
|
|
}
|