支持国际化中文 菜单拼音模糊搜索
This commit is contained in:
parent
a9e21c2ce2
commit
10ff36d9a1
|
@ -58,6 +58,7 @@
|
||||||
"normalize.css": "7.0.0",
|
"normalize.css": "7.0.0",
|
||||||
"nprogress": "0.2.0",
|
"nprogress": "0.2.0",
|
||||||
"path-to-regexp": "2.4.0",
|
"path-to-regexp": "2.4.0",
|
||||||
|
"pinyin": "^2.9.0",
|
||||||
"screenfull": "4.2.0",
|
"screenfull": "4.2.0",
|
||||||
"showdown": "1.9.0",
|
"showdown": "1.9.0",
|
||||||
"sortablejs": "1.8.4",
|
"sortablejs": "1.8.4",
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
import Fuse from 'fuse.js'
|
import Fuse from 'fuse.js'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import i18n from '@/lang'
|
import i18n from '@/lang'
|
||||||
|
import pinyin from 'pinyin'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'HeaderSearch',
|
name: 'HeaderSearch',
|
||||||
|
@ -51,6 +52,10 @@ export default {
|
||||||
this.searchPool = this.generateRoutes(this.routes)
|
this.searchPool = this.generateRoutes(this.routes)
|
||||||
},
|
},
|
||||||
searchPool(list) {
|
searchPool(list) {
|
||||||
|
// Support pinyin search
|
||||||
|
if (this.lang === 'zh') {
|
||||||
|
this.pinyin(list)
|
||||||
|
}
|
||||||
this.initFuse(list)
|
this.initFuse(list)
|
||||||
},
|
},
|
||||||
show(value) {
|
show(value) {
|
||||||
|
@ -65,6 +70,22 @@ export default {
|
||||||
this.searchPool = this.generateRoutes(this.routes)
|
this.searchPool = this.generateRoutes(this.routes)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
pinyin(list) {
|
||||||
|
if (Array.isArray(list)) {
|
||||||
|
list.forEach(element => {
|
||||||
|
const title = element.title
|
||||||
|
if (Array.isArray(title)) {
|
||||||
|
title.forEach(v => {
|
||||||
|
v = pinyin(v, {
|
||||||
|
style: pinyin.STYLE_NORMAL
|
||||||
|
}).join('')
|
||||||
|
element.pinyinTitle = v
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
},
|
||||||
click() {
|
click() {
|
||||||
this.show = !this.show
|
this.show = !this.show
|
||||||
if (this.show) {
|
if (this.show) {
|
||||||
|
@ -95,6 +116,9 @@ export default {
|
||||||
keys: [{
|
keys: [{
|
||||||
name: 'title',
|
name: 'title',
|
||||||
weight: 0.7
|
weight: 0.7
|
||||||
|
}, {
|
||||||
|
name: 'pinyinTitle',
|
||||||
|
weight: 0.3
|
||||||
}, {
|
}, {
|
||||||
name: 'path',
|
name: 'path',
|
||||||
weight: 0.3
|
weight: 0.3
|
||||||
|
|
Loading…
Reference in New Issue