index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div class="wh-full" :class="classObj">
  3. <!-- 遮罩层 -->
  4. <div
  5. v-if="classObj.mobile && classObj.openSidebar"
  6. class="wh-full fixed-lt z-999 bg-black bg-opacity-30"
  7. @click="handleOutsideClick"
  8. ></div>
  9. <!-- 公用侧边栏 -->
  10. <Sidebar class="sidebar-container" />
  11. <!-- 混合布局 -->
  12. <div v-if="layout === 'mix'" class="mix-container">
  13. <div class="mix-container__left">
  14. <SidebarMenu :menu-list="mixLeftMenus" :base-path="activeTopMenuPath" />
  15. <div class="sidebar-toggle">
  16. <hamburger
  17. :is-active="appStore.sidebar.opened"
  18. @toggle-click="toggleSidebar"
  19. />
  20. </div>
  21. </div>
  22. <div :class="{ hasTagsView: showTagsView }" class="main-container">
  23. <div :class="{ 'fixed-header': fixedHeader }">
  24. <TagsView v-if="showTagsView" />
  25. </div>
  26. <AppMain />
  27. <Settings v-if="defaultSettings.showSettings" />
  28. </div>
  29. </div>
  30. <!-- 左侧和顶部布局 -->
  31. <div v-else :class="{ hasTagsView: showTagsView }" class="main-container">
  32. <div :class="{ 'fixed-header': fixedHeader }">
  33. <NavBar v-if="layout === 'left'" />
  34. <TagsView v-if="showTagsView" />
  35. </div>
  36. <AppMain />
  37. <Settings v-if="defaultSettings.showSettings" />
  38. </div>
  39. </div>
  40. </template>
  41. <script setup lang="ts">
  42. import { useAppStore, useSettingsStore, usePermissionStore } from "@/store";
  43. import defaultSettings from "@/settings";
  44. import { DeviceEnum } from "@/enums/DeviceEnum";
  45. const appStore = useAppStore();
  46. const settingsStore = useSettingsStore();
  47. const permissionStore = usePermissionStore();
  48. const fixedHeader = computed(() => settingsStore.fixedHeader); // 是否固定header
  49. const showTagsView = computed(() => settingsStore.tagsView); // 是否显示tagsView
  50. const layout = computed(() => settingsStore.layout); // 布局模式 left top mix
  51. const activeTopMenuPath = computed(() => appStore.activeTopMenuPath); // 顶部菜单激活path
  52. const mixLeftMenus = computed(() => permissionStore.mixLeftMenus); // 混合布局左侧菜单
  53. watch(
  54. () => activeTopMenuPath.value,
  55. (newVal) => {
  56. permissionStore.setMixLeftMenus(newVal);
  57. },
  58. {
  59. deep: true,
  60. immediate: true,
  61. }
  62. );
  63. const classObj = computed(() => ({
  64. hideSidebar: !appStore.sidebar.opened,
  65. openSidebar: appStore.sidebar.opened,
  66. mobile: appStore.device === DeviceEnum.MOBILE,
  67. "layout-left": layout.value === "left",
  68. "layout-top": layout.value === "top",
  69. "layout-mix": layout.value === "mix",
  70. }));
  71. const width = useWindowSize().width;
  72. const WIDTH = 992; // 响应式布局容器固定宽度 大屏(>=1200px) 中屏(>=992px) 小屏(>=768px)
  73. watchEffect(() => {
  74. if (width.value < WIDTH) {
  75. appStore.toggleDevice(DeviceEnum.MOBILE);
  76. appStore.closeSideBar();
  77. } else {
  78. appStore.toggleDevice(DeviceEnum.DESKTOP);
  79. if (width.value >= 1200) {
  80. appStore.openSideBar();
  81. } else {
  82. appStore.closeSideBar();
  83. }
  84. }
  85. });
  86. function handleOutsideClick() {
  87. appStore.closeSideBar();
  88. }
  89. function toggleSidebar() {
  90. appStore.toggleSidebar();
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .fixed-header {
  95. position: fixed;
  96. top: 0;
  97. right: 0;
  98. z-index: 9;
  99. width: calc(100% - $sidebar-width);
  100. transition: width 0.28s;
  101. }
  102. .sidebar-container {
  103. position: fixed;
  104. top: 0;
  105. bottom: 0;
  106. left: 0;
  107. z-index: 999;
  108. width: $sidebar-width;
  109. height: 100%;
  110. overflow: hidden;
  111. background-color: $menu-background;
  112. transition: width 0.28s;
  113. :deep(.el-menu) {
  114. border: none;
  115. }
  116. }
  117. .main-container {
  118. position: relative;
  119. min-height: 100%;
  120. margin-left: $sidebar-width;
  121. transition: margin-left 0.28s;
  122. }
  123. .layout-top {
  124. .fixed-header {
  125. top: $navbar-height;
  126. width: 100%;
  127. }
  128. .sidebar-container {
  129. z-index: 999;
  130. display: flex;
  131. width: 100% !important;
  132. height: $navbar-height;
  133. :deep(.el-scrollbar) {
  134. flex: 1;
  135. height: $navbar-height;
  136. }
  137. :deep(.el-menu-item),
  138. :deep(.el-sub-menu__title),
  139. :deep(.el-menu--horizontal) {
  140. height: $navbar-height;
  141. line-height: $navbar-height;
  142. }
  143. :deep(.el-menu--collapse) {
  144. width: 100%;
  145. }
  146. }
  147. .main-container {
  148. min-height: calc(100vh - $navbar-height);
  149. padding-top: $navbar-height;
  150. margin-left: 0;
  151. }
  152. }
  153. .layout-mix {
  154. .sidebar-container {
  155. width: 100% !important;
  156. height: $navbar-height;
  157. :deep(.el-scrollbar) {
  158. flex: 1;
  159. height: $navbar-height;
  160. }
  161. :deep(.el-menu-item),
  162. :deep(.el-sub-menu__title),
  163. :deep(.el-menu--horizontal) {
  164. height: $navbar-height;
  165. line-height: $navbar-height;
  166. }
  167. :deep(.el-menu--horizontal.el-menu) {
  168. border: none;
  169. }
  170. }
  171. .mix-container {
  172. display: flex;
  173. height: 100%;
  174. padding-top: $navbar-height;
  175. .mix-container__left {
  176. position: relative;
  177. width: $sidebar-width;
  178. height: 100%;
  179. :deep(.el-menu) {
  180. height: 100%;
  181. border: none;
  182. }
  183. .sidebar-toggle {
  184. position: absolute;
  185. bottom: 0;
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. width: 100%;
  190. height: 50px;
  191. line-height: 50px;
  192. box-shadow: 0 0 6px -2px var(--el-color-primary);
  193. div:hover {
  194. background-color: var(--menu-background);
  195. }
  196. :deep(svg) {
  197. color: var(--el-color-primary) !important;
  198. }
  199. }
  200. }
  201. .main-container {
  202. flex: 1;
  203. min-width: 0;
  204. margin-left: 0;
  205. .fixed-header {
  206. top: $navbar-height;
  207. }
  208. }
  209. }
  210. }
  211. .hideSidebar {
  212. .fixed-header {
  213. left: $sidebar-width-collapsed;
  214. width: calc(100% - $sidebar-width-collapsed);
  215. }
  216. .main-container {
  217. margin-left: $sidebar-width-collapsed;
  218. }
  219. &.layout-top {
  220. .fixed-header {
  221. left: 0;
  222. width: 100%;
  223. }
  224. .main-container {
  225. margin-left: 0;
  226. }
  227. }
  228. &.layout-mix {
  229. .fixed-header {
  230. left: $sidebar-width-collapsed;
  231. width: calc(100% - $sidebar-width-collapsed);
  232. }
  233. .sidebar-container {
  234. width: 100% !important;
  235. }
  236. .mix-container {
  237. .mix-container__left {
  238. width: $sidebar-width-collapsed;
  239. }
  240. }
  241. }
  242. }
  243. .layout-left.hideSidebar {
  244. .sidebar-container {
  245. width: $sidebar-width-collapsed !important;
  246. }
  247. .main-container {
  248. margin-left: $sidebar-width-collapsed;
  249. }
  250. &.mobile {
  251. .sidebar-container {
  252. pointer-events: none;
  253. transition-duration: 0.3s;
  254. transform: translate3d(-210px, 0, 0);
  255. }
  256. .main-container {
  257. margin-left: 0;
  258. }
  259. }
  260. }
  261. .mobile {
  262. .fixed-header {
  263. left: 0;
  264. width: 100%;
  265. }
  266. .main-container {
  267. margin-left: 0;
  268. }
  269. &.layout-top {
  270. .sidebar-container {
  271. z-index: 999;
  272. display: flex;
  273. width: 100% !important;
  274. height: $navbar-height;
  275. :deep(.el-scrollbar) {
  276. flex: 1;
  277. min-width: 0;
  278. height: $navbar-height;
  279. }
  280. }
  281. .main-container {
  282. padding-top: $navbar-height;
  283. margin-left: 0;
  284. overflow: hidden;
  285. }
  286. // 顶部模式全局变量修改
  287. --el-menu-item-height: $navbar-height;
  288. }
  289. }
  290. </style>