Newer
Older
KaiFengPC / src / store / modules / settings.js
@zhangdeliang zhangdeliang on 23 May 1 KB 初始化项目
  1. import defaultSettings from "@/settings";
  2. import { useDynamicTitle } from "@/utils/dynamicTitle";
  3.  
  4. const {
  5. sideTheme,
  6. showSettings,
  7. topNav,
  8. tagsView,
  9. fixedHeader,
  10. sidebarLogo,
  11. dynamicTitle,
  12. } = defaultSettings;
  13.  
  14. const storageSetting = JSON.parse(localStorage.getItem("layout-setting")) || "";
  15.  
  16. const useSettingsStore = defineStore("settings", {
  17. state: () => ({
  18. title: "",
  19. theme: storageSetting.theme || "#409EFF",
  20. sideTheme: storageSetting.sideTheme || sideTheme,
  21. showSettings: showSettings,
  22. topNav:
  23. storageSetting.topNav === undefined ? topNav : storageSetting.topNav,
  24. tagsView:
  25. storageSetting.tagsView === undefined
  26. ? tagsView
  27. : storageSetting.tagsView,
  28. fixedHeader:
  29. storageSetting.fixedHeader === undefined
  30. ? fixedHeader
  31. : storageSetting.fixedHeader,
  32. sidebarLogo:
  33. storageSetting.sidebarLogo === undefined
  34. ? sidebarLogo
  35. : storageSetting.sidebarLogo,
  36. dynamicTitle:
  37. storageSetting.dynamicTitle === undefined
  38. ? dynamicTitle
  39. : storageSetting.dynamicTitle,
  40. }),
  41. actions: {
  42. // 修改布局设置
  43. changeSetting(data) {
  44. const { key, value } = data;
  45. if (this.hasOwnProperty(key)) {
  46. this[key] = value;
  47. }
  48. },
  49. // 设置网页标题
  50. setTitle(title) {
  51. this.title = title;
  52. useDynamicTitle();
  53. },
  54. },
  55. });
  56.  
  57. export default useSettingsStore;