Merge pull request #5707 from dataease/pr@dev@perf_filter_vague_search

perf(过滤器): 下拉过滤器模糊搜索选项忽略大小写
This commit is contained in:
fit2cloud-chenyw 2023-07-20 10:21:43 +08:00 committed by GitHub
commit 78cc58929b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 8 deletions

View File

@ -410,7 +410,7 @@ export default {
}, },
_filterFun(value, data, node) { _filterFun(value, data, node) {
if (!value) return true if (!value) return true
return data[this.propsLabel].indexOf(value) !== -1 return data[this.propsLabel?.toLocaleUpperCase()].indexOf(value.toLocaleUpperCase()) !== -1
}, },
_treeNodeClickFun(data, node, vm) { _treeNodeClickFun(data, node, vm) {
const { multiple } = this.selectParams const { multiple } = this.selectParams

View File

@ -121,7 +121,7 @@ export default {
}, },
keyWord(val, old) { keyWord(val, old) {
if (val === old) return if (val === old) return
const results = val ? this.list.filter(item => item.text.includes(val)) : null const results = val ? this.vagueFilter(val, this.list) : null
this.resetList(results) this.resetList(results)
this.reCacularHeight() this.reCacularHeight()
this.$nextTick(() => { this.$nextTick(() => {
@ -136,6 +136,11 @@ export default {
}) })
}, },
methods: { methods: {
vagueFilter(val, nodes) {
if (!val || !val.trim()) return nodes
const results = nodes.filter(item => item.text?.toLocaleUpperCase().includes(val.toLocaleUpperCase()))
return results
},
resetSelectAll() { resetSelectAll() {
this.selectAll = false this.selectAll = false
}, },
@ -148,7 +153,7 @@ export default {
selectAllChange(val) { selectAllChange(val) {
let vals = val ? [...this.list.map(ele => ele.id)] : [] let vals = val ? [...this.list.map(ele => ele.id)] : []
if (this.keyWord.trim() && val) { if (this.keyWord.trim() && val) {
vals = this.list.filter(item => item.text.includes(this.keyWord.trim())).map(ele => ele.id) vals = this.vagueFilter(this.keyWord.trim(), this.list).map(ele => ele.id)
} }
this.visualChange(vals) this.visualChange(vals)
this.selectValue = vals this.selectValue = vals
@ -233,14 +238,14 @@ export default {
isAllSelect() { isAllSelect() {
let vals = this.list.length let vals = this.list.length
if (this.keyWord.trim()) { if (this.keyWord.trim()) {
vals = this.list.filter(item => item.text.includes(this.keyWord.trim())).map(ele => ele.id).filter(ele => this.selectValue.includes(ele)).length vals = this.vagueFilter(this.keyWord.trim(), this.list).map(ele => ele.id).filter(ele => this.selectValue.includes(ele)).length
} }
return vals return vals
}, },
halfSelect() { halfSelect() {
let vals = this.list.length let vals = this.list.length
if (this.keyWord.trim()) { if (this.keyWord.trim()) {
vals = this.list.filter(item => item.text.includes(this.keyWord.trim())).map(ele => ele.id).length vals = this.vagueFilter(this.keyWord.trim(), this.list).map(ele => ele.id).length
} }
return vals return vals
}, },

View File

@ -31,7 +31,7 @@
v-model="value" v-model="value"
@change="handleCheckedChange" @change="handleCheckedChange"
> >
<template v-for="item in data.filter(node => !keyWord || (node.id && node.id.includes(keyWord)))"> <template v-for="item in data.filter(node => !keyWord || (node.id && node.id.toLocaleUpperCase().includes(keyWord.toLocaleUpperCase())))">
<el-checkbox <el-checkbox
:key="item.id" :key="item.id"
:label="item.id" :label="item.id"
@ -51,7 +51,7 @@
@change="changeRadioBox" @change="changeRadioBox"
> >
<el-radio <el-radio
v-for="(item, index) in data.filter(node => !keyWord || (node.id && node.id.includes(keyWord)))" v-for="(item, index) in data.filter(node => !keyWord || (node.id && node.id.toLocaleUpperCase().includes(keyWord.toLocaleUpperCase())))"
:key="index" :key="index"
:label="item.id" :label="item.id"
@click.native.prevent="testChange(item)" @click.native.prevent="testChange(item)"

View File

@ -381,7 +381,7 @@ export default {
_filterFun(value, data, node) { _filterFun(value, data, node) {
if (!value) return true if (!value) return true
return data.id.toString().indexOf(value.toString()) !== -1 return data.id.toString().toLocaleUpperCase().indexOf(value.toString().toLocaleUpperCase()) !== -1
}, },
// //
_nodeClickFun(data, node, vm) { _nodeClickFun(data, node, vm) {