App.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div id="app">
  3. <ElConfigProvider :locale="langStore.elLocale">
  4. <el-container style="min-height: 100vh;">
  5. <el-header>
  6. <div class="header-content">
  7. <div class="logo" @click="$router.push('/')">{{ $t('common.title') }}</div>
  8. <el-menu :default-active="activeIndex" mode="horizontal" :ellipsis="false" class="meauList">
  9. <el-menu-item index="1" @click="$router.push('/')">AI{{ $t('common.gongzuoliu') }}</el-menu-item>
  10. <!-- <el-menu-item index="2" @click="$router.push('/my-learning')">工作流交易</el-menu-item> -->
  11. <el-menu-item index="2" @click="goMyLearning">{{ $t('common.gongzuoliu_trade') }}</el-menu-item>
  12. <el-menu-item index="3" @click="$router.push('/my-learning')">学习教程系统</el-menu-item>
  13. <el-menu-item index="4" @click="$router.push('/my-learning')">学习笔记</el-menu-item>
  14. <el-menu-item index="5" @click="$router.push('/my-learning')">米币商城</el-menu-item>
  15. </el-menu>
  16. <div class="header-right">
  17. <el-avatar :size="32" :src="appStore.userInfo?.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" />
  18. <el-dropdown v-if="appStore.token">
  19. <span class="el-dropdown-link">
  20. {{ appStore.userInfo?.nickName || '用户' }}
  21. <el-icon class="el-icon--right">
  22. <arrow-down />
  23. </el-icon>
  24. </span>
  25. <template #dropdown>
  26. <el-dropdown-menu>
  27. <el-dropdown-item @click="handleLogout">{{ $t('common.logout') }}</el-dropdown-item>
  28. </el-dropdown-menu>
  29. </template>
  30. </el-dropdown>
  31. <!-- 打开登录弹框 -->
  32. <el-button type="text" @click="openLoginDialog" v-if="!appStore.token">{{ $t('common.login') }}</el-button>
  33. <LangSwitch />
  34. </div>
  35. </div>
  36. </el-header>
  37. <!-- 固定头部占位 -->
  38. <div style="height: 60px;"></div>
  39. <el-main class="container">
  40. <router-view />
  41. </el-main>
  42. <el-footer>
  43. <div class="footer-content">
  44. <p>服务协议隐私政策浙ICP备2024141841号-6浙公网安备 33011002018505 号</p>
  45. </div>
  46. </el-footer>
  47. </el-container>
  48. <!-- 登录弹框组件 -->
  49. <LoginDialog ref="loginDialogRef" @login-success="handleLoginSuccess" />
  50. </ElConfigProvider>
  51. </div>
  52. </template>
  53. <script setup>
  54. import { logout } from '@/api/auth.js'
  55. import LoginDialog from './components/LoginDialog.vue'
  56. import { computed,ref,onMounted } from 'vue'
  57. import LangSwitch from './components/LangSwitch.vue'
  58. import { ElConfigProvider, ElMessage } from 'element-plus'
  59. import { useRoute, useRouter } from 'vue-router'
  60. // 在Pinia安装后再设置初始语言
  61. import { useLangStore } from '@/pinia/langStore'
  62. import { useAppStore } from '@/pinia/appStore'
  63. const langStore = useLangStore();
  64. const appStore = useAppStore();
  65. $i18n.global.locale.value = langStore.currentLang
  66. // 动态更新页面标题
  67. langStore.updateDynamicTitle()
  68. const route = useRoute()
  69. const router = useRouter()
  70. // 登录弹框引用
  71. const loginDialogRef = ref(null)
  72. onMounted(() => {
  73. appStore.USERINFO()
  74. })
  75. // 打开登录弹框
  76. const openLoginDialog = () => {
  77. loginDialogRef.value?.open()
  78. }
  79. // 处理登录成功
  80. const handleLoginSuccess = () => {
  81. console.log('登录成功')
  82. // 可以在这里处理登录后的逻辑,比如更新用户信息、刷新页面等
  83. }
  84. //
  85. function goMyLearning() {
  86. router.push('/my-learning')
  87. };
  88. // 将 activeIndex 改为响应式,并根据当前路由动态计算
  89. const activeIndex = computed(() => {
  90. console.log(route)
  91. if (route.path === '/') return '1'
  92. if (route.path.startsWith('/my-learning')) {
  93. return '2'
  94. }
  95. return '1' // 默认返回首页
  96. });
  97. // 处理注销
  98. const handleLogout = () => {
  99. logout().then(() => {
  100. appStore.LOGOUT()
  101. ElMessage.success('注销成功')
  102. router.push('/')
  103. })
  104. };
  105. </script>
  106. <style lang="scss">
  107. #app {
  108. font-family: Avenir, Helvetica, Arial, sans-serif;
  109. -webkit-font-smoothing: antialiased;
  110. -moz-osx-font-smoothing: grayscale;
  111. color: #2c3e50;
  112. }
  113. .el-header {
  114. // background-color: rgba(255, 255, 255, 0.5);
  115. background: url('@/assets/imgs/bg-header.png') no-repeat;
  116. background-size: 100% 100%;
  117. color: #333;
  118. line-height: 60px;
  119. // border-bottom: 1px solid #eee;
  120. position: fixed;
  121. top: 0;
  122. left: 0;
  123. right: 0;
  124. z-index: 1000;
  125. padding: 0;
  126. .header-content {
  127. max-width: 1520px;
  128. width: 80%;
  129. min-width: 1200px;
  130. margin: 0 auto;
  131. display: flex;
  132. align-items: center;
  133. justify-content: space-between;
  134. .logo {
  135. min-width: 220px;
  136. font-size: 24px;
  137. font-weight: bold;
  138. cursor: pointer;
  139. }
  140. .meauList{
  141. &.el-menu{
  142. background-color: transparent;
  143. }
  144. .el-menu--horizontal.el-menu{
  145. border-bottom: none;
  146. }
  147. .el-menu-item{
  148. font-size: 16px;
  149. }
  150. }
  151. .header-right {
  152. margin-right: 30px;
  153. display: flex;
  154. align-items: center; /* 垂直居中 */
  155. gap: 10px;
  156. }
  157. }
  158. }
  159. .el-footer {
  160. color: #666;
  161. text-align: center;
  162. padding: 20px 0;
  163. .footer-content {
  164. font-size: 14px;
  165. max-width: 1200px;
  166. margin: 0 auto;
  167. }
  168. }
  169. .el-main {
  170. padding: 0;
  171. }
  172. </style>