ruoyi-plus-soybean/src/store/modules/app/index.ts

54 lines
1.2 KiB
TypeScript
Raw Normal View History

import { defineStore } from 'pinia';
2021-08-18 12:02:59 +08:00
import type { GlobalThemeOverrides } from 'naive-ui';
import { store } from '../../index';
2021-08-18 12:02:59 +08:00
import { themeSettings } from '@/settings';
import type { ThemeSettings } from '@/interface';
import { brightenColor } from '@/utils';
interface AppState {
2021-08-18 12:02:59 +08:00
/** 主题配置 */
themeSettings: ThemeSettings;
/** 侧边栏折叠 */
asideCollapse: boolean;
}
const appStore = defineStore({
id: 'app-store',
state: (): AppState => ({
2021-08-18 12:02:59 +08:00
themeSettings,
asideCollapse: false
}),
2021-08-18 12:02:59 +08:00
getters: {
/** naive UI主题配置 */
themeOverrids(): GlobalThemeOverrides {
const primaryColor = this.themeSettings.themeColor;
const primaryColorHover = brightenColor(primaryColor);
const primaryColorPressed = primaryColorHover;
const colorLoading = primaryColor;
return {
common: {
primaryColor,
primaryColorHover,
primaryColorPressed
},
LoadingBar: {
colorLoading
}
};
}
},
actions: {
handleAsideCollapse(collapse: boolean) {
this.asideCollapse = collapse;
},
toggleAside() {
this.asideCollapse = !this.asideCollapse;
}
}
});
export default function useAppStore() {
return appStore(store);
}