Sidebar.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div class="nav-sidebar">
  3. <!-- Logo区域 -->
  4. <div class="logo-section" @click="goToHome">
  5. <img src="@/assets/index/2.jpg" alt="logo" class="logo-image">
  6. </div>
  7. <!-- 导航菜单 -->
  8. <div class="nav-menu">
  9. <div class="nav-item" :class="{ active: currentRoute === 'Chat' }" @click="handleNavItem('ai-chat')">
  10. <img src="@/assets/Chat/17.png" alt="AI问答" class="nav-icon">
  11. <span class="nav-text">AI问答</span>
  12. </div>
  13. <div class="nav-item" :class="{ active: currentRoute === 'HazardDetection' }" @click="handleNavItem('hazard-detection')">
  14. <img src="@/assets/Chat/8.png" alt="隐患识别" class="nav-icon">
  15. <span class="nav-text">隐患提示</span>
  16. </div>
  17. <div class="nav-item" :class="{ active: currentRoute === 'SafetyHazard' }" @click="handleNavItem('safety-hazard')">
  18. <img src="@/assets/Chat/14.png" alt="安全隐患" class="nav-icon">
  19. <span class="nav-text">安全培训</span>
  20. </div>
  21. <div class="nav-item" :class="{ active: currentRoute === 'AIWriting' }" @click="handleNavItem('ai-writing')">
  22. <img src="@/assets/Chat/13.png" alt="AI写作" class="nav-icon">
  23. <span class="nav-text">AI写作</span>
  24. </div>
  25. <div class="nav-item" :class="{ active: currentRoute === 'ExamWorkshop' }" @click="handleNavItem('exam-workshop')">
  26. <img src="@/assets/Chat/19.png" alt="考试工坊" class="nav-icon">
  27. <span class="nav-text">考试工坊</span>
  28. </div>
  29. </div>
  30. <!-- 退出按钮 -->
  31. <!-- <div class="logout-section">
  32. <div class="nav-item logout-item" @click="handleLogout">
  33. <img src="@/assets/out.png" alt="退出" class="out-icon">
  34. <span class="nav-text">退出</span>
  35. </div>
  36. </div> -->
  37. </div>
  38. </template>
  39. <script setup>
  40. import { computed } from 'vue'
  41. import { useRouter, useRoute } from 'vue-router'
  42. import { performLogout } from '../utils/auth.js'
  43. const router = useRouter()
  44. const route = useRoute()
  45. // 当前路由
  46. const currentRoute = computed(() => {
  47. console.log('当前路由名称:', route.name, '当前路径:', route.path)
  48. return route.name
  49. })
  50. // 切换导航项
  51. const handleNavItem = (navType) => {
  52. console.log('切换导航:', navType)
  53. switch (navType) {
  54. case 'ai-chat':
  55. router.push('/chat')
  56. break
  57. case 'safety-hazard':
  58. router.push('/safety-hazard')
  59. break
  60. case 'hazard-detection':
  61. router.push('/hazard-detection')
  62. break
  63. case 'ai-writing':
  64. router.push('/ai-writing')
  65. break
  66. case 'exam-workshop':
  67. router.push('/exam-workshop')
  68. break
  69. }
  70. }
  71. // 回到首页
  72. const goToHome = () => {
  73. router.push('/')
  74. }
  75. // 退出登录
  76. const handleLogout = () => {
  77. console.log('退出登录')
  78. performLogout()
  79. }
  80. </script>
  81. <style lang="less" scoped>
  82. /* 最左侧导航栏 */
  83. .nav-sidebar {
  84. width: 80px;
  85. min-width: 80px;
  86. flex-shrink: 0;
  87. background: url('@/assets/Chat/1.png') no-repeat center center;
  88. background-size: cover;
  89. color: white;
  90. display: flex;
  91. flex-direction: column;
  92. align-items: center;
  93. padding: 20px 8px;
  94. }
  95. /* 最左侧导航栏样式 */
  96. .nav-sidebar {
  97. .logo-section {
  98. margin-bottom: 30px;
  99. cursor: pointer;
  100. transition: opacity 0.3s ease;
  101. &:hover {
  102. opacity: 0.8;
  103. }
  104. .logo-image {
  105. width: 44px;
  106. height: 44px;
  107. object-fit: contain;
  108. // border-radius: 50%;
  109. }
  110. }
  111. .nav-menu {
  112. display: flex;
  113. flex-direction: column;
  114. gap: 15px;
  115. .nav-item {
  116. width: 60px;
  117. display: flex;
  118. flex-direction: column;
  119. align-items: center;
  120. justify-content: center;
  121. cursor: pointer;
  122. transition: all 0.3s ease;
  123. .nav-icon {
  124. width: 44px;
  125. height: 44px;
  126. object-fit: contain;
  127. margin-bottom: 4px;
  128. padding: 8px;
  129. border-radius: 50%;
  130. transition: background 0.3s ease;
  131. }
  132. &:hover .nav-icon {
  133. background: rgba(255, 255, 255, 0.1);
  134. }
  135. &.active .nav-icon {
  136. background: rgba(255, 255, 255, 0.3);
  137. transform: scale(1.1);
  138. box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
  139. filter: brightness(1.2);
  140. }
  141. &.active .nav-text {
  142. color: #FFFFFF;
  143. font-weight: 600;
  144. }
  145. .nav-text {
  146. font-size: 12px;
  147. color: #CACACA;
  148. text-align: center;
  149. line-height: 1.2;
  150. white-space: nowrap;
  151. transition: all 0.3s ease;
  152. }
  153. }
  154. }
  155. /* 退出按钮区域 */
  156. .logout-section {
  157. margin-top: auto;
  158. padding-top: 20px;
  159. .logout-item {
  160. &:hover .nav-icon {
  161. background: rgba(255, 0, 0, 0.1);
  162. }
  163. .out-icon {
  164. // filter: brightness(0.8);
  165. width: 44px;
  166. height: 44px;
  167. object-fit: contain;
  168. margin-bottom: 4px;
  169. padding: 8px;
  170. // border-radius: 50%;
  171. transition: background 0.3s ease;
  172. }
  173. .nav-text {
  174. color: #FF6B6B;
  175. }
  176. }
  177. }
  178. }
  179. </style>