2026-03-16 14:21:04 +08:00

47 lines
1.1 KiB
TypeScript

import { defineStore } from 'pinia'
import Cookies from 'js-cookie'
import { getLanguage } from '@/lang'
interface AppState {
sidebar: {
opened: boolean
withoutAnimation: boolean
}
device: string
language: string
}
export const useAppStore = defineStore('app', {
state: (): AppState => ({
sidebar: {
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus')! : true,
withoutAnimation: false
},
device: 'desktop',
language: getLanguage()
}),
actions: {
toggleSideBar() {
this.sidebar.opened = !this.sidebar.opened
this.sidebar.withoutAnimation = false
if (this.sidebar.opened) {
Cookies.set('sidebarStatus', '1')
} else {
Cookies.set('sidebarStatus', '0')
}
},
closeSideBar(withoutAnimation: boolean) {
Cookies.set('sidebarStatus', '0')
this.sidebar.opened = false
this.sidebar.withoutAnimation = withoutAnimation
},
toggleDevice(device: string) {
this.device = device
},
setLanguage(language: string) {
this.language = language
Cookies.set('language', language)
}
}
})