Sidebar.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div class="has-logo">
  3. <logo />
  4. <div class="sidebar-box">
  5. <div v-for="item in sidebarRouters" :key="item.path" class="sidebar-box-item" :class="{ active: item.path == active }" @click="toMainMenu(item)">
  6. <item :icon="item.icon" :title="item.menuName" />
  7. </div>
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import { mapGetters, mapState } from 'vuex'
  13. import Logo from './Sidebar/Logo'
  14. import Item from './Sidebar/Item'
  15. export default {
  16. components: { Logo, Item },
  17. data() {
  18. return {
  19. active: sessionStorage.getItem('sidebarActive') || 'index'
  20. }
  21. },
  22. computed: {
  23. ...mapState(['settings']),
  24. ...mapGetters(['sidebarRouters', 'sidebar']),
  25. isCollapse() {
  26. return !this.sidebar.opened
  27. }
  28. },
  29. methods: {
  30. toMainMenu(item) {
  31. if (this.$route.query.id == item.menuId) {
  32. return
  33. }
  34. this.active = item.path
  35. sessionStorage.setItem('sidebarActive', item.path)
  36. this.$router.replace({
  37. path: '/mainMenu',
  38. query: {
  39. id: item.menuId
  40. }
  41. })
  42. }
  43. }
  44. }
  45. </script>
  46. <style scoped lang="scss">
  47. .sidebar-box {
  48. width: 100%;
  49. .sidebar-box-item {
  50. width: 100%;
  51. height: 49px;
  52. font-size: 16px;
  53. color: #fff;
  54. text-align: center;
  55. line-height: 49px;
  56. cursor: pointer;
  57. user-select: none;
  58. border-bottom: 1px dashed #535559;
  59. &:hover {
  60. background-color: #535559;
  61. }
  62. &.active {
  63. background-color: #4c9898;
  64. }
  65. }
  66. }
  67. </style>