index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <script setup lang="ts">
  2. import "animate.css";
  3. // 引入 src/components/ReIcon/src/offlineIcon.ts 文件中所有使用addIcon添加过的本地图标
  4. import "@/components/ReIcon/src/offlineIcon";
  5. import { setType } from "./types";
  6. import { useLayout } from "./hooks/useLayout";
  7. import { useAppStoreHook } from "@/store/modules/app";
  8. import { useSettingStoreHook } from "@/store/modules/settings";
  9. import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange";
  10. import {
  11. h,
  12. ref,
  13. reactive,
  14. computed,
  15. onMounted,
  16. onBeforeMount,
  17. defineComponent
  18. } from "vue";
  19. import {
  20. useDark,
  21. useGlobal,
  22. deviceDetection,
  23. useResizeObserver
  24. } from "@pureadmin/utils";
  25. import navbar from "./components/navbar.vue";
  26. import tag from "./components/tag/index.vue";
  27. import appMain from "./components/appMain.vue";
  28. import setting from "./components/setting/index.vue";
  29. import Vertical from "./components/sidebar/vertical.vue";
  30. import Horizontal from "./components/sidebar/horizontal.vue";
  31. import backTop from "@/assets/svg/back_top.svg?component";
  32. const appWrapperRef = ref();
  33. const { isDark } = useDark();
  34. const { layout } = useLayout();
  35. const isMobile = deviceDetection();
  36. const pureSetting = useSettingStoreHook();
  37. const { $storage } = useGlobal<GlobalPropertiesApi>();
  38. const set: setType = reactive({
  39. sidebar: computed(() => {
  40. return useAppStoreHook().sidebar;
  41. }),
  42. device: computed(() => {
  43. return useAppStoreHook().device;
  44. }),
  45. fixedHeader: computed(() => {
  46. return pureSetting.fixedHeader;
  47. }),
  48. classes: computed(() => {
  49. return {
  50. hideSidebar: !set.sidebar.opened,
  51. openSidebar: set.sidebar.opened,
  52. withoutAnimation: set.sidebar.withoutAnimation,
  53. mobile: set.device === "mobile"
  54. };
  55. }),
  56. hideTabs: computed(() => {
  57. return $storage?.configure.hideTabs;
  58. })
  59. });
  60. function setTheme(layoutModel: string) {
  61. window.document.body.setAttribute("layout", layoutModel);
  62. $storage.layout = {
  63. layout: `${layoutModel}`,
  64. theme: $storage.layout?.theme,
  65. darkMode: $storage.layout?.darkMode,
  66. sidebarStatus: $storage.layout?.sidebarStatus,
  67. epThemeColor: $storage.layout?.epThemeColor,
  68. themeColor: $storage.layout?.themeColor,
  69. overallStyle: $storage.layout?.overallStyle
  70. };
  71. }
  72. function toggle(device: string, bool: boolean) {
  73. useAppStoreHook().toggleDevice(device);
  74. useAppStoreHook().toggleSideBar(bool, "resize");
  75. }
  76. // 判断是否可自动关闭菜单栏
  77. let isAutoCloseSidebar = true;
  78. useResizeObserver(appWrapperRef, entries => {
  79. if (isMobile) return;
  80. const entry = entries[0];
  81. const [{ inlineSize: width, blockSize: height }] = entry.borderBoxSize;
  82. useAppStoreHook().setViewportSize({ width, height });
  83. width <= 760 ? setTheme("vertical") : setTheme(useAppStoreHook().layout);
  84. /** width app-wrapper类容器宽度
  85. * 0 < width <= 760 隐藏侧边栏
  86. * 760 < width <= 990 折叠侧边栏
  87. * width > 990 展开侧边栏
  88. */
  89. if (width > 0 && width <= 760) {
  90. toggle("mobile", false);
  91. isAutoCloseSidebar = true;
  92. } else if (width > 760 && width <= 990) {
  93. if (isAutoCloseSidebar) {
  94. toggle("desktop", false);
  95. isAutoCloseSidebar = false;
  96. }
  97. } else if (width > 990 && !set.sidebar.isClickCollapse) {
  98. toggle("desktop", true);
  99. isAutoCloseSidebar = true;
  100. } else {
  101. toggle("desktop", false);
  102. isAutoCloseSidebar = false;
  103. }
  104. });
  105. onMounted(() => {
  106. if (isMobile) {
  107. toggle("mobile", false);
  108. }
  109. });
  110. onBeforeMount(() => {
  111. useDataThemeChange().dataThemeChange($storage.layout?.overallStyle);
  112. });
  113. const layoutHeader = defineComponent({
  114. render() {
  115. return h(
  116. "div",
  117. {
  118. class: { "fixed-header": set.fixedHeader },
  119. style: [
  120. set.hideTabs && layout.value.includes("horizontal")
  121. ? isDark.value
  122. ? "box-shadow: 0 1px 4px #0d0d0d"
  123. : "box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08)"
  124. : ""
  125. ]
  126. },
  127. {
  128. default: () => [
  129. !pureSetting.hiddenSideBar &&
  130. (layout.value.includes("vertical") || layout.value.includes("mix"))
  131. ? h(navbar)
  132. : null,
  133. !pureSetting.hiddenSideBar && layout.value.includes("horizontal")
  134. ? h(Horizontal)
  135. : null,
  136. h(tag)
  137. ]
  138. }
  139. );
  140. }
  141. });
  142. </script>
  143. <template>
  144. <div ref="appWrapperRef" :class="['app-wrapper', set.classes]">
  145. <div class="z-10">
  146. <div
  147. v-show="
  148. set.device === 'mobile' &&
  149. set.sidebar.opened &&
  150. layout.includes('vertical')
  151. "
  152. class="app-mask"
  153. @click="useAppStoreHook().toggleSideBar()"
  154. />
  155. <Vertical
  156. v-show="
  157. !pureSetting.hiddenSideBar &&
  158. (layout.includes('vertical') || layout.includes('mix'))
  159. "
  160. />
  161. <div
  162. :class="[
  163. 'main-container',
  164. pureSetting.hiddenSideBar ? 'main-hidden' : ''
  165. ]"
  166. >
  167. <div v-if="set.fixedHeader">
  168. <layout-header />
  169. <!-- 主体内容 -->
  170. <app-main :fixed-header="set.fixedHeader" />
  171. </div>
  172. <el-scrollbar v-else>
  173. <el-backtop
  174. title="回到顶部"
  175. target=".main-container .el-scrollbar__wrap"
  176. >
  177. <backTop />
  178. </el-backtop>
  179. <layout-header />
  180. <!-- 主体内容 -->
  181. <app-main :fixed-header="set.fixedHeader" />
  182. </el-scrollbar>
  183. </div>
  184. <!-- 系统设置 -->
  185. <setting />
  186. </div>
  187. <div class="projectBG">
  188. <!-- 背景色 -->
  189. </div>
  190. </div>
  191. </template>
  192. <style lang="scss" scoped>
  193. .app-wrapper {
  194. position: relative;
  195. width: 100%;
  196. height: 100%;
  197. &::after {
  198. display: table;
  199. clear: both;
  200. content: "";
  201. }
  202. &.mobile.openSidebar {
  203. position: fixed;
  204. top: 0;
  205. }
  206. }
  207. .app-mask {
  208. position: absolute;
  209. top: 0;
  210. z-index: 999;
  211. width: 100%;
  212. height: 100%;
  213. background: #000;
  214. opacity: 0.3;
  215. }
  216. .re-screen {
  217. margin-top: 12px;
  218. }
  219. .projectBG {
  220. position: absolute;
  221. top: 0;
  222. left: 0;
  223. // background: blue;
  224. z-index: -1;
  225. width: 100vw;
  226. height: 100vh;
  227. // background: linear-gradient(to center, blue, white);
  228. background: radial-gradient(circle, white, #d2e6fa);
  229. background: linear-gradient(to right, #d2e6fa, white, #d2e6fa);
  230. }
  231. </style>