App.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. <!-- 任务中心悬浮按钮和面板 -->
  77. <TaskCenterFab />
  78. <TaskCenterPanel />
  79. </div>
  80. </el-config-provider>
  81. </template>
  82. <script setup>
  83. import { ref, computed } from 'vue'
  84. import { useRouter, useRoute } from 'vue-router'
  85. import { Bell, HomeFilled, Files, Document, QuestionFilled } from '@element-plus/icons-vue'
  86. import { ElMessage, ElMessageBox } from 'element-plus'
  87. import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
  88. import TaskCenterFab from '@/components/TaskCenter/TaskCenterFab.vue'
  89. import TaskCenterPanel from '@/components/TaskCenter/TaskCenterPanel.vue'
  90. const router = useRouter()
  91. const route = useRoute()
  92. const searchKeyword = ref('')
  93. const currentRoute = computed(() => route.path)
  94. const isEditorPage = computed(() => route.path.startsWith('/editor'))
  95. const hideLayout = computed(() => route.meta.hideLayout === true)
  96. // 用户信息
  97. const username = computed(() => localStorage.getItem('username') || '用户')
  98. const userInitial = computed(() => username.value.charAt(0))
  99. // 用户菜单操作
  100. function handleUserCommand(command) {
  101. switch (command) {
  102. case 'profile':
  103. ElMessage.info('个人中心开发中...')
  104. break
  105. case 'settings':
  106. ElMessage.info('系统设置开发中...')
  107. break
  108. case 'logout':
  109. ElMessageBox.confirm('确定要退出登录吗?', '退出确认', {
  110. confirmButtonText: '退出',
  111. cancelButtonText: '取消',
  112. type: 'warning'
  113. }).then(() => {
  114. // 清除登录信息
  115. localStorage.removeItem('accessToken')
  116. localStorage.removeItem('refreshToken')
  117. localStorage.removeItem('userId')
  118. localStorage.removeItem('username')
  119. ElMessage.success('已退出登录')
  120. router.push('/login')
  121. }).catch(() => {})
  122. break
  123. }
  124. }
  125. </script>
  126. <style lang="scss">
  127. .app-container {
  128. height: 100vh;
  129. display: flex;
  130. flex-direction: column;
  131. }
  132. .app-header {
  133. height: 56px;
  134. background: #fff;
  135. border-bottom: 1px solid #e8e8e8;
  136. display: flex;
  137. align-items: center;
  138. justify-content: space-between;
  139. padding: 0 20px;
  140. flex-shrink: 0;
  141. }
  142. .header-left {
  143. display: flex;
  144. align-items: center;
  145. gap: 20px;
  146. }
  147. .logo {
  148. display: flex;
  149. align-items: center;
  150. gap: 8px;
  151. font-size: 17px;
  152. font-weight: 600;
  153. color: #1890ff;
  154. cursor: pointer;
  155. .logo-icon {
  156. width: 32px;
  157. height: 32px;
  158. background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  159. border-radius: 8px;
  160. display: flex;
  161. align-items: center;
  162. justify-content: center;
  163. color: white;
  164. font-size: 18px;
  165. }
  166. }
  167. .search-input {
  168. width: 320px;
  169. }
  170. .header-right {
  171. display: flex;
  172. align-items: center;
  173. gap: 16px;
  174. }
  175. .notification-badge {
  176. .el-button {
  177. font-size: 18px;
  178. }
  179. }
  180. .user-menu {
  181. display: flex;
  182. align-items: center;
  183. gap: 8px;
  184. cursor: pointer;
  185. padding: 4px 8px;
  186. border-radius: 20px;
  187. &:hover {
  188. background: #f5f7fa;
  189. }
  190. }
  191. .user-avatar {
  192. background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  193. }
  194. .user-name {
  195. font-size: 14px;
  196. font-weight: 500;
  197. }
  198. .app-body {
  199. flex: 1;
  200. display: flex;
  201. overflow: hidden;
  202. }
  203. .app-sidebar {
  204. width: 200px;
  205. background: #fff;
  206. border-right: 1px solid #e8e8e8;
  207. flex-shrink: 0;
  208. .sidebar-menu {
  209. border-right: none;
  210. height: 100%;
  211. }
  212. }
  213. .app-main {
  214. flex: 1;
  215. overflow-y: auto;
  216. background: #f5f7fa;
  217. padding: 20px;
  218. &.full-width {
  219. padding: 0;
  220. }
  221. }
  222. </style>