tapd相关修改更新
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* @desc 函数防抖
|
||||
* @param func 目标函数
|
||||
* @param wait 延迟执行毫秒数
|
||||
* @param immediate true - 立即执行, false - 延迟执行
|
||||
*/
|
||||
export const debounce = function(func, wait = 1000, immediate = true) {
|
||||
let timer;
|
||||
return function() {
|
||||
let context = this,
|
||||
args = arguments;
|
||||
if (timer) clearTimeout(timer);
|
||||
if (immediate) {
|
||||
let callNow = !timer;
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
}, wait);
|
||||
if (callNow) func.apply(context, args);
|
||||
} else {
|
||||
timer = setTimeout(() => {
|
||||
func.apply(context, args);
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
143
commons/utils/index.js
Normal file
143
commons/utils/index.js
Normal file
@@ -0,0 +1,143 @@
|
||||
|
||||
export const utils = {
|
||||
ColorMain: '#318AFE',
|
||||
ColorRed: '#F02C45',
|
||||
|
||||
/**
|
||||
* 限制只让输入数字
|
||||
* @param {Object} e
|
||||
*/
|
||||
isNumber (e) {
|
||||
console.log(e)
|
||||
return e.replace(/[^\d]/g, '')
|
||||
},
|
||||
|
||||
/**
|
||||
* 限制金额输入格式
|
||||
* @param {Object} e
|
||||
*/
|
||||
isPrice (e) {
|
||||
return e.replace(/[^0-9.]/g, '').replace(/\.{2,}/g, "").replace(/^\./, '')
|
||||
},
|
||||
|
||||
/**
|
||||
* 金额保留两位小数
|
||||
* @param {Object} e
|
||||
*/
|
||||
toFixed (price,item) {
|
||||
if( item ){
|
||||
if( item.productType == 'weight' || item.type == 'weight'){
|
||||
return (Math.floor(price * 100)/100).toFixed(2)
|
||||
} else {
|
||||
return parseFloat(price).toFixed(2)
|
||||
}
|
||||
} else {
|
||||
return parseFloat(price).toFixed(2)
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 金额向下取整
|
||||
* @param {Object} e
|
||||
*/
|
||||
formatPrice (e) {
|
||||
return (Math.floor(n*100)/100).toFixed(2)
|
||||
},
|
||||
|
||||
/**
|
||||
* 消息提示框
|
||||
*/
|
||||
showToast(title, duration = 1.5, extObject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.showToast(Object.assign({ title: title, icon: 'none', mask: false, duration: (duration * 1000) }, extObject))
|
||||
setTimeout(resolve, (duration * 1000));
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 保留小数n位,不进行四舍五入
|
||||
* num你传递过来的数字,
|
||||
* decimal你保留的几位,默认保留小数后两位
|
||||
*/
|
||||
formatDecimal (num, decimal = 2) {
|
||||
num = num.toString()
|
||||
const index = num.indexOf('.')
|
||||
if (index !== -1) {
|
||||
num = num.substring(0, decimal + index + 1)
|
||||
} else {
|
||||
num = num.substring(0)
|
||||
}
|
||||
//截取后保留两位小数
|
||||
return parseFloat(num).toFixed(decimal)
|
||||
},
|
||||
|
||||
/**
|
||||
* 分转元
|
||||
* amount - 金额
|
||||
* parseFloat - 是否转换为数字格式,
|
||||
* 默认String
|
||||
*/
|
||||
cert2Dollar(amount, needParseFloat = false) {
|
||||
if (needParseFloat) { // parseFlot
|
||||
return formatDecimal(amount / 100)
|
||||
}
|
||||
return formatDecimal(amount / 100)
|
||||
},
|
||||
|
||||
/**
|
||||
* @desc 函数防抖
|
||||
* @param func 目标函数
|
||||
* @param wait 延迟执行毫秒数
|
||||
* @param immediate true - 立即执行, false - 延迟执行
|
||||
*/
|
||||
debounce (func, wait = 1000, immediate = true) {
|
||||
let timer;
|
||||
return function() {
|
||||
let context = this,
|
||||
args = arguments;
|
||||
if (timer) clearTimeout(timer);
|
||||
if (immediate) {
|
||||
let callNow = !timer;
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
}, wait);
|
||||
if (callNow) func.apply(context, args);
|
||||
} else {
|
||||
timer = setTimeout(() => {
|
||||
func.apply(context, args);
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @desc 函数节流
|
||||
* @param func 函数
|
||||
* @param wait 延迟执行毫秒数
|
||||
* @param type 1 使用表时间戳,在时间段开始的时候触发 2 使用表定时器,在时间段结束的时候触发
|
||||
*/
|
||||
throttle (func, wait = 1000, type = 1) {
|
||||
let previous = 0;
|
||||
let timeout;
|
||||
return function() {
|
||||
let context = this;
|
||||
let args = arguments;
|
||||
if (type === 1) {
|
||||
let now = Date.now();
|
||||
|
||||
if (now - previous > wait) {
|
||||
func.apply(context, args);
|
||||
previous = now;
|
||||
}
|
||||
} else if (type === 2) {
|
||||
if (!timeout) {
|
||||
timeout = setTimeout(() => {
|
||||
timeout = null;
|
||||
func.apply(context, args)
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* @desc 函数节流
|
||||
* @param func 函数
|
||||
* @param wait 延迟执行毫秒数
|
||||
* @param type 1 使用表时间戳,在时间段开始的时候触发 2 使用表定时器,在时间段结束的时候触发
|
||||
*/
|
||||
export const throttle = (func, wait = 1000, type = 1) => {
|
||||
let previous = 0;
|
||||
let timeout;
|
||||
return function() {
|
||||
let context = this;
|
||||
let args = arguments;
|
||||
if (type === 1) {
|
||||
let now = Date.now();
|
||||
|
||||
if (now - previous > wait) {
|
||||
func.apply(context, args);
|
||||
previous = now;
|
||||
}
|
||||
} else if (type === 2) {
|
||||
if (!timeout) {
|
||||
timeout = setTimeout(() => {
|
||||
timeout = null;
|
||||
func.apply(context, args)
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ class WebsocketUtil {
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error('WebSocket连接失败', error);
|
||||
uni.$emit('is-socket-open', true)
|
||||
this.reconnect();
|
||||
}
|
||||
});
|
||||
@@ -42,10 +43,12 @@ class WebsocketUtil {
|
||||
// 连接成功后启动心跳和消息监听
|
||||
this.startHeartbeat();
|
||||
this.listenForMessages();
|
||||
uni.$emit('is-socket-open', true)
|
||||
|
||||
});
|
||||
this.socketTask.onError((res) => {
|
||||
console.log('WebSocket连接失败!==',res);
|
||||
uni.$emit('is-socket-open', false)
|
||||
this.reconnect();
|
||||
});
|
||||
// 注意:这里的 onClose 监听器应该放在 uni.connectSocket 调用之后
|
||||
@@ -93,7 +96,7 @@ class WebsocketUtil {
|
||||
const { data } = res;
|
||||
this.messageCallbacks.forEach(callback => callback(data.toString())); // 假设 data 是字符串或可转换为字符串
|
||||
});
|
||||
this.send("WebSocket连接正常");
|
||||
// this.send("WebSocket连接正常");
|
||||
} else {
|
||||
console.error('WebSocket 连接尚未建立,无法监听消息');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user