77 <img src =" ../../assets/img/mobile-logo.png" alt =" " >
88 </div >
99 <div style =" margin-bottom :50px " >
10+ <div v-if =" showSidebarSearch" style =" margin-top : 15px " >
11+ <div class =" search-display" v-if =" !showSearchList" @click =" toSearch" >
12+ <i class =" el-icon-search" ></i >
13+ </div >
14+ <el-select
15+ v-if =" showSearchList"
16+ size =" medium"
17+ filterable
18+ clearable
19+ :filter-method =" search"
20+ v-model =" sidebar"
21+ @change =" handleChange"
22+ class =" search"
23+ placeholder =" 请输入关键字"
24+ ref =" searchInput" >
25+ <el-option
26+ v-for =" item in groups"
27+ :key =" item.key"
28+ :label =" item.title"
29+ :value =" item.path" >
30+ </el-option >
31+ </el-select >
32+ </div >
1033 <el-menu
1134 class =" el-menu-vertical-demo"
1235 ref =" meun"
3053
3154 <!-- 二级菜单 -->
3255 <template v-for =" (subItem ) in item .children " >
33- <el-submenu v-if =" subItem.children" :key =" idMap[subItem.name]" :index =" idMap[subItem.name]" class =" subMenuContent" >
56+ <el-submenu
57+ v-if =" subItem.children"
58+ :key =" idMap[subItem.name]"
59+ :index =" idMap[subItem.name]"
60+ class =" subMenuContent" >
3461 <template slot="title">
3562 <i class =" iconfont icon-erjizhibiao" ></i >
3663 <span slot =" title" class =" two-folder" >{{subItem.title}}</span >
82109<script >
83110import { mapGetters } from ' vuex'
84111import Utils from ' @/lin/utils/util'
112+ import Config from ' ../../config/index'
85113
86114export default {
87115 props: [' isCollapse' ],
116+ data () {
117+ return {
118+ sidebar: ' ' ,
119+ groups: [],
120+ showSidebarSearch: Config .showSidebarSearch ,
121+ showSearchList: false ,
122+ }
123+ },
124+ inject: [' eventBus' ],
125+ mounted () {
126+ this .eventBus .$on (' removeSidebarSearch' , () => {
127+ this .showSidebarSearch = false
128+ })
129+ this .eventBus .$on (' showSidebarSearch' , () => {
130+ if (Config .showSidebarSearch ) {
131+ this .showSidebarSearch = true
132+ }
133+ })
134+ },
88135 methods: {
89136 goto (path ) {
90137 this .$router .push ({
@@ -94,6 +141,51 @@ export default {
94141 filterIcon (icon ) {
95142 return icon .indexOf (' /' ) !== - 1
96143 },
144+ handleChange (val ) {
145+ this .groups = []
146+ this .sidebar = ' '
147+ this .showSearchList = false
148+ this .$router .push (val)
149+ },
150+ toSearch () {
151+ this .showSearchList = true
152+ setTimeout (() => {
153+ this .$refs .searchInput .focus ()
154+ }, 200 )
155+ },
156+ search (val ) {
157+ if (! val) {
158+ this .showSearchList = false
159+ return
160+ }
161+ this .groups = []
162+
163+ // 深度遍历配置树, 摘取叶子节点作为路由部分
164+ function deepTravel (config , fuc ) {
165+ if (Array .isArray (config)) {
166+ config .forEach ((subConfig ) => {
167+ deepTravel (subConfig, fuc)
168+ })
169+ } else if (config .children ) {
170+ config .children .forEach ((subConfig ) => {
171+ deepTravel (subConfig, fuc)
172+ })
173+ } else {
174+ fuc (config)
175+ }
176+ }
177+
178+ deepTravel (this .sideBarList , (viewConfig ) => {
179+ // 构造舞台view路由
180+ if (viewConfig .title .includes (val)) {
181+ const viewRouter = {}
182+ viewRouter .path = viewConfig .path
183+ viewRouter .title = viewConfig .title
184+ viewRouter .key = Math .random ()
185+ this .groups .push (viewRouter)
186+ }
187+ })
188+ },
97189 },
98190 computed: {
99191 // 根据当前路由设置激活侧边栏
@@ -147,17 +239,21 @@ export default {
147239 width : 0px ;
148240 height : 0px ;
149241}
242+
150243.app-sidebar {
151244 background : #192a5e ;
152- & ::-webkit-scrollbar {
245+
246+ & ::-webkit-scrollbar {
153247 width : 0px ;
154248 height : 0px ;
155249 }
250+
156251 .subMenuContent {
157252 overflow : hidden ;
158253 text-overflow : ellipsis ;
159254 white-space : nowrap ;
160255 }
256+
161257 .logo {
162258 width : $sidebar-width ;
163259 height : $header-height ;
@@ -169,9 +265,9 @@ export default {
169265 transition : all 0.5s ease-in-out ;
170266 background-color : #122150 ;
171267 transition : all 0.3s linear ;
172- position :sticky ;
173- top :0 ;
174- left :0 ;
268+ position : sticky ;
269+ top : 0 ;
270+ left : 0 ;
175271 z-index : 99 ;
176272
177273 img {
@@ -211,5 +307,26 @@ export default {
211307 color : $submenu-title ;
212308 height : $menuItem-height ;
213309 }
310+
311+ .search-display {
312+ position : relative ;
313+ width : 80% ;
314+ margin : 0 auto ;
315+ height : 36px ;
316+ border-bottom : 1px $theme solid ;
317+ cursor : pointer ;
318+
319+ .el-icon-search {
320+ position : absolute ;
321+ left : 1px ;
322+ top : 10px ;
323+ color : $theme ;
324+ }
325+ }
326+
327+ .search {
328+ // margin-top: 20px;
329+ width : 80% ;
330+ }
214331}
215332 </style >
0 commit comments