SidebarMenu.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <script setup>
  2. import { computed } from 'vue'
  3. import { useRouter, useRoute } from 'vue-router'
  4. import {
  5. Picture,
  6. List,
  7. User,
  8. Operation,
  9. Fold,
  10. Expand,
  11. Aim,
  12. Coin,
  13. DataAnalysis,
  14. Cpu,
  15. Download,
  16. SetUp,
  17. Bell,
  18. Files,
  19. Notebook,
  20. FolderOpened,
  21. MagicStick,
  22. } from '@element-plus/icons-vue'
  23. import { isCollapsed, toggleCollapse } from '../stores/sidebarStore'
  24. const router = useRouter()
  25. const route = useRoute()
  26. // 使用全局状态管理的折叠状态
  27. const isCollapse = isCollapsed
  28. // 从 localStorage 获取用户信息
  29. const userInfo = computed(() => {
  30. const storedUser = localStorage.getItem('login_user')
  31. return storedUser ? JSON.parse(storedUser) : {}
  32. })
  33. // 判断用户角色
  34. const isAdmin = computed(() => userInfo.value?.role === 'ADMIN')
  35. const isDeveloper = computed(() => userInfo.value?.role === 'DEVELOPER')
  36. const isAdminOrDeveloper = computed(() => isAdmin.value || isDeveloper.value)
  37. // 导航菜单项
  38. const menuItems = computed(() => [
  39. {
  40. name: '数据看板',
  41. path: '/home',
  42. icon: DataAnalysis,
  43. visible: true
  44. },
  45. {
  46. name: '模型训练',
  47. path: '/model-training',
  48. icon: MagicStick,
  49. visible: isAdminOrDeveloper.value
  50. },
  51. {
  52. name: '桥梁安全隐患检测',
  53. path: '/disease-detection',
  54. icon: Aim,
  55. visible: true
  56. },
  57. {
  58. name: '安全隐患检测记录',
  59. path: '/detection-records',
  60. icon: List,
  61. visible: true
  62. },
  63. {
  64. name: '批量安全隐患检测',
  65. path: '/batch-detection',
  66. icon: Files,
  67. visible: true
  68. },
  69. {
  70. name: '安全隐患台账',
  71. path: '/defect-ledger',
  72. icon: Notebook,
  73. visible: true
  74. },
  75. {
  76. name: '报告中心',
  77. path: '/report-center',
  78. icon: FolderOpened,
  79. visible: true
  80. },
  81. {
  82. name: '媒体库',
  83. path: '/media-library',
  84. icon: Picture,
  85. visible: true
  86. },
  87. {
  88. name: '传感器管理',
  89. path: '/sensor-management',
  90. icon: Cpu,
  91. visible: true
  92. },
  93. {
  94. name: '数据采集',
  95. path: '/data-collection',
  96. icon: Download,
  97. visible: true
  98. },
  99. {
  100. name: '数据处理',
  101. path: '/data-processing',
  102. icon: SetUp,
  103. visible: true
  104. },
  105. {
  106. name: '预警管理',
  107. path: '/alert-management',
  108. icon: Bell,
  109. visible: true
  110. },
  111. {
  112. name: '模型库',
  113. path: '/model-library',
  114. icon: Coin,
  115. visible: isDeveloper.value
  116. },
  117. {
  118. name: '用户管理',
  119. path: '/user-management',
  120. icon: User,
  121. visible: isAdminOrDeveloper.value
  122. },
  123. {
  124. name: '系统操作日志',
  125. path: '/operation-logs',
  126. icon: Operation,
  127. visible: isAdminOrDeveloper.value
  128. }
  129. ])
  130. // 当前活动菜单项
  131. const activeMenu = computed(() => route.path)
  132. // 导航到指定路径
  133. const navigateTo = (path) => {
  134. router.push(path)
  135. }
  136. </script>
  137. <template>
  138. <div class="sidebar-menu" :class="{ 'collapsed': isCollapse }">
  139. <div class="collapse-btn" @click="toggleCollapse">
  140. <el-icon class="collapse-icon">
  141. <component :is="isCollapse ? Expand : Fold" />
  142. </el-icon>
  143. <span class="collapse-text" :class="{ 'hidden': isCollapse }">收起菜单</span>
  144. </div>
  145. <el-menu :default-active="activeMenu" class="el-menu-vertical" :collapse="isCollapse" :collapse-transition="true">
  146. <el-menu-item v-for="(item, index) in menuItems.filter(item => item.visible)" :key="index" :index="item.path"
  147. @click="navigateTo(item.path)">
  148. <el-icon>
  149. <component :is="item.icon" />
  150. </el-icon>
  151. <template #title>
  152. <span class="menu-text">{{ item.name }}</span>
  153. </template>
  154. </el-menu-item>
  155. </el-menu>
  156. </div>
  157. </template>
  158. <style scoped>
  159. .sidebar-menu {
  160. height: 100%;
  161. width: 200px;
  162. flex-shrink: 0;
  163. background: linear-gradient(
  164. 185deg,
  165. var(--sidebar) 0%,
  166. color-mix(in srgb, var(--sidebar) 55%, var(--primary) 45%) 52%,
  167. var(--sidebar) 100%
  168. );
  169. transition: width 0.42s cubic-bezier(0.32, 1.38, 0.55, 1);
  170. position: relative;
  171. display: flex;
  172. flex-direction: column;
  173. box-shadow: 4px 0 32px rgba(15, 23, 42, 0.35);
  174. overflow: hidden;
  175. border-radius: 0 16px 16px 0;
  176. }
  177. .sidebar-menu.collapsed {
  178. width: 64px;
  179. }
  180. .el-menu-vertical {
  181. border-right: none;
  182. width: 100%;
  183. flex: 1;
  184. background-color: transparent !important;
  185. }
  186. .el-menu-vertical :deep(.el-menu-item) {
  187. height: 50px;
  188. line-height: 50px;
  189. color: rgba(248, 250, 252, 0.82);
  190. margin: 4px 0;
  191. border-radius: 10px;
  192. padding: 0 20px !important;
  193. transition: all 0.3s ease;
  194. display: flex;
  195. align-items: center;
  196. justify-content: flex-start;
  197. }
  198. .el-menu-vertical :deep(.el-menu-item.is-active) {
  199. background: linear-gradient(90deg, rgba(79, 70, 229, 0.38), rgba(99, 102, 241, 0.12));
  200. color: #f8fafc;
  201. font-weight: 600;
  202. box-shadow:
  203. inset 3px 0 0 0 rgba(129, 140, 248, 0.95),
  204. 0 0 28px rgba(79, 70, 229, 0.28),
  205. 0 6px 18px rgba(0, 0, 0, 0.22);
  206. transform: translateX(2px);
  207. }
  208. .el-menu-vertical :deep(.el-menu-item:hover:not(.is-active)) {
  209. background: rgba(248, 250, 252, 0.08);
  210. color: #ffffff;
  211. box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  212. }
  213. .collapse-btn {
  214. height: 40px;
  215. display: flex;
  216. align-items: center;
  217. justify-content: flex-start;
  218. padding: 0 20px;
  219. cursor: pointer;
  220. color: rgba(226, 232, 240, 0.75);
  221. transition: color 0.3s ease, background-color 0.3s ease;
  222. margin: 8px 0;
  223. }
  224. .collapse-icon {
  225. width: 24px;
  226. text-align: center;
  227. display: flex;
  228. justify-content: center;
  229. align-items: center;
  230. flex-shrink: 0;
  231. }
  232. .collapse-text {
  233. margin-left: 8px;
  234. font-size: 14px;
  235. transition: opacity 0.25s ease 0.05s, transform 0.3s ease;
  236. white-space: nowrap;
  237. opacity: 1;
  238. transform: translateX(0);
  239. }
  240. .collapse-text.hidden {
  241. opacity: 0;
  242. transform: translateX(-10px);
  243. }
  244. .menu-text {
  245. transition: opacity 0.25s ease 0.05s, transform 0.3s ease;
  246. opacity: 1;
  247. transform: translateX(0);
  248. display: inline-block;
  249. }
  250. .el-menu--collapse :deep(.el-menu-item) .menu-text {
  251. opacity: 0;
  252. transform: translateX(-10px);
  253. }
  254. .el-menu-vertical :deep(.el-icon) {
  255. width: 24px;
  256. text-align: center;
  257. transition: all 0.3s ease;
  258. display: flex;
  259. justify-content: center;
  260. align-items: center;
  261. margin-right: 8px;
  262. flex-shrink: 0;
  263. }
  264. .el-menu--collapse :deep(.el-menu-item) .el-icon {
  265. margin: 0 auto;
  266. justify-content: center;
  267. transform: translateX(0);
  268. left: 0;
  269. width: 24px;
  270. text-align: center;
  271. display: flex;
  272. align-items: center;
  273. }
  274. .collapse-btn:hover {
  275. color: #ffffff;
  276. background-color: rgba(255, 255, 255, 0.15);
  277. border-left: 3px solid rgba(201, 224, 255, 0.7);
  278. }
  279. /* 添加图标样式 */
  280. .el-menu-vertical :deep(.el-menu-item) .el-icon {
  281. color: rgba(226, 232, 240, 0.75);
  282. margin-right: 10px;
  283. transition: all 0.3s ease;
  284. }
  285. .el-menu-vertical :deep(.el-menu-item.is-active) .el-icon {
  286. color: #ffffff;
  287. transform: scale(1.05);
  288. }
  289. .el-menu-vertical :deep(.el-menu-item:hover) .el-icon {
  290. color: #ffffff;
  291. transform: scale(1.1);
  292. }
  293. .collapse-btn:hover {
  294. color: #ffffff;
  295. background-color: rgba(255, 255, 255, 0.15);
  296. border-left: 3px solid rgba(201, 224, 255, 0.7);
  297. }
  298. </style>