2022-08-24 16:52:01 +08:00
|
|
|
import { reactive, ref } from "vue"
|
2022-04-22 01:16:02 +08:00
|
|
|
import { defineStore } from "pinia"
|
2022-10-17 15:04:27 +08:00
|
|
|
import { getSidebarStatus, setSidebarStatus } from "@/utils/cache/localStorage"
|
2022-04-21 18:20:39 +08:00
|
|
|
|
2023-05-21 10:47:42 +08:00
|
|
|
export enum DeviceEnum {
|
2022-04-21 18:20:39 +08:00
|
|
|
Mobile,
|
|
|
|
Desktop
|
|
|
|
}
|
|
|
|
|
2023-05-21 09:51:41 +08:00
|
|
|
interface Sidebar {
|
2022-08-24 16:52:01 +08:00
|
|
|
opened: boolean
|
|
|
|
withoutAnimation: boolean
|
2022-04-21 18:20:39 +08:00
|
|
|
}
|
|
|
|
|
2022-08-24 16:52:01 +08:00
|
|
|
export const useAppStore = defineStore("app", () => {
|
2023-05-21 09:51:41 +08:00
|
|
|
const sidebar: Sidebar = reactive({
|
2022-08-24 16:52:01 +08:00
|
|
|
opened: getSidebarStatus() !== "closed",
|
|
|
|
withoutAnimation: false
|
|
|
|
})
|
2023-05-21 10:47:42 +08:00
|
|
|
const device = ref<DeviceEnum>(DeviceEnum.Desktop)
|
2022-08-24 16:52:01 +08:00
|
|
|
|
|
|
|
const toggleSidebar = (withoutAnimation: boolean) => {
|
|
|
|
sidebar.opened = !sidebar.opened
|
|
|
|
sidebar.withoutAnimation = withoutAnimation
|
|
|
|
if (sidebar.opened) {
|
|
|
|
setSidebarStatus("opened")
|
|
|
|
} else {
|
2022-04-22 01:16:02 +08:00
|
|
|
setSidebarStatus("closed")
|
2022-04-21 18:20:39 +08:00
|
|
|
}
|
|
|
|
}
|
2022-08-24 16:52:01 +08:00
|
|
|
const closeSidebar = (withoutAnimation: boolean) => {
|
|
|
|
sidebar.opened = false
|
|
|
|
sidebar.withoutAnimation = withoutAnimation
|
|
|
|
setSidebarStatus("closed")
|
|
|
|
}
|
2023-05-21 10:47:42 +08:00
|
|
|
const toggleDevice = (value: DeviceEnum) => {
|
2022-08-24 16:52:01 +08:00
|
|
|
device.value = value
|
|
|
|
}
|
|
|
|
|
2022-10-17 15:04:27 +08:00
|
|
|
return { device, sidebar, toggleSidebar, closeSidebar, toggleDevice }
|
2022-04-21 18:20:39 +08:00
|
|
|
})
|