@@ -41,6 +41,9 @@ export default {
41
41
},
42
42
lang () {
43
43
return this .$store .getters .language
44
+ },
45
+ supportPinyinSearch () {
46
+ return this .$store .state .settings .supportPinyinSearch
44
47
}
45
48
},
46
49
watch: {
@@ -51,6 +54,10 @@ export default {
51
54
this .searchPool = this .generateRoutes (this .routes )
52
55
},
53
56
searchPool (list ) {
57
+ // Support pinyin search
58
+ if (this .lang === ' zh' && this .supportPinyinSearch ) {
59
+ this .addPinyinField (list)
60
+ }
54
61
this .initFuse (list)
55
62
},
56
63
show (value ) {
@@ -65,6 +72,23 @@ export default {
65
72
this .searchPool = this .generateRoutes (this .routes )
66
73
},
67
74
methods: {
75
+ async addPinyinField (list ) {
76
+ const { default: pinyin } = await import (' pinyin' )
77
+ if (Array .isArray (list)) {
78
+ list .forEach (element => {
79
+ const title = element .title
80
+ if (Array .isArray (title)) {
81
+ title .forEach (v => {
82
+ v = pinyin (v, {
83
+ style: pinyin .STYLE_NORMAL
84
+ }).join (' ' )
85
+ element .pinyinTitle = v
86
+ })
87
+ }
88
+ })
89
+ return list
90
+ }
91
+ },
68
92
click () {
69
93
this .show = ! this .show
70
94
if (this .show ) {
@@ -95,6 +119,9 @@ export default {
95
119
keys: [{
96
120
name: ' title' ,
97
121
weight: 0.7
122
+ }, {
123
+ name: ' pinyinTitle' ,
124
+ weight: 0.3
98
125
}, {
99
126
name: ' path' ,
100
127
weight: 0.3
@@ -105,29 +132,23 @@ export default {
105
132
// And generate the internationalized title
106
133
generateRoutes (routes , basePath = ' /' , prefixTitle = []) {
107
134
let res = []
108
-
109
135
for (const router of routes) {
110
136
// skip hidden router
111
137
if (router .hidden ) { continue }
112
-
113
138
const data = {
114
139
path: path .resolve (basePath, router .path ),
115
140
title: [... prefixTitle]
116
141
}
117
-
118
142
if (router .meta && router .meta .title ) {
119
143
// generate internationalized title
120
144
const i18ntitle = i18n .t (` route.${ router .meta .title } ` )
121
-
122
145
data .title = [... data .title , i18ntitle]
123
-
124
146
if (router .redirect !== ' noRedirect' ) {
125
147
// only push the routes with title
126
148
// special case: need to exclude parent router without redirect
127
149
res .push (data)
128
150
}
129
151
}
130
-
131
152
// recursive child routes
132
153
if (router .children ) {
133
154
const tempRoutes = this .generateRoutes (router .children , data .path , data .title )
@@ -152,13 +173,11 @@ export default {
152
173
<style lang="scss" scoped>
153
174
.header-search {
154
175
font-size : 0 !important ;
155
-
156
176
.search-icon {
157
177
cursor : pointer ;
158
178
font-size : 18px ;
159
179
vertical-align : middle ;
160
180
}
161
-
162
181
.header-search-select {
163
182
font-size : 18px ;
164
183
transition : width 0.2s ;
@@ -168,7 +187,6 @@ export default {
168
187
border-radius : 0 ;
169
188
display : inline-block ;
170
189
vertical-align : middle ;
171
-
172
190
/deep / .el-input__inner {
173
191
border-radius : 0 ;
174
192
border : 0 ;
@@ -179,7 +197,6 @@ export default {
179
197
vertical-align : middle ;
180
198
}
181
199
}
182
-
183
200
& .show {
184
201
.header-search-select {
185
202
width : 210px ;
0 commit comments