Sidebar.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <div class="sidebar" :style="collapse ? 'width:85px' : ''">
  3. <div class="logo" v-if="!collapse">
  4. <img src="@/assets/img/img_logo2.png" />
  5. <div class="title"><span class="point"></span>运营支撑</div>
  6. </div>
  7. <div class="logo shrink" v-else>
  8. <div class="text">运营支撑</div>
  9. </div>
  10. <div class="menu-wrap no-scrollbar">
  11. <el-menu
  12. class="sidebar-el-menu"
  13. :default-active="onRoutes"
  14. :collapse="collapse"
  15. background-color="#171F32"
  16. text-color="#aaadba"
  17. active-text-color="#2887f2"
  18. unique-opened
  19. collapse-transition
  20. router
  21. :style="collapse ? 'width:84px' : 'width:220px'"
  22. >
  23. <menu-tree :menuList="menuList" :collapse="collapse" :openArray="openArray"></menu-tree>
  24. </el-menu>
  25. </div>
  26. <div class="footer">
  27. <img
  28. :class="[collapse ? 'expandhover' : 'packuphover']"
  29. :src="collapse ? btnCollpaseright : btnCollpaseleft"
  30. @click="collapseChage"
  31. />
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import MenuTree from './MenuTree.vue';
  37. export default {
  38. data() {
  39. return {
  40. btnCollpaseright: require('@assets/img/btn_collpaseright.png'),
  41. btnCollpaseleft: require('@assets/img/btn_collpaseleft.png'),
  42. openList: []
  43. };
  44. },
  45. components: {
  46. MenuTree
  47. },
  48. computed: {
  49. onRoutes() {
  50. return this.$route.path;
  51. },
  52. collapse() {
  53. return this.$store.getters['getCollapse'];
  54. },
  55. menuList() {
  56. let list = this.$store.getters['getMenuList'];
  57. return list;
  58. },
  59. openArray() {
  60. return this.openList;
  61. }
  62. },
  63. methods: {
  64. // 侧边栏折叠
  65. collapseChage() {
  66. this.$store.dispatch('collapse', !this.collapse);
  67. },
  68. thisfindMen(arr, indexPath) {
  69. let status = [];
  70. arr.map((v) => {
  71. if (v.children) {
  72. v.children.map((s) => {
  73. if ('/' + s.linkPath === indexPath) {
  74. status.push(v.linkPath, s.linkPath);
  75. }
  76. });
  77. } else {
  78. if ('/' + v.linkPath === indexPath) {
  79. status.push(v.linkPath);
  80. }
  81. }
  82. });
  83. return status;
  84. }
  85. },
  86. watch: {
  87. $route(newValue, oldValue) {
  88. this.openList = this.thisfindMen(this.$store.getters['getMenuList'], newValue.path);
  89. }
  90. },
  91. created() {
  92. this.openList = this.thisfindMen(this.$store.getters['getMenuList'], this.$route.path);
  93. }
  94. };
  95. </script>
  96. <style lang="scss">
  97. .sidebar {
  98. width: 220px;
  99. display: flex;
  100. flex-direction: column;
  101. background: #171f32;
  102. border-radius: 0px 30px 30px 0px;
  103. z-index: 2;
  104. .logo {
  105. width: 100%;
  106. height: 110px;
  107. color: #ffffff;
  108. padding: 35px 10px 0 20px;
  109. border-bottom: 1px solid #2a335c;
  110. margin-bottom: 25px;
  111. img {
  112. width: 90px;
  113. height: 24px;
  114. display: inline-block;
  115. vertical-align: middle;
  116. margin-right: 6px;
  117. }
  118. .title {
  119. font-size: 16px;
  120. font-weight: 500;
  121. display: inline-block;
  122. vertical-align: middle;
  123. background: rgba(255, 255, 255, 0.1);
  124. border-radius: 4px;
  125. border: 1px solid rgba(255, 255, 255, 0.4);
  126. padding: 0px 7px;
  127. }
  128. .point {
  129. width: 4px;
  130. height: 4px;
  131. display: inline-block;
  132. // margin-right: 5px;
  133. vertical-align: middle;
  134. text-align: center;
  135. }
  136. .text {
  137. width: 40px;
  138. margin-left: -14px;
  139. }
  140. }
  141. .menu-wrap {
  142. overflow: auto;
  143. flex: 1;
  144. scrollbar-width: 0;
  145. }
  146. .menu-footer.dark {
  147. bottom: 0;
  148. left: 0;
  149. width: 220px;
  150. height: 30px;
  151. div {
  152. width: 100%;
  153. height: 100%;
  154. border-radius: 0px 0 30px 0px;
  155. background-color: #171f32;
  156. border: none;
  157. }
  158. &.dark {
  159. background-color: #070f22 !important;
  160. z-index: 1;
  161. }
  162. &.light {
  163. background-color: #f4f7f9 !important;
  164. z-index: 1;
  165. }
  166. }
  167. .footer {
  168. position: absolute;
  169. bottom: 30px;
  170. left: 20px;
  171. z-index: 11;
  172. width: 30px;
  173. height: 30px;
  174. img {
  175. display: block;
  176. width: 24px;
  177. height: 24px;
  178. cursor: pointer;
  179. }
  180. }
  181. }
  182. .el-menu {
  183. border: none;
  184. }
  185. .sidebar-el-menu .el-submenu.is-opened > .el-submenu__title {
  186. //设置一级菜单点开后的状态
  187. color: #fff !important;
  188. background: rgb(44, 53, 74);
  189. border-radius: 0;
  190. }
  191. .sidebar-el-menu > .el-submenu.is-opened > .el-menu--inline > .el-submenu.is-opened > .el-submenu__title {
  192. color: #fff !important;
  193. }
  194. .sidebar-el-menu > div > .el-submenu.is-opened.is-active > .el-submenu__title {
  195. background: #2c354a !important;
  196. border-radius: 32px 0px 0px 32px;
  197. color: rgb(39, 135, 241) !important;
  198. border-right: 2px solid #2787f1;
  199. .el-submenu__icon-arrow::before {
  200. color: rgb(39, 135, 241);
  201. }
  202. }
  203. .el-menu-item.is-active {
  204. color: rgb(39, 135, 241);
  205. }
  206. .el-submenu.is-active > div > span {
  207. color: rgb(39, 135, 241);
  208. }
  209. .sidebar .logo.shrink {
  210. display: flex;
  211. font-size: 16px;
  212. justify-content: center;
  213. // color: $mainTextColor;
  214. border-bottom: 2px solid #2a335c;
  215. margin-bottom: 20px;
  216. align-items: flex-start;
  217. .text {
  218. width: 48px;
  219. height: 48px;
  220. background: rgba(255, 255, 255, 0.1);
  221. border-radius: 4px;
  222. border: 1px solid rgba(255, 255, 255, 0.4);
  223. text-align: center;
  224. }
  225. }
  226. // .sidebar .logo.shrink {
  227. // display: flex;
  228. // justify-content: center;
  229. // color: #2787f1;
  230. // border-bottom: 2px solid #2a335c;
  231. // margin-bottom: 20px;
  232. // align-items: flex-start;
  233. // .text {
  234. // width: 48px;
  235. // height: 48px;
  236. // background: rgba(255, 255, 255, 0.1);
  237. // border-radius: 4px;
  238. // border: 1px solid rgba(255, 255, 255, 0.4);
  239. // text-align: center;
  240. // }
  241. // }
  242. .el-menu--collapse > .is-active {
  243. color: #2787f1;
  244. background: #2c354a;
  245. border-radius: 32px 0px 0px 32px;
  246. }
  247. .el-menu--collapse > .is-active > .el-submenu__title {
  248. background: transparent !important;
  249. }
  250. .el-submenu > .el-submenu__title:hover {
  251. //设置一级菜单的鼠标经过时候的样式
  252. background: rgb(44, 53, 74) !important;
  253. border-radius: 32px 0px 0px 32px !important;
  254. }
  255. .el-menu-item:hover {
  256. border-radius: 32px 0px 0px 32px;
  257. }
  258. </style>