Sidebar.vue 8.3 KB

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