Files
lingji-work-fe/src/stores/modules/app/index.ts

103 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-06-20 06:10:15 -04:00
import { defineStore } from 'pinia';
2025-06-16 14:42:26 +08:00
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<AppState>) {
// @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 = [];
},
},
});