You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.9 KiB

  1. import { computed } from "vue";
  2. import { useI18n } from "vue-i18n";
  3. import { routerArrays } from "../types";
  4. import { useGlobal } from "@pureadmin/utils";
  5. import { useMultiTagsStore } from "@/store/modules/multiTags";
  6. export function useLayout() {
  7. const { $storage, $config } = useGlobal<GlobalPropertiesApi>();
  8. const initStorage = () => {
  9. /** 路由 */
  10. if (
  11. useMultiTagsStore().multiTagsCache &&
  12. (!$storage.tags || $storage.tags.length === 0)
  13. ) {
  14. $storage.tags = routerArrays;
  15. }
  16. /** 国际化 */
  17. if (!$storage.locale) {
  18. $storage.locale = { locale: $config?.Locale ?? "zh" };
  19. useI18n().locale.value = $config?.Locale ?? "zh";
  20. }
  21. /** 导航 */
  22. if (!$storage.layout) {
  23. $storage.layout = {
  24. layout: $config?.Layout ?? "vertical",
  25. theme: $config?.Theme ?? "light",
  26. darkMode: $config?.DarkMode ?? false,
  27. sidebarStatus: $config?.SidebarStatus ?? true,
  28. epThemeColor: $config?.EpThemeColor ?? "#409EFF",
  29. themeColor: $config?.Theme ?? "light",
  30. overallStyle: $config?.OverallStyle ?? "light"
  31. };
  32. }
  33. /** 灰色模式、色弱模式、隐藏标签页 */
  34. if (!$storage.configure) {
  35. $storage.configure = {
  36. grey: $config?.Grey ?? false,
  37. weak: $config?.Weak ?? false,
  38. hideTabs: $config?.HideTabs ?? false,
  39. hideFooter: $config.HideFooter ?? true,
  40. showLogo: $config?.ShowLogo ?? true,
  41. showModel: $config?.ShowModel ?? "smart",
  42. multiTagsCache: $config?.MultiTagsCache ?? false,
  43. stretch: $config?.Stretch ?? false
  44. };
  45. }
  46. };
  47. /** 清空缓存后从platform-config.json读取默认配置并赋值到storage中 */
  48. const layout = computed(() => {
  49. return $storage?.layout.layout;
  50. });
  51. const layoutTheme = computed(() => {
  52. return $storage.layout;
  53. });
  54. return {
  55. layout,
  56. layoutTheme,
  57. initStorage
  58. };
  59. }