Sidebar.vue 7.4 KB

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