App.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <el-config-provider :locale="zhCn">
  3. <!-- 登录/注册页面不显示布局 -->
  4. <template v-if="hideLayout">
  5. <router-view />
  6. </template>
  7. <!-- 正常布局 -->
  8. <div v-else class="app-container">
  9. <!-- 顶部导航 -->
  10. <header class="app-header">
  11. <div class="header-left">
  12. <div class="logo" @click="router.push('/')">
  13. <div class="logo-icon">📊</div>
  14. <span>灵越智报</span>
  15. </div>
  16. <el-input
  17. v-model="searchKeyword"
  18. placeholder="搜索报告、模板..."
  19. prefix-icon="Search"
  20. class="search-input"
  21. clearable
  22. />
  23. </div>
  24. <div class="header-right">
  25. <el-badge :value="3" class="notification-badge">
  26. <el-button :icon="Bell" circle />
  27. </el-badge>
  28. <el-dropdown trigger="click" @command="handleUserCommand">
  29. <div class="user-menu">
  30. <el-avatar :size="32" class="user-avatar">{{ userInitial }}</el-avatar>
  31. <span class="user-name">{{ username }}</span>
  32. </div>
  33. <template #dropdown>
  34. <el-dropdown-menu>
  35. <el-dropdown-item command="profile">个人中心</el-dropdown-item>
  36. <el-dropdown-item command="settings">系统设置</el-dropdown-item>
  37. <el-dropdown-item command="logout" divided>退出登录</el-dropdown-item>
  38. </el-dropdown-menu>
  39. </template>
  40. </el-dropdown>
  41. </div>
  42. </header>
  43. <!-- 主体区域 -->
  44. <div class="app-body">
  45. <!-- 侧边栏 -->
  46. <aside class="app-sidebar" v-if="!isEditorPage">
  47. <el-menu
  48. :default-active="currentRoute"
  49. router
  50. class="sidebar-menu"
  51. >
  52. <el-menu-item index="/">
  53. <el-icon><HomeFilled /></el-icon>
  54. <span>首页</span>
  55. </el-menu-item>
  56. <el-menu-item index="/templates">
  57. <el-icon><Files /></el-icon>
  58. <span>模板管理</span>
  59. </el-menu-item>
  60. <el-menu-item index="/generations">
  61. <el-icon><Document /></el-icon>
  62. <span>生成记录</span>
  63. </el-menu-item>
  64. <el-divider />
  65. <el-menu-item index="/help">
  66. <el-icon><QuestionFilled /></el-icon>
  67. <span>帮助中心</span>
  68. </el-menu-item>
  69. </el-menu>
  70. </aside>
  71. <!-- 内容区 -->
  72. <main class="app-main" :class="{ 'full-width': isEditorPage }">
  73. <router-view />
  74. </main>
  75. </div>
  76. </div>
  77. </el-config-provider>
  78. </template>
  79. <script setup>
  80. import { ref, computed } from 'vue'
  81. import { useRouter, useRoute } from 'vue-router'
  82. import { Bell, HomeFilled, Files, Document, QuestionFilled } from '@element-plus/icons-vue'
  83. import { ElMessage, ElMessageBox } from 'element-plus'
  84. import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
  85. const router = useRouter()
  86. const route = useRoute()
  87. const searchKeyword = ref('')
  88. const currentRoute = computed(() => route.path)
  89. const isEditorPage = computed(() => route.path.startsWith('/editor'))
  90. const hideLayout = computed(() => route.meta.hideLayout === true)
  91. // 用户信息
  92. const username = computed(() => localStorage.getItem('username') || '用户')
  93. const userInitial = computed(() => username.value.charAt(0))
  94. // 用户菜单操作
  95. function handleUserCommand(command) {
  96. switch (command) {
  97. case 'profile':
  98. ElMessage.info('个人中心开发中...')
  99. break
  100. case 'settings':
  101. ElMessage.info('系统设置开发中...')
  102. break
  103. case 'logout':
  104. ElMessageBox.confirm('确定要退出登录吗?', '退出确认', {
  105. confirmButtonText: '退出',
  106. cancelButtonText: '取消',
  107. type: 'warning'
  108. }).then(() => {
  109. // 清除登录信息
  110. localStorage.removeItem('accessToken')
  111. localStorage.removeItem('refreshToken')
  112. localStorage.removeItem('userId')
  113. localStorage.removeItem('username')
  114. ElMessage.success('已退出登录')
  115. router.push('/login')
  116. }).catch(() => {})
  117. break
  118. }
  119. }
  120. </script>
  121. <style lang="scss">
  122. .app-container {
  123. height: 100vh;
  124. display: flex;
  125. flex-direction: column;
  126. }
  127. .app-header {
  128. height: 56px;
  129. background: #fff;
  130. border-bottom: 1px solid #e8e8e8;
  131. display: flex;
  132. align-items: center;
  133. justify-content: space-between;
  134. padding: 0 20px;
  135. flex-shrink: 0;
  136. }
  137. .header-left {
  138. display: flex;
  139. align-items: center;
  140. gap: 20px;
  141. }
  142. .logo {
  143. display: flex;
  144. align-items: center;
  145. gap: 8px;
  146. font-size: 17px;
  147. font-weight: 600;
  148. color: #1890ff;
  149. cursor: pointer;
  150. .logo-icon {
  151. width: 32px;
  152. height: 32px;
  153. background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  154. border-radius: 8px;
  155. display: flex;
  156. align-items: center;
  157. justify-content: center;
  158. color: white;
  159. font-size: 18px;
  160. }
  161. }
  162. .search-input {
  163. width: 320px;
  164. }
  165. .header-right {
  166. display: flex;
  167. align-items: center;
  168. gap: 16px;
  169. }
  170. .notification-badge {
  171. .el-button {
  172. font-size: 18px;
  173. }
  174. }
  175. .user-menu {
  176. display: flex;
  177. align-items: center;
  178. gap: 8px;
  179. cursor: pointer;
  180. padding: 4px 8px;
  181. border-radius: 20px;
  182. &:hover {
  183. background: #f5f7fa;
  184. }
  185. }
  186. .user-avatar {
  187. background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  188. }
  189. .user-name {
  190. font-size: 14px;
  191. font-weight: 500;
  192. }
  193. .app-body {
  194. flex: 1;
  195. display: flex;
  196. overflow: hidden;
  197. }
  198. .app-sidebar {
  199. width: 200px;
  200. background: #fff;
  201. border-right: 1px solid #e8e8e8;
  202. flex-shrink: 0;
  203. .sidebar-menu {
  204. border-right: none;
  205. height: 100%;
  206. }
  207. }
  208. .app-main {
  209. flex: 1;
  210. overflow-y: auto;
  211. background: #f5f7fa;
  212. padding: 20px;
  213. &.full-width {
  214. padding: 0;
  215. }
  216. }
  217. </style>