SidevarItem.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div class="box-item">
  3. <el-menu
  4. class="el-menu-vertical-demo"
  5. text-color="#fff"
  6. :default-active="activeIndex"
  7. :collapse="menuClose"
  8. @select="handleSelect"
  9. :router="true"
  10. >
  11. <!-- :default-openeds="[34]" -->
  12. <div class="logo el-menu-item">
  13. <el-icon :size="20"
  14. ><img src="@/assets/images/logo.png" style="width: 40px; height: 40px"
  15. /></el-icon>
  16. </div>
  17. <el-menu-item :index="`/process/${item.name}`" v-for="item in roleList" :key="item.name">
  18. <div class="itemSon">
  19. <SvgIcon :icon="item.meta.icon" :size="22" />
  20. <span>{{ item.meta.title }}</span>
  21. </div>
  22. </el-menu-item>
  23. </el-menu>
  24. </div>
  25. </template>
  26. <script setup>
  27. import { ref, onBeforeMount, onMounted, watch, reactive } from "vue";
  28. import { useStore } from "vuex";
  29. import { useRouter } from "vue-router";
  30. const store = useStore();
  31. const router = useRouter();
  32. const roleList = ref();
  33. const menuClose = ref(false);
  34. const activeIndex = ref('/process/user');
  35. const acitveItems = reactive({ list: [] });
  36. watch(
  37. () => store.state.user.collapse,
  38. (newValue, oldValue) => {
  39. menuClose.value = newValue;
  40. }
  41. );
  42. watch(
  43. () => router.currentRoute.value.fullPath,
  44. (newValue, oldValue) => {
  45. console.log(newValue);
  46. store.commit("indexUp", newValue);
  47. activeIndex.value = newValue;
  48. }
  49. );
  50. const handleSelect = (key, keyPath) => {
  51. // store.commit("indexUp", key);
  52. // activeIndex.value = key;
  53. // sessionStorage.setItem("sidevarItem", key);
  54. console.log(key, keyPath);
  55. router.push({
  56. path: `${key}`,
  57. });
  58. activeIndex.value = key;
  59. store.commit("indexUp", key);
  60. // if (activeIndex.value == 1) {
  61. // router.push({
  62. // path: `/jianguanCloud/order`,
  63. // });
  64. // }
  65. };
  66. onBeforeMount(() => {
  67. activeIndex.value = sessionStorage.getItem("sidevarItem");
  68. roleList.value = store.state.user.roleList;
  69. });
  70. </script>
  71. <style lang="scss" scoped>
  72. .el-menu-vertical-demo:not(.el-menu--collapse) {
  73. width: 220px;
  74. // min-height: 400px;
  75. }
  76. .box-item {
  77. width: 220px;
  78. height: calc(100vh);
  79. }
  80. .el-menu {
  81. width: 220px;
  82. height: 100%;
  83. overflow: auto;
  84. // background: rgba(55, 105, 173, 1);
  85. background: rgba(46, 64, 89, 1);
  86. box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.16);
  87. border: none;
  88. .logo {
  89. height: 64px;
  90. color: rgb(255, 255, 255);
  91. cursor: default;
  92. display: flex;
  93. justify-content: space-around;
  94. align-items: center;
  95. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  96. }
  97. .logo:hover {
  98. background-color: transparent !important;
  99. }
  100. .itemSon {
  101. width: 180px;
  102. height: 40px;
  103. border-radius: 10px;
  104. display: flex;
  105. // justify-content: space-around;
  106. align-items: center;
  107. // background: linear-gradient(
  108. // 90deg,
  109. // rgba(38, 151, 255, 1) 0%,
  110. // rgba(102, 182, 255, 1) 100%
  111. // );
  112. .svg-icon{
  113. margin:0 15px;
  114. }
  115. }
  116. .el-sub-menu {
  117. padding: 8px 0;
  118. .el-menu-item {
  119. padding: 0;
  120. background: rgba(46, 64, 89, 1);
  121. color: #fff;
  122. display: flex;
  123. justify-content: center;
  124. .img {
  125. width: 18px;
  126. margin: 0 20px;
  127. }
  128. .itemSon:hover {
  129. background: rgba(55, 105, 173, 1);
  130. color: rgba(99, 180, 255, 1);
  131. }
  132. }
  133. .el-menu-item:hover {
  134. background: rgba(46, 64, 89, 1);
  135. color: #fff;
  136. .itemSon {
  137. background: rgba(55, 105, 173, 1);
  138. color: rgba(99, 180, 255, 1);
  139. }
  140. }
  141. .el-menu-item.is-active {
  142. .itemSon {
  143. background: rgba(55, 105, 173, 1);
  144. color: rgba(99, 180, 255, 1);
  145. }
  146. }
  147. // 系统设置栏样式
  148. :deep(.el-sub-menu__title) {
  149. padding: 0;
  150. margin: 0 auto;
  151. width: 180px;
  152. height: 40px;
  153. border-radius: 10px;
  154. display: flex;
  155. align-items: center;
  156. background: rgba(55, 105, 173, 1);
  157. color: #fff;
  158. .el-icon {
  159. width: 18px;
  160. }
  161. }
  162. }
  163. .el-sub-menu.is-active {
  164. :deep(.el-sub-menu__title) {
  165. background: linear-gradient(
  166. 90deg,
  167. rgba(38, 151, 255, 1) 0%,
  168. rgba(102, 182, 255, 1) 100%
  169. );
  170. color: fff;
  171. }
  172. }
  173. // 单个菜单项样式
  174. .el-menu-item {
  175. padding: 10px 0 !important;
  176. display: flex;
  177. justify-content: center;
  178. }
  179. .el-menu-item:hover {
  180. background: rgba(46, 64, 89, 1);
  181. .itemSon {
  182. background: rgba(55, 105, 173, 1);
  183. color: rgba(99, 180, 255, 1);
  184. }
  185. }
  186. .el-menu-item.is-active {
  187. .itemSon {
  188. background: linear-gradient(
  189. 90deg,
  190. rgba(38, 151, 255, 1) 0%,
  191. rgba(102, 182, 255, 1) 100%
  192. );
  193. color: #fff;
  194. }
  195. }
  196. }
  197. </style>