gohttpdUi/src/store/modules/app.ts

138 lines
3.3 KiB
TypeScript
Raw Normal View History

import { defineStore } from 'pinia'
import { store } from '../index'
2022-01-05 17:02:25 +08:00
import { useCache } from '@/hooks/web/useCache'
import { appModules } from '@/config/app'
import type { AppState, LayoutType } from '@/config/app'
2022-01-05 17:02:25 +08:00
const { wsCache } = useCache()
export const useAppStore = defineStore({
id: 'app',
2022-01-05 17:02:25 +08:00
state: (): AppState => appModules,
getters: {
2022-01-12 16:44:57 +08:00
getCollapse(): boolean {
return this.collapse
},
getShowLogo(): boolean {
return this.showLogo
},
getShowTags(): boolean {
return this.showTags
},
getShowNavbar(): boolean {
return this.showNavbar
},
getFixedHeader(): boolean {
return this.fixedHeader
},
getLayout(): LayoutType {
return this.layout
},
getShowBreadcrumb(): boolean {
return this.showBreadcrumb
},
getShowHamburger(): boolean {
return this.showHamburger
},
getShowScreenfull(): boolean {
return this.showScreenfull
},
getShowUserInfo(): boolean {
return this.showUserInfo
},
getTitle(): string {
return this.title
},
getLogoTitle(): string {
return this.logoTitle
},
getUserInfo(): string {
return this.userInfo
},
getGreyMode(): boolean {
return this.greyMode
},
getShowBackTop(): boolean {
return this.showBackTop
},
getShowMenuTab(): boolean {
return this.showMenuTab
},
2021-12-31 17:19:53 +08:00
getIsDark(): boolean {
return this.isDark
},
getSize(): ElememtPlusSzie {
return this.size
2022-01-03 18:01:43 +08:00
},
getSizeMap(): ElememtPlusSzie[] {
return this.sizeMap
}
},
actions: {
2022-01-12 16:44:57 +08:00
setCollapse(collapse: boolean) {
this.collapse = collapse
},
2021-12-11 11:49:39 +08:00
setShowLogo(showLogo: boolean) {
this.showLogo = showLogo
},
2021-12-11 11:49:39 +08:00
setShowTags(showTags: boolean) {
this.showTags = showTags
},
2021-12-11 11:49:39 +08:00
setShowNavbar(showNavbar: boolean) {
this.showNavbar = showNavbar
},
2021-12-11 11:49:39 +08:00
setFixedHeader(fixedHeader: boolean) {
this.fixedHeader = fixedHeader
},
2021-12-11 11:49:39 +08:00
setLayout(layout: LayoutType) {
this.layout = layout
},
2021-12-11 11:49:39 +08:00
setBreadcrumb(showBreadcrumb: boolean) {
this.showBreadcrumb = showBreadcrumb
},
2021-12-11 11:49:39 +08:00
setHamburger(showHamburger: boolean) {
this.showHamburger = showHamburger
},
2021-12-11 11:49:39 +08:00
setScreenfull(showScreenfull: boolean) {
this.showScreenfull = showScreenfull
},
2021-12-11 11:49:39 +08:00
setUserInfo(showUserInfo: boolean) {
this.showUserInfo = showUserInfo
},
2021-12-11 11:49:39 +08:00
setTitle(title: string) {
this.title = title
},
2021-12-11 11:49:39 +08:00
setLogoTitle(logoTitle: string) {
this.logoTitle = logoTitle
},
2021-12-11 11:49:39 +08:00
setGreyMode(greyMode: boolean) {
this.greyMode = greyMode
},
2021-12-11 11:49:39 +08:00
setShowBackTop(showBackTop: boolean) {
this.showBackTop = showBackTop
},
2021-12-11 11:49:39 +08:00
setShowMenuTab(showMenuTab: boolean) {
this.showMenuTab = showMenuTab
},
2021-12-31 17:19:53 +08:00
setIsDark(isDark: boolean) {
this.isDark = isDark
if (this.isDark) {
document.documentElement.classList.add('dark')
document.documentElement.classList.remove('light')
} else {
document.documentElement.classList.add('light')
document.documentElement.classList.remove('dark')
}
2022-01-05 17:02:25 +08:00
wsCache.set('isDark', this.isDark)
2021-12-31 17:19:53 +08:00
},
setSize(size: ElememtPlusSzie) {
this.size = size
2022-01-05 17:02:25 +08:00
wsCache.set('size', this.size)
}
}
})
export function useAppStoreWithOut() {
return useAppStore(store)
}