Sidebar.vue 11 KB

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