|
@@ -52,10 +52,18 @@
|
|
|
type: Array,
|
|
|
default: [],
|
|
|
required: true
|
|
|
+ },
|
|
|
+ mode: {
|
|
|
+ type: String,
|
|
|
+ default: 'fuzzy'
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
|
items(values) {
|
|
|
+ if (this.mode !== 'fuzzy') {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
this.fuse.setCollection(values)
|
|
|
},
|
|
|
search(value) {
|
|
@@ -78,7 +86,33 @@
|
|
|
})
|
|
|
},
|
|
|
performSearch(value) {
|
|
|
- this.results = this.fuse.search(value)
|
|
|
+ if(!value) {
|
|
|
+ this.results = []
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.mode === 'fuzzy') {
|
|
|
+ this.results = this.fuse.search(value)
|
|
|
+ } else {
|
|
|
+ this.results = []
|
|
|
+
|
|
|
+ for (let item of this.items) {
|
|
|
+ for (let field in item) {
|
|
|
+ if (typeof item[field] !== 'string') {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.keys.length !== 0 && this.keys.indexOf(field) === -1) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item[field].toLowerCase().indexOf(value.toLowerCase()) !== -1) {
|
|
|
+ this.results.push(item)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
@@ -89,6 +123,10 @@
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
+ if (this.mode !== 'fuzzy') {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
this.initFuse()
|
|
|
}
|
|
|
}
|