index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div :class="{ 'has-logo': showLogo }"
  3. :style="{ backgroundColor: sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }">
  4. <logo v-if="showLogo" :collapse="isCollapse"/>
  5. <el-row class="headBar">
  6. <el-col :span="8.5">
  7. <div class="line-left-img">
  8. <img src="@/assets/images/top.png" alt=""/>
  9. </div>
  10. <div class="line-left-name">
  11. <span>上海市水务海洋数字孪生模型服务管理系统</span>
  12. </div>
  13. </el-col>
  14. <el-col :span="14">
  15. <el-scrollbar :class="sideTheme" wrap-class="scrollbar-wrapper" style="margin-left: 5%;">
  16. <el-menu
  17. :default-active="activeMenu"
  18. :collapse="isCollapse"
  19. :background-color="sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground"
  20. :text-color="sideTheme === 'theme-dark' ? variables.menuColor : variables.menuLightColor"
  21. :unique-opened="true"
  22. :active-text-color="theme"
  23. :collapse-transition="false"
  24. mode="horizontal"
  25. >
  26. <sidebar-item
  27. v-for="(route, index) in sidebarRouters"
  28. :key="route.path + index"
  29. :item="route"
  30. :base-path="route.path"
  31. />
  32. </el-menu>
  33. </el-scrollbar>
  34. </el-col>
  35. <el-col :span="1">
  36. <div class="avatar-container">
  37. <el-dropdown @command="handleCommand" class="right-menu-item hover-effect" trigger="click">
  38. <div class="avatar-wrapper">
  39. <img :src="userStore.avatar" class="user-avatar"/>
  40. <el-icon>
  41. <caret-bottom/>
  42. </el-icon>
  43. </div>
  44. <template #dropdown>
  45. <el-dropdown-menu>
  46. <router-link to="/user/profile">
  47. <el-dropdown-item>个人中心</el-dropdown-item>
  48. </router-link>
  49. <!-- <el-dropdown-item command="setLayout" v-if="settingsStore.showSettings">
  50. <span>布局设置</span>
  51. </el-dropdown-item> -->
  52. <el-dropdown-item divided command="logout">
  53. <span>退出登录</span>
  54. </el-dropdown-item>
  55. </el-dropdown-menu>
  56. </template>
  57. </el-dropdown>
  58. </div>
  59. </el-col>
  60. </el-row>
  61. </div>
  62. </template>
  63. <script setup>
  64. import Logo from './Logo'
  65. import SidebarItem from './SidebarItem'
  66. import variables from '@/assets/styles/variables.module.scss'
  67. import useAppStore from '@/store/modules/app'
  68. import useSettingsStore from '@/store/modules/settings'
  69. import usePermissionStore from '@/store/modules/permission'
  70. import { ElMessageBox } from 'element-plus'
  71. import useUserStore from '@/store/modules/user'
  72. import { ref, onMounted, onUnmounted, nextTick } from 'vue';
  73. import Cookies from 'js-cookie'
  74. const route = useRoute();
  75. const appStore = useAppStore()
  76. const userStore = useUserStore()
  77. const settingsStore = useSettingsStore()
  78. const permissionStore = usePermissionStore()
  79. const sidebarRouters = computed(() => permissionStore.sidebarRouters);
  80. const showLogo = computed(() => settingsStore.sidebarLogo);
  81. const sideTheme = computed(() => settingsStore.sideTheme);
  82. const theme = computed(() => settingsStore.theme);
  83. const isCollapse = computed(() => !appStore.sidebar.opened);
  84. const activeMenu = computed(() => {
  85. const {meta, path} = route;
  86. // if set path, the sidebar will highlight the path you set
  87. if (meta.activeMenu) {
  88. return meta.activeMenu;
  89. }
  90. return path;
  91. })
  92. onMounted(() => {
  93. appStore.sidebar.opened = true
  94. console.log(Cookies.get('sidebarStatus'))
  95. });
  96. function handleCommand(command) {
  97. switch (command) {
  98. case "setLayout":
  99. setLayout();
  100. break;
  101. case "logout":
  102. logout();
  103. break;
  104. default:
  105. break;
  106. }
  107. }
  108. </script>
  109. <style>
  110. .headBar {
  111. height: 60px;
  112. line-height: 60px;
  113. background-image: url('../../../assets/images/title-background.png') !important;
  114. .line-left-img {
  115. float: left;
  116. img {
  117. width: 60px;
  118. height: 60px;
  119. margin-left: 10px;
  120. }
  121. }
  122. .line-left-name {
  123. float: left;
  124. span {
  125. font-size: 25px;
  126. font-weight: bold;
  127. color: #f5f6f8;
  128. height: 60px;
  129. line-height: 60px;
  130. letter-spacing: 3px;
  131. }
  132. }
  133. }
  134. .el-menu {
  135. background-color: transparent !important; /* 使用 !important 确保优先级 */
  136. font-size: 20px !important;
  137. }
  138. .avatar-container {
  139. .avatar-wrapper {
  140. margin-top: 10px;
  141. position: relative;
  142. .user-avatar {
  143. cursor: pointer;
  144. width: 40px;
  145. height: 40px;
  146. border-radius: 10px;
  147. }
  148. i {
  149. cursor: pointer;
  150. position: absolute;
  151. right: -20px;
  152. top: 25px;
  153. font-size: 12px;
  154. }
  155. }
  156. }
  157. </style>