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: {
options: {
handler(val) {
if (val && val.length > 0) {
const routeFilter = this.checkInTableColumns()
handler(newVal, oldVal) {
if (newVal && newVal.length > 0) {
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)
}
},
@ -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: {
// url
checkInTableColumns() {
checkInTableColumns(options) {
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 routeQueryKeysLength = Object.keys(routeQuery).length
if (routeQueryKeysLength < 1) return searchFieldOptions
@ -211,10 +210,10 @@ export default {
...asFilterTags,
...routeFilter
}
if (Object.keys(routeFilter).length > 0) {
if (Object.keys(this.filterTags).length > 0) {
setTimeout(() => {
return this.$emit('tagSearch', this.filterMaps)
}, 490)
}, 400)
}
},
getValueLabel(key, value) {