index.vue 7.6 KB

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