123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- import { defineStore } from 'pinia'
- import { store } from '../index'
- import { useCache } from '@/hooks/web/useCache'
- import { appModules } from '@/config/app'
- import type { AppState, LayoutType } from '@/config/app'
- import { setCssVar, humpToUnderline } from '@/utils'
- import { ElMessage } from 'element-plus'
- const { wsCache } = useCache()
- export const useAppStore = defineStore({
- id: 'app',
- state: (): AppState => appModules,
- getters: {
- getBreadcrumb(): boolean {
- return this.breadcrumb
- },
- getBreadcrumbIcon(): boolean {
- return this.breadcrumbIcon
- },
- getCollapse(): boolean {
- return this.collapse
- },
- getHamburger(): boolean {
- return this.hamburger
- },
- getScreenfull(): boolean {
- return this.screenfull
- },
- getSize(): boolean {
- return this.size
- },
- getLocale(): boolean {
- return this.locale
- },
- getTagsView(): boolean {
- return this.tagsView
- },
- getLogo(): boolean {
- return this.logo
- },
- getFixedHeader(): boolean {
- return this.fixedHeader
- },
- getFixedMenu(): boolean {
- return this.fixedMenu
- },
- getGreyMode(): boolean {
- return this.greyMode
- },
- getLayout(): LayoutType {
- return this.layout
- },
- getTitle(): string {
- return this.title
- },
- getUserInfo(): string {
- return this.userInfo
- },
- getIsDark(): boolean {
- return this.isDark
- },
- getCurrentSize(): ElememtPlusSzie {
- return this.currentSize
- },
- getSizeMap(): ElememtPlusSzie[] {
- return this.sizeMap
- },
- getMobile(): boolean {
- return this.mobile
- },
- getTheme(): Recordable {
- return this.theme
- }
- },
- actions: {
- setBreadcrumb(breadcrumb: boolean) {
- this.breadcrumb = breadcrumb
- },
- setBreadcrumbIcon(breadcrumbIcon: boolean) {
- this.breadcrumbIcon = breadcrumbIcon
- },
- setCollapse(collapse: boolean) {
- this.collapse = collapse
- },
- setHamburger(hamburger: boolean) {
- this.hamburger = hamburger
- },
- setScreenfull(screenfull: boolean) {
- this.screenfull = screenfull
- },
- setSize(size: boolean) {
- this.size = size
- },
- setLocale(locale: boolean) {
- this.locale = locale
- },
- setTagsView(tagsView: boolean) {
- this.tagsView = tagsView
- },
- setLogo(logo: boolean) {
- this.logo = logo
- },
- setFixedHeader(fixedHeader: boolean) {
- this.fixedHeader = fixedHeader
- },
- setFixedMenu(fixedMenu: boolean) {
- this.fixedMenu = fixedMenu
- },
- setGreyMode(greyMode: boolean) {
- this.greyMode = greyMode
- },
- setLayout(layout: LayoutType) {
- if (this.mobile && layout !== 'classic') {
- ElMessage.warning('移动端模式下不支持切换其他布局')
- return
- }
- this.layout = layout
- wsCache.set('layout', this.layout)
- },
- setTitle(title: string) {
- this.title = title
- },
- 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')
- }
- wsCache.set('isDark', this.isDark)
- },
- setCurrentSize(currentSize: ElememtPlusSzie) {
- this.currentSize = currentSize
- wsCache.set('currentSize', this.currentSize)
- },
- setMobile(mobile: boolean) {
- this.mobile = mobile
- },
- setTheme(theme: Recordable) {
- this.theme = Object.assign(this.theme, theme)
- wsCache.set('theme', this.theme)
- },
- setCssVarTheme() {
- for (const key in this.theme) {
- setCssVar(`--${humpToUnderline(key)}`, this.theme[key])
- }
- }
- }
- })
- export const useAppStoreWithOut = () => {
- return useAppStore(store)
- }
|