first commit
This commit is contained in:
101
src/stores/modules/app/index.ts
Normal file
101
src/stores/modules/app/index.ts
Normal file
@ -0,0 +1,101 @@
|
||||
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 = [];
|
||||
},
|
||||
},
|
||||
});
|
||||
24
src/stores/modules/app/types.ts
Normal file
24
src/stores/modules/app/types.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import type { RouteRecordNormalized } from 'vue-router';
|
||||
import type { NotificationReturn } from '@arco-design/web-vue/es/notification/interface';
|
||||
import type { AppRouteRecordRaw } from '@/router/routes/types';
|
||||
|
||||
export { RouteRecordNormalized, NotificationReturn };
|
||||
|
||||
export interface AppState {
|
||||
theme: string;
|
||||
colorWeak: boolean;
|
||||
navbar: boolean;
|
||||
menu: boolean;
|
||||
topMenu: boolean;
|
||||
hideMenu: boolean;
|
||||
menuCollapse: boolean;
|
||||
footer: boolean;
|
||||
themeColor: string;
|
||||
menuWidth: number;
|
||||
globalSettings: boolean;
|
||||
device: string;
|
||||
tabBar: boolean;
|
||||
menuFromServer: boolean;
|
||||
serverMenu: AppRouteRecordRaw[];
|
||||
[key: string]: unknown;
|
||||
}
|
||||
Reference in New Issue
Block a user