优化搜索状态处理及数据请求节流

This commit is contained in:
aixianling
2024-11-29 18:03:26 +08:00
parent 1845f6cc9a
commit 9c6248e5df

View File

@@ -1,4 +1,14 @@
<script>
function throttle(func, limit = 500) {
let timer;
return function () {
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(func, limit);
}
}
export default {
name: "AppStoresTable",
label: "多店监控",
@@ -44,7 +54,12 @@ export default {
}
},
computed: {
search: v => v.$multipleStoreBoard.search,
search: v => {
const search = JSON.parse(JSON.stringify(v.$multipleStoreBoard.search))
delete search.t
return search
},
refreshTimer: v => v.search.t,
storeList: v => {
const list = []
let group = []
@@ -65,17 +80,22 @@ export default {
},
watch: {
search: {
immediate: true, deep: true, handler(v, old) {
if (old) {
delete v.t
old?.t && delete old.t
}
(old && JSON.stringify(v) == JSON.stringify(old) ? this.refreshData() : this.getData()).then(() => {
immediate: true, deep: true, handler(v) {
this.getData().then(() => {
if (v.interval > 0 && v.changeWay == '1') {
this.$refs.carousel?.$forceUpdate()
}
})
}
},
refreshTimer() {
console.log("刷新")
this.refreshData().then(() => {
const v = this.search
if (v.interval > 0 && v.changeWay == '1') {
this.$refs.carousel?.$forceUpdate()
}
})
}
},
methods: {
@@ -112,21 +132,27 @@ export default {
})
},
getStoreKeyGoods() {
return $http.post("/data-boot/la/screen/multipleStoreBoard/storeKeyGoods", {
type: "1", ...this.search,
}).then(res => {
if (res?.data) {
this.storeKeyGoods = res.data
}
return new Promise(resolve => {
throttle(() => $http.post("/data-boot/la/screen/multipleStoreBoard/storeKeyGoods", {
type: "1", ...this.search,
}).then(res => {
if (res?.data) {
this.storeKeyGoods = res.data
resolve()
}
}))()
})
},
getCategorySales() {
return $http.post("/data-boot/la/screen/multipleStoreBoard/categorySale", {
type: "1", ...this.search,
}).then(res => {
if (res?.data) {
this.categorySales = res.data
}
return new Promise(resolve => {
throttle(() => $http.post("/data-boot/la/screen/multipleStoreBoard/categorySale", {
type: "1", ...this.search,
}).then(res => {
if (res?.data) {
this.categorySales = res.data
resolve()
}
}))()
})
},
gotoDetail(store, i) {