refactor(projects): 精简版+动态路由权限初步

This commit is contained in:
Soybean
2022-01-03 22:20:10 +08:00
parent 7a0648dba5
commit de2057f141
354 changed files with 2053 additions and 22117 deletions

View File

@ -1,39 +0,0 @@
import { brightenColor, darkenColor, addColorAlpha } from '@/utils';
type ColorType = 'primary' | 'info' | 'success' | 'warning' | 'error';
type ColorScene = '' | 'Suppl' | 'Hover' | 'Pressed' | 'Active';
type ColorKey = `${ColorType}Color${ColorScene}`;
type ThemeColor = {
[key in ColorKey]?: string;
};
interface ColorAction {
scene: ColorScene;
handler: (color: string) => string;
}
/** 获取主题颜色的各种场景对应的颜色 */
export function getThemeColors(colors: [ColorType, string][]) {
const colorActions: ColorAction[] = [
{ scene: '', handler: color => color },
{ scene: 'Suppl', handler: color => color },
{ scene: 'Hover', handler: color => brightenColor(color) },
{ scene: 'Pressed', handler: color => darkenColor(color) },
{ scene: 'Active', handler: color => addColorAlpha(color, 0.1) }
];
const themeColor: ThemeColor = {};
colors.forEach(color => {
colorActions.forEach(action => {
const [colorType, colorValue] = color;
const colorKey: ColorKey = `${colorType}Color${action.scene}`;
themeColor[colorKey] = action.handler(colorValue);
});
});
return themeColor;
}

View File

@ -1,138 +1,7 @@
import { defineStore } from 'pinia';
import type { GlobalThemeOverrides } from 'naive-ui';
import { themeSettings, defaultThemeSettings } from '@/settings';
import { store } from '@/store';
import type { ThemeSettings, NavMode, MultiTabMode, AnimateType, HorizontalMenuPosition } from '@/interface';
import { getThemeColors } from './helpers';
type ThemeState = ThemeSettings;
// interface ThemeStore {
// primary: string;
// }
const themeStore = defineStore({
id: 'theme-store',
state: (): ThemeState => ({
...themeSettings
}),
getters: {
/** naive UI主题配置 */
themeOverrids(): GlobalThemeOverrides {
const {
themeColor,
otherColor: { info, success, warning, error }
} = this;
const themeColors = getThemeColors([
['primary', themeColor],
['info', info],
['success', success],
['warning', warning],
['error', error]
]);
const colorLoading = themeColor;
return {
common: {
...themeColors
},
LoadingBar: {
colorLoading
}
};
},
isVerticalNav(): boolean {
const { mode } = this.navStyle;
return mode === 'vertical' || mode === 'vertical-mix';
},
pageAnimateType(): AnimateType | '' {
return this.pageStyle.animate ? this.pageStyle.animateType : '';
}
},
actions: {
/** 设置默认配置 */
setDefaultThemeStore() {
Object.assign(this, defaultThemeSettings);
},
/** 设置暗黑模式 */
handleDarkMode(isDark: boolean) {
this.darkMode = isDark;
},
/** 切换暗黑模式 */
toggleDarkMode() {
this.darkMode = !this.darkMode;
},
/** 设置系统主题颜色 */
setThemeColor(color: string) {
this.themeColor = color;
},
/** 设置导航栏模式 */
setNavMode(mode: NavMode) {
this.navStyle.mode = mode;
},
/** 更改菜单展开的宽度 */
handleMenuWidth(width: number | null) {
if (width !== null) {
this.menuStyle.width = width;
}
},
/** 更改混合菜单展开的宽度 */
handleMixMenuWidth(width: number | null) {
if (width !== null) {
this.menuStyle.mixWidth = width;
}
},
/** 更改顶部水平菜单的位置 */
handleHorizontalMenuPosition(position: HorizontalMenuPosition) {
this.menuStyle.horizontalPosition = position;
},
/** 更改头部的高度 */
handleHeaderHeight(height: number | null) {
if (height !== null) {
this.headerStyle.height = height;
}
},
/** 更改Tab标签的高度 */
handleMultiTabHeight(height: number | null) {
if (height !== null) {
this.multiTabStyle.height = height;
}
},
/** 设置多页签的显示 */
handleMultiTabVisible(visible: boolean) {
this.multiTabStyle.visible = visible;
},
/** 设置多页签的显示 */
handleMultiTabMode(mode: MultiTabMode) {
this.multiTabStyle.mode = mode;
},
/** 设置多页签缓存 */
handleSetMultiTabCache(isCache: boolean) {
this.multiTabStyle.isCache = isCache;
},
/** 设置面包屑的显示 */
handleCrumbsVisible(visible: boolean) {
this.crumbsStyle.visible = visible;
},
/** 设置面包屑图标的显示 */
handleCrumbsIconVisible(visible: boolean) {
this.crumbsStyle.showIcon = visible;
},
/** 开启页面切换动画 */
handlePageAnimate(animate: boolean) {
this.pageStyle.animate = animate;
},
/** 设置页面切换动画类型 */
handlePageAnimateType(animateType: AnimateType) {
if (this.pageStyle.animate) {
this.pageStyle.animateType = animateType;
}
},
/** 固定头部 */
handleFixedHeaderAndTab(isFixed: boolean) {
this.fixedHeaderAndTab = isFixed;
}
}
});
export default function useThemeStore() {
return themeStore(store);
}
export const useThemeStore = defineStore('theme-store', () => {});