perf: 优化table组件在有查询条件的情况下列表会重复请求接口的问题

This commit is contained in:
“huailei000” 2023-10-18 15:57:59 +08:00 committed by 老广
parent 53d130f1cf
commit a08fbc3b77

View File

@ -107,9 +107,16 @@ export default {
}, },
watch: { watch: {
options: { options: {
handler(val) { handler(newVal, oldVal) {
if (val && val.length > 0) { if (newVal && newVal.length > 0) {
const routeFilter = this.checkInTableColumns() const routeFilter = this.checkInTableColumns(newVal)
if (oldVal.length > 0 && newVal.length !== oldVal.length) {
const beforeRouteFilter = this.checkInTableColumns(oldVal)
// 2
if (_.isEqual(routeFilter, beforeRouteFilter)) {
return
}
}
this.filterTagSearch(routeFilter) this.filterTagSearch(routeFilter)
} }
}, },
@ -121,19 +128,11 @@ export default {
} }
} }
}, },
mounted() {
setTimeout(() => {
if (Object.keys(this.filterMaps).length > 0) {
return this.$emit('tagSearch', this.filterMaps)
}
}, 400)
// this.$nextTick(() => this.$emit('tagSearch', this.filterMaps))
},
methods: { methods: {
// url // url
checkInTableColumns() { checkInTableColumns(options) {
const searchFieldOptions = {} const searchFieldOptions = {}
const queryInfoValues = this.options.map((i) => i.value) const queryInfoValues = options.map((i) => i.value)
const routeQuery = this.getUrlQuery ? this.$route?.query : {} const routeQuery = this.getUrlQuery ? this.$route?.query : {}
const routeQueryKeysLength = Object.keys(routeQuery).length const routeQueryKeysLength = Object.keys(routeQuery).length
if (routeQueryKeysLength < 1) return searchFieldOptions if (routeQueryKeysLength < 1) return searchFieldOptions
@ -211,10 +210,10 @@ export default {
...asFilterTags, ...asFilterTags,
...routeFilter ...routeFilter
} }
if (Object.keys(routeFilter).length > 0) { if (Object.keys(this.filterTags).length > 0) {
setTimeout(() => { setTimeout(() => {
return this.$emit('tagSearch', this.filterMaps) return this.$emit('tagSearch', this.filterMaps)
}, 490) }, 400)
} }
}, },
getValueLabel(key, value) { getValueLabel(key, value) {