From 6168e1c43ed2d9c6cf6f1488d150273536e2737f Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Thu, 25 Apr 2024 18:10:55 +0800 Subject: [PATCH] uu --- common/util.js | 42 ++++++++++++++++++- .../tpx-scroll-view/tpx-scroll-view.vue | 8 +++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/common/util.js b/common/util.js index 3a784ce..4fa341b 100644 --- a/common/util.js +++ b/common/util.js @@ -95,10 +95,12 @@ const numberToChinese = (num)=> { return result; } +// - 获取地址详情 const getAddressDetail = (item= {})=> { return `${item.countryName||''}${item.provinceName||''}${item.cityName||''}${item.countyName||''}${item.address||''}` } +// - 转换list的key val const transListKeyTitle = ({ valKey = '', titleKey = '', list = [] })=> { list.map(t=> { t.title = t[titleKey] @@ -107,11 +109,49 @@ const transListKeyTitle = ({ valKey = '', titleKey = '', list = [] })=> { return list } +// -防抖 +const debounce = (fn, wait) => { + let delay = wait || 500 + let timer + return function() { + let args = arguments; + if (timer) { + clearTimeout(timer) + console.log('拦截') + } + let callNow = !timer + timer = setTimeout(() => { + console.log('发送') + timer = null + }, delay) + if (callNow) fn.apply(this, args) + } +} + +// -节流 +const throttle = (fn, wait) => { + let delay = wait || 500 + let timer = null + return function() { + if (timer) { + console.log('拦截'); + return + } + timer = setTimeout(() => { + console.log('发送'); + fn.apply(this, arguments) + timer = null + }, delay) + } +} + export { getAddressDetail, numberToChinese, formatTime, formatLocation, dateUtils, - transListKeyTitle + transListKeyTitle, + debounce, + throttle, } diff --git a/components/tpx-scroll-view/tpx-scroll-view.vue b/components/tpx-scroll-view/tpx-scroll-view.vue index 9cdfd9a..3e10f62 100644 --- a/components/tpx-scroll-view/tpx-scroll-view.vue +++ b/components/tpx-scroll-view/tpx-scroll-view.vue @@ -15,11 +15,15 @@