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

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