File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -188,14 +188,24 @@ const useMenuStore = defineStore(
188188 } ) . catch ( ( ) => { } )
189189 }
190190 // 设置主导航
191+ function isPathInMenus ( menus : Menu . recordRaw [ ] , path : string ) {
192+ let flag = false
193+ flag = menus . some ( ( item ) => {
194+ if ( item . children ) {
195+ return isPathInMenus ( item . children , path )
196+ }
197+ return path . indexOf ( `${ item . path } /` ) === 0 || path === item . path
198+ } )
199+ return flag
200+ }
191201 function setActived ( data : number | string ) {
192202 if ( typeof data === 'number' ) {
193203 // 如果是 number 类型,则认为是主导航的索引
194204 actived . value = data
195205 }
196206 else {
197207 // 如果是 string 类型,则认为是路由,需要查找对应的主导航索引
198- const findIndex = allMenus . value . findIndex ( item => item . children . some ( r => data . indexOf ( ` ${ r . path } /` ) === 0 || data === r . path ) )
208+ const findIndex = allMenus . value . findIndex ( item => isPathInMenus ( item . children , data ) )
199209 if ( findIndex >= 0 ) {
200210 actived . value = findIndex
201211 }
You can’t perform that action at this time.
0 commit comments