模糊搜索

Former-commit-id: 5018b93c371f8db744b56e818bb99e6c05e3260d [formerly 5018b93c371f8db744b56e818bb99e6c05e3260d [formerly 5018b93c371f8db744b56e818bb99e6c05e3260d [formerly 5018b93c371f8db744b56e818bb99e6c05e3260d [formerly 56cc5dae4d4158a81fec23ab1e2f18b07fd15709 [formerly bbea23ad730ba3e11667cee9ad6eed09a3049db1]]]]]
Former-commit-id: 7e61a3e9f340910d4a333e1487a6c33171b958cb
Former-commit-id: 4139f65e79da4ab9e1c3404285cd56978da1f1d0
Former-commit-id: 4b00899d4ca353ee2d13b9e57c8274026ab2bfa6 [formerly 99bb77688468de73e5cd8cee07128385ff8f75b0]
Former-commit-id: 2da313bd6ecc62aad64fcfbb69d9295ac5c6acb7
Former-commit-id: 0624a606f90e6c939dbe1ced498cb3a0eb97e806
Former-commit-id: 4650a9c9422f9c3657ceefbc0365f64ccb16de5e
Former-commit-id: e80e99e2eaa99cee2ce13e0bb46972cbcc2f593e
Former-commit-id: 7cef5e26a7dff21925ecdca043849701a679af57
This commit is contained in:
liyang
2018-08-30 11:17:34 +08:00
parent ef47ff3104
commit 6f740765d4
3 changed files with 21 additions and 9 deletions

View File

@@ -24,6 +24,7 @@
"element-ui": "^2.4.4",
"file-saver": "^1.3.3",
"flex.css": "^1.1.7",
"fuse.js": "^3.2.1",
"github-markdown-css": "^2.10.0",
"highlight.js": "^9.12.0",
"hotkeys-js": "^3.3.6",

View File

@@ -48,6 +48,7 @@
</template>
<script>
import Fuse from 'fuse.js'
import { mapState } from 'vuex'
import mixin from '../mixin/menu'
export default {
@@ -92,14 +93,24 @@ export default {
* @param {String} queryString 查询字符串
*/
query (pool, queryString) {
return pool.filter(item => {
const path = item.path || ''
const fullTitle = item.fullTitle || ''
return (`${fullTitle}${path}`.toLowerCase().indexOf(queryString.toLowerCase()) >= 0)
}).map(e => ({
value: e.fullTitle,
...e
}))
return new Fuse(pool, {
shouldSort: true,
tokenize: true,
threshold: 0.6,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: [
'fullTitle',
'path'
]
})
.search(queryString)
.map(e => ({
value: e.fullTitle,
...e
}))
},
/**
* @description 聚焦输入框

View File

@@ -4,7 +4,7 @@ export default {
namespaced: true,
state: {
// 搜索面板激活状态
active: true,
active: false,
// 快捷键
hotkey: {
open: setting.hotkey.search.open,