2025-10-20 16:53:28 +08:00

66 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineStore } from 'pinia'
import storage from '@/utils/storage'
import useRouterStore from './router'
import { config } from '@/config'
import { useRoute, useRouter } from 'vue-router'
const defaultConfig = {
layout: 'leftRight', // 页面布局【topBottom=上下布局leftRight=左右布局】
menuMode: 'side', // 菜单模式【side=侧边菜单top=顶部菜单mix=混合菜单】
sideCollapsedWidth: 60,
sideWidth: 220,
headerHeight: 60,
sideTheme: 'dark', // 侧边菜单主题【dark=暗色light=亮色】
headerTheme: 'light', // 侧边菜单主题【dark=暗色light=亮色】
multiTab: true,
multiTabHeight: 48,
mainMargin: 16,
}
const useAppStore = defineStore('app', {
name: 'useAppStore',
state: () => ({
complete: false,
config: storage.session.getItem(config('storage.config'), defaultConfig),
}),
getters: {
mainOffsetTop: (state) => {
const multiTabHeight = state.config?.multiTab ? `${state.config.multiTabHeight}px` : '0px'
return `calc(${state.config.headerHeight}px + ${multiTabHeight} + ${state.config.mainMargin}px)`
},
mainHeight: (state) => {
const multiTabHeight = state.config?.multiTab ? `${state.config.multiTabHeight}px` : '0px'
return `calc(100vh - ${state.config.headerHeight}px - ${multiTabHeight} - ${state.config.mainMargin * 2}px)`
},
},
actions: {
/**
* 初始化
* @returns {Promise}
*/
init() {
const platform=storage.local.getItem('platform')
if(!platform){
const router = useRouter()
return router.replace({path:'/platForm'})
}
const routerStore = useRouterStore()
return new Promise((resolve) => {
Promise.all([routerStore.getRouterList({platform:platform})])
.then(() => {
this.complete = true
resolve()
})
.catch(() => {})
})
},
/**
* 更新 config
*/
updateConfig() {
storage.session.setItem(config('storage.config'), this.config)
},
},
})
export default useAppStore