57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
/*
|
|
* @Author: RenXiaoDong
|
|
* @Date: 2025-06-23 03:56:22
|
|
*/
|
|
import { defineStore } from 'pinia';
|
|
import type { AppState, RouteRecordNormalized } 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.menuFromServer = true;
|
|
},
|
|
clearServerMenu() {
|
|
this.serverMenu = [];
|
|
},
|
|
},
|
|
});
|