| | |
| | | parseInt(t[2], 10) || null |
| | | )).getTime() / 1000; |
| | | }, |
| | | formatDate(dat, type) { |
| | | if(!dat){ |
| | | minutesBetweenDates(date1, date2) { |
| | | let dateOne = new Date(date1) |
| | | const oneMinute = 60 * 1000; // 1分钟的毫秒数 |
| | | const difference = Math.abs(date2.getTime() - dateOne.getTime()); // 计算两个日期的毫秒差 |
| | | return Math.floor(difference / oneMinute); // 将差异转换为分钟并向下取整 |
| | | }, |
| | | formatDate(dat, type, addNum) { |
| | | if (!dat) { |
| | | return '-' |
| | | } |
| | | let date = new Date(dat) |
| | | if (addNum) { |
| | | date = new Date(date.setDate(date.getDate() + addNum)); |
| | | } |
| | | const year = date.getFullYear(); |
| | | const month = (date.getMonth() + 1).toString().padStart(2, '0'); |
| | | const day = date.getDate().toString().padStart(2, '0'); |
| | | const hours = date.getHours().toString().padStart(2, '0'); |
| | | const minutes = date.getMinutes().toString().padStart(2, '0'); |
| | | if (type) { |
| | | return `${year}/${month}/${day} ${hours}:${minutes}`; |
| | | return `${year}-${month}-${day} ${hours}:${minutes}`; |
| | | } |
| | | return `${year}/${month}/${day}`; |
| | | return `${year}-${month}-${day}`; |
| | | }, |
| | | /** |
| | | * 倒计时 |
| | |
| | | } |
| | | typeof callback == 'function' && callback(theRequest); |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * 路径转base64 |
| | | * @param {Object} string |
| | |
| | | reject(error); |
| | | }; |
| | | // #endif |
| | | |
| | | |
| | | // #ifdef MP |
| | | if (uni.canIUse('getFileSystemManager')) { |
| | | uni.getFileSystemManager().readFile({ |
| | |
| | | }) |
| | | } |
| | | // #endif |
| | | |
| | | |
| | | // #ifdef APP-PLUS |
| | | plus.io.resolveLocalFileSystemURL(getLocalFilePath(path), (entry) => { |
| | | entry.file((file) => { |
| | |
| | | }, reject) |
| | | // #endif |
| | | }) |
| | | } |
| | | |
| | | |
| | | } |
| | | }, |
| | | roundToTwo(num) { |
| | | if (isNaN(num)) { |
| | | return 0 |
| | | } |
| | | return Math.round((num + Number.EPSILON) * 100) / 100; |
| | | }, |
| | | /** |
| | | * @method 函数防抖 |
| | | * @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) |
| | | } |
| | | } |
| | | }, |
| | | /** |
| | | * @method 函数节流 |
| | | * @desc 指连续触发事件,但是在 n 秒内只执行一次函数。即 2n 秒内执行 2 次... 。会稀释函数的执行频率。 |
| | | * @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) |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | checkFileExtensions(str) { |
| | | const extensions = ['pdf', 'doc', 'docx', 'xls', 'xlsx']; |
| | | return extensions.some(extension => str.includes(extension)); |
| | | }, |
| | | previewWechat(urlPdf) { |
| | | uni.showLoading({ |
| | | title: '正在加载中..' |
| | | }) |
| | | uni.downloadFile({ |
| | | url: urlPdf, |
| | | success: function(res) { |
| | | var filePath = res.tempFilePath; |
| | | uni.openDocument({ |
| | | filePath: filePath, |
| | | showMenu: true, |
| | | success: function(res) { |
| | | console.log('打开文档成功'); |
| | | uni.hideLoading() |
| | | }, |
| | | }); |
| | | }, |
| | | complete: function(r) { |
| | | uni.hideLoading() |
| | | } |
| | | }); |
| | | }, |
| | | } |