import type { AppState, RouteRecordNormalized, NotificationReturn } from './types'; import defaultSettings from '@/config/settings.json'; import type { AppRouteRecordRaw } from '@/router/routes/types'; export const useAppStore = defineStore('app', { state: (): AppState => ({ ...defaultSettings }), getters: { appCurrentSetting(state: AppState): AppState { return { ...state }; }, appDevice(state: AppState) { return state.device; }, appAsyncMenus(state: AppState): AppRouteRecordRaw[] { return state.serverMenu as unknown as AppRouteRecordRaw[]; }, }, actions: { // Update app settings updateSettings(partial: Partial) { // @ts-ignore-next-line this.$patch(partial); }, // Change theme color toggleTheme(dark: boolean) { if (dark) { this.theme = 'dark'; document.body.setAttribute('arco-theme', 'dark'); } else { this.theme = 'light'; document.body.removeAttribute('arco-theme'); } }, toggleDevice(device: string) { this.device = device; }, toggleMenu(value: boolean) { this.hideMenu = value; }, async fetchServerMenuConfig() { this.serverMenu = [ { path: '/enterprise', name: 'enterprise', meta: { locale: '企业票夹', requiresAuth: true, roles: ['*'], }, children: [ { path: 'input', name: 'input', meta: { icon: IconImport, locale: '进项管理', requiresAuth: true, roles: ['*'], }, }, { path: 'output', name: 'output', meta: { locale: '销项管理', requiresAuth: true, roles: ['*'], }, }, { path: 'red-invoice', name: 'red-invoice', meta: { locale: '全电红字确认单管理', requiresAuth: true, roles: ['*'], }, }, { path: 'information', name: 'information', meta: { locale: '企业信息', requiresAuth: true, roles: ['*'], }, }, ], }, ]; this.menuFromServer = true; }, clearServerMenu() { this.serverMenu = []; }, }, });