This commit is contained in:
aihe 2024-04-25 18:10:55 +08:00
parent 4783cc3e6c
commit 6168e1c43e
2 changed files with 47 additions and 3 deletions

View File

@ -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,
}

View File

@ -15,11 +15,15 @@
</template>
<script>
import { throttle } from "@/common/util"
export default {
watch: {
searchParam: {
handler(cval, oval) {
this.getDataList(true)
throttle(()=> {
this.getDataList(true)
}, 500)
},
deep: true
}
@ -102,7 +106,7 @@
page: this.page,
showLoadMore: this.showLoadMore,
loadedAll: this.loadedAll,
reqLoading: this.reqLoading
reqLoading: this.reqLoading,
...obj,
})
}