sider.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <el-aside style="width: 254px;">
  3. <div class="sidebar">
  4. <div class="side-logo">
  5. <img @click="$router.push({path:'/'})" src="/static/image/logo.png" class="logo" />
  6. </div>
  7. <el-menu class="sidebar-el-menu" :default-active="$route.path" :collapse="collapse" background-color="#00152A"
  8. text-color="#bfcbd9" active-text-color="#20a0ff" router>
  9. <template v-for="item in items">
  10. <template v-if="item.children">
  11. <el-submenu :index="item.path" :key="item.path">
  12. <template slot="title">
  13. <!-- <i :class="[item.icon,'aliFamily']"></i> -->
  14. <img v-if="item.icon" class="side-bar-icon" :src="item.icon" />
  15. <span slot="title">{{ item.title }}</span>
  16. </template>
  17. <template v-for="subItem in item.children">
  18. <el-submenu v-if="subItem.children" :index="subItem.path" :key="subItem.path">
  19. <template slot="title">{{ subItem.title }}</template>
  20. <el-menu-item v-for="(threeItem,i) in subItem.children" :key="i" :index="threeItem.path">
  21. {{ threeItem.title }}</el-menu-item>
  22. </el-submenu>
  23. <el-menu-item v-else :index="subItem.path" :key="subItem.path">{{ subItem.title }}</el-menu-item>
  24. </template>
  25. </el-submenu>
  26. </template>
  27. <template v-else>
  28. <el-menu-item :index="item.path" :key="item.path">
  29. <!-- <i :class="[item.icon,'aliFamily']"></i> -->
  30. <img :src="item.icon" class="side-bar-icon" v-if="item.icon" />
  31. <span slot="title">{{ item.title }}</span>
  32. </el-menu-item>
  33. </template>
  34. </template>
  35. </el-menu>
  36. </div>
  37. </el-aside>
  38. </template>
  39. <script>
  40. import bus from '../common/bus'
  41. import router from '../router/index.js';
  42. export default {
  43. data() {
  44. return {
  45. collapse: false,
  46. //items: []
  47. items: [
  48. {
  49. path: '/',
  50. name: 'home',
  51. title: '一键发单',
  52. icon: '/static/image/order-icon.png',
  53. children: [
  54. {
  55. path: '/',
  56. name: 'HomeIndex',
  57. title: '订单列表',
  58. },
  59. {
  60. path: '/orderSearch',
  61. name: 'orderSearch',
  62. title: '订单查询',
  63. }
  64. ]
  65. },
  66. {
  67. path: '/shopInfo',
  68. name: 'shopInfo',
  69. title: '商户信息',
  70. icon: '/static/image/shop-icon.png',
  71. children: [
  72. {
  73. path: '/shopInfo/shopInfos',
  74. name: 'shopInfos',
  75. title: '门店管理',
  76. },
  77. {
  78. path: '/shopInfo/shopAccount',
  79. name: 'shopInfos',
  80. title: '我的账户',
  81. }
  82. ]
  83. },
  84. {
  85. path: '/setUp/set',
  86. name: 'setUp',
  87. title: '设置',
  88. icon: '/static/image/setting-icon.png'
  89. }
  90. ]
  91. }
  92. },
  93. created() {
  94. console.log(router.options.routes)
  95. //this.items = [...router.options.routes];
  96. // 通过 Event Bus 进行组件间通信,来折叠侧边栏
  97. bus.$on('collapse', msg => {
  98. this.collapse = msg
  99. bus.$emit('collapse-content', msg)
  100. })
  101. }
  102. }
  103. </script>
  104. <style lang='scss' scoped='scoped'>
  105. /deep/ .el-submenu .el-menu-item {
  106. padding-left: 76px !important;
  107. }
  108. /deep/ .el-menu-item.is-active {
  109. color: #fff !important;
  110. background-color: #0C2B47 !important;
  111. border-right: 6px solid #009CFF;
  112. }
  113. .sidebar {
  114. display: block;
  115. position: absolute;
  116. left: 0;
  117. top: 0;
  118. bottom: 0;
  119. box-sizing: border-box;
  120. padding-top: 80px;
  121. }
  122. .side-logo {
  123. width: 100%;
  124. height: 80px;
  125. box-sizing: border-box;
  126. padding-top: 18px;
  127. position: absolute;
  128. top: 0;
  129. left: 0;
  130. z-index: 400;
  131. background-color: #fff;
  132. font-size: 0;
  133. padding-left: 32px;
  134. cursor: pointer;
  135. }
  136. .logo {
  137. width: 204px;
  138. height: 44px;
  139. }
  140. .side-bar-icon {
  141. width: 21px;
  142. height: 21px;
  143. margin-right: 18px;
  144. margin-left: 14px;
  145. }
  146. .aliFamily {
  147. font-size: 24px;
  148. margin-right: 10px;
  149. }
  150. .sidebar::-webkit-scrollbar {
  151. width: 0;
  152. }
  153. .sidebar-el-menu:not(.el-menu--collapse) {
  154. width: 254px;
  155. box-sizing: border-box;
  156. }
  157. .sidebar>ul {
  158. height: 100%;
  159. }
  160. </style>