42 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-08-24 16:52:01 +08:00
import { reactive, ref } from "vue"
import { defineStore } from "pinia"
import { getSidebarStatus, setSidebarStatus } from "@/utils/cache/localStorage"
export enum DeviceType {
Mobile,
Desktop
}
2022-08-24 16:52:01 +08:00
interface ISidebar {
opened: boolean
withoutAnimation: boolean
}
2022-08-24 16:52:01 +08:00
export const useAppStore = defineStore("app", () => {
const sidebar: ISidebar = reactive({
opened: getSidebarStatus() !== "closed",
withoutAnimation: false
})
const device = ref<DeviceType>(DeviceType.Desktop)
const toggleSidebar = (withoutAnimation: boolean) => {
sidebar.opened = !sidebar.opened
sidebar.withoutAnimation = withoutAnimation
if (sidebar.opened) {
setSidebarStatus("opened")
} else {
setSidebarStatus("closed")
}
}
2022-08-24 16:52:01 +08:00
const closeSidebar = (withoutAnimation: boolean) => {
sidebar.opened = false
sidebar.withoutAnimation = withoutAnimation
setSidebarStatus("closed")
}
const toggleDevice = (value: DeviceType) => {
device.value = value
}
return { device, sidebar, toggleSidebar, closeSidebar, toggleDevice }
})