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.

72 lines
1.7 KiB

  1. import { storageLocal } from "/@/utils/storage";
  2. import { deviceDetection } from "/@/utils/deviceDetection";
  3. import { defineStore } from "pinia";
  4. import { store } from "/@/store";
  5. interface AppState {
  6. sidebar: {
  7. opened: boolean;
  8. withoutAnimation: boolean;
  9. };
  10. layout: string;
  11. device: string;
  12. }
  13. export const useAppStore = defineStore({
  14. id: "pure-app",
  15. state: (): AppState => ({
  16. sidebar: {
  17. opened: storageLocal.getItem("sidebarStatus")
  18. ? !!+storageLocal.getItem("sidebarStatus")
  19. : true,
  20. withoutAnimation: false
  21. },
  22. layout:
  23. storageLocal.getItem("responsive-layout")?.layout.match(/(.*)-/)[1] ??
  24. "vertical",
  25. device: deviceDetection() ? "mobile" : "desktop"
  26. }),
  27. getters: {
  28. getSidebarStatus() {
  29. return this.sidebar.opened;
  30. },
  31. getDevice() {
  32. return this.device;
  33. }
  34. },
  35. actions: {
  36. TOGGLE_SIDEBAR() {
  37. this.sidebar.opened = !this.sidebar.opened;
  38. this.sidebar.withoutAnimation = false;
  39. if (this.sidebar.opened) {
  40. storageLocal.setItem("sidebarStatus", 1);
  41. } else {
  42. storageLocal.setItem("sidebarStatus", 0);
  43. }
  44. },
  45. CLOSE_SIDEBAR(withoutAnimation: boolean) {
  46. storageLocal.setItem("sidebarStatus", 0);
  47. this.sidebar.opened = false;
  48. this.sidebar.withoutAnimation = withoutAnimation;
  49. },
  50. TOGGLE_DEVICE(device: string) {
  51. this.device = device;
  52. },
  53. async toggleSideBar() {
  54. await this.TOGGLE_SIDEBAR();
  55. },
  56. closeSideBar(withoutAnimation) {
  57. this.CLOSE_SIDEBAR(withoutAnimation);
  58. },
  59. toggleDevice(device) {
  60. this.TOGGLE_DEVICE(device);
  61. },
  62. setLayout(layout) {
  63. this.layout = layout;
  64. }
  65. }
  66. });
  67. export function useAppStoreHook() {
  68. return useAppStore(store);
  69. }