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
72 lines
1.7 KiB
import { storageLocal } from "/@/utils/storage";
|
|
import { deviceDetection } from "/@/utils/deviceDetection";
|
|
import { defineStore } from "pinia";
|
|
import { store } from "/@/store";
|
|
|
|
interface AppState {
|
|
sidebar: {
|
|
opened: boolean;
|
|
withoutAnimation: boolean;
|
|
};
|
|
layout: string;
|
|
device: string;
|
|
}
|
|
|
|
export const useAppStore = defineStore({
|
|
id: "pure-app",
|
|
state: (): AppState => ({
|
|
sidebar: {
|
|
opened: storageLocal.getItem("sidebarStatus")
|
|
? !!+storageLocal.getItem("sidebarStatus")
|
|
: true,
|
|
withoutAnimation: false
|
|
},
|
|
layout:
|
|
storageLocal.getItem("responsive-layout")?.layout.match(/(.*)-/)[1] ??
|
|
"vertical",
|
|
device: deviceDetection() ? "mobile" : "desktop"
|
|
}),
|
|
getters: {
|
|
getSidebarStatus() {
|
|
return this.sidebar.opened;
|
|
},
|
|
getDevice() {
|
|
return this.device;
|
|
}
|
|
},
|
|
actions: {
|
|
TOGGLE_SIDEBAR() {
|
|
this.sidebar.opened = !this.sidebar.opened;
|
|
this.sidebar.withoutAnimation = false;
|
|
if (this.sidebar.opened) {
|
|
storageLocal.setItem("sidebarStatus", 1);
|
|
} else {
|
|
storageLocal.setItem("sidebarStatus", 0);
|
|
}
|
|
},
|
|
CLOSE_SIDEBAR(withoutAnimation: boolean) {
|
|
storageLocal.setItem("sidebarStatus", 0);
|
|
this.sidebar.opened = false;
|
|
this.sidebar.withoutAnimation = withoutAnimation;
|
|
},
|
|
TOGGLE_DEVICE(device: string) {
|
|
this.device = device;
|
|
},
|
|
async toggleSideBar() {
|
|
await this.TOGGLE_SIDEBAR();
|
|
},
|
|
closeSideBar(withoutAnimation) {
|
|
this.CLOSE_SIDEBAR(withoutAnimation);
|
|
},
|
|
toggleDevice(device) {
|
|
this.TOGGLE_DEVICE(device);
|
|
},
|
|
setLayout(layout) {
|
|
this.layout = layout;
|
|
}
|
|
}
|
|
});
|
|
|
|
export function useAppStoreHook() {
|
|
return useAppStore(store);
|
|
}
|