22 <div class =" app-sidebar" >
33 <logo :elMenuCollapse =" elMenuCollapse" />
44 <div style =" margin-bottom :50px " >
5- <div v-if =" showSidebarSearch" style =" margin-top : 15px " >
6- <div class =" search-display" v-if =" !showSearchList" @click =" toSearch" ><i class =" el-icon-search" ></i ></div >
7- <el-select
8- v-if =" showSearchList"
9- size =" medium"
10- filterable
11- clearable
12- :filter-method =" search"
13- v-model =" sidebar"
14- @change =" handleChange"
15- class =" search"
16- placeholder =" 请输入关键字"
17- ref =" searchInput"
18- >
19- <el-option v-for =" item in groups" :key =" item.key" :label =" item.title" :value =" item.path" > </el-option >
20- </el-select >
21- </div >
5+ <search ></search >
226 <el-menu
237 ref =" meun"
248 class =" el-menu-vertical-demo"
3620
3721<script >
3822import { mapGetters } from ' vuex'
39- import emitter from ' lin/util/emitter'
40- import Config from ' @/config/index'
41- import MenuTree from ' ./menu-tree'
23+
4224import Logo from ' ./logo'
25+ import Search from ' ./search'
26+ import MenuTree from ' ./menu-tree'
4327
4428export default {
45- components: { MenuTree, Logo },
46- data () {
47- return {
48- sidebar: ' ' ,
49- groups: [],
50- showSearchList: false ,
51- showSidebarSearch: Config .showSidebarSearch ,
52- }
53- },
29+ components: { MenuTree, Logo, Search },
5430 props: {
5531 isPhone: {
5632 type: Boolean ,
@@ -61,69 +37,11 @@ export default {
6137 default: false ,
6238 },
6339 },
64- mounted () {
65- emitter .on (' removeSidebarSearch' , () => {
66- this .showSidebarSearch = false
67- })
68- emitter .on (' showSidebarSearch' , () => {
69- if (Config .showSidebarSearch ) {
70- this .showSidebarSearch = true
71- }
72- })
73- },
74- methods: {
75- handleChange (val ) {
76- this .groups = []
77- this .sidebar = ' '
78- this .showSearchList = false
79- this .$router .push (val)
80- },
81- toSearch () {
82- this .showSearchList = true
83- setTimeout (() => {
84- this .$refs .searchInput .focus ()
85- }, 200 )
86- },
87- search (val ) {
88- // if (!val) {
89- // this.showSearchList = false
90- // return
91- // }
92- this .groups = []
93-
94- // 深度遍历配置树, 摘取叶子节点作为路由部分
95- function deepTravel (config , fuc ) {
96- if (Array .isArray (config)) {
97- config .forEach (subConfig => {
98- deepTravel (subConfig, fuc)
99- })
100- } else if (config .children ) {
101- config .children .forEach (subConfig => {
102- deepTravel (subConfig, fuc)
103- })
104- } else {
105- fuc (config)
106- }
107- }
108-
109- deepTravel (this .sidebarList , viewConfig => {
110- // 构造舞台view路由
111- if (viewConfig .title .includes (val)) {
112- const viewRouter = {}
113- viewRouter .path = viewConfig .path
114- viewRouter .title = viewConfig .title
115- viewRouter .key = Math .random ()
116- this .groups .push (viewRouter)
117- }
118- })
119- },
120- },
12140 computed: {
12241 elMenuCollapse () {
12342 if (this .isPhone ) {
12443 return false
12544 }
126-
12745 return this .isCollapse
12846 },
12947 /**
@@ -151,26 +69,5 @@ export default {
15169 width : 0px ;
15270 height : 0px ;
15371 }
154-
155- .search-display {
156- position : relative ;
157- width : 80% ;
158- margin : 0 auto ;
159- height : 36px ;
160- border-bottom : 1px rgb (185 , 190 , 195 ) solid ;
161- cursor : pointer ;
162-
163- .el-icon-search {
164- position : absolute ;
165- left : 1px ;
166- top : 10px ;
167- color : rgb (185 , 190 , 195 );
168- }
169- }
170-
171- .search {
172- // margin-top: 20px;
173- width : 80% ;
174- }
17572}
17673 </style >
0 commit comments