Files
vue3-element-admin/src/store/modules/app.ts
2021-12-26 13:19:08 +08:00

39 lines
1.1 KiB
TypeScript

import {AppState} from "@store/interface";
import {Local} from "@utils/storage";
import { store } from "@/store";
import { defineStore } from "pinia";
export const useAppStore = defineStore({
id: "app",
state: ():AppState=>({
device: 'desktop',
sidebar: {
opened: Local.get('sidebarStatus') ? !!+Local.get('sidebarStatus') : true,
withoutAnimation: false
}
}),
actions: {
toggleSidebar() {
this.sidebar.opened = !this.sidebar.opened
this.sidebar.withoutAnimation = false
if (this.sidebar.opened) {
Local.set('sidebarStatus', 1)
} else {
Local.set('sidebarStatus', 0)
}
},
closeSideBar ( withoutAnimation:any) {
Local.set('sidebarStatus', 0)
this.sidebar.opened = false
this.sidebar.withoutAnimation = withoutAnimation
},
toggleDevice( device:any) {
console.log('TOGGLE_DEVICE',device)
this.device = device
}
}
})
export function useAppStoreHook() {
return useAppStore(store);
}