| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { ThemeEnum } from '/@/enums/appEnum';
- import { HOME_STYLE_KEY } from '/@/enums/cacheEnum';
- /**
- * 首页风格选择:localStorage 的存放与读取工具。
- * key 定义见 /@/enums/cacheEnum 的 HOME_STYLE_KEY;
- * 最终可选首页由 HomeStyleSelect.vue 的前端配置数组与 /sys/permissionNew/list 后端数据按 component 匹配得出。
- */
- export interface HomeStyleOption {
- /** 唯一标识(持久化用,取前端配置的 component,稳定) */
- id: string;
- /** 首页风格名称(下拉框显示) */
- name: string;
- /** 首页路由(对应后端菜单 url) */
- route: string;
- /** 主题模式:ThemeEnum.VENT1 / DEEPBLUE / GREEN / LIGHT / DARK */
- theme: ThemeEnum;
- /** 页面样式变量,可选(如 ThemeModel.theme5_5) */
- cssVars?: Record<string, string>;
- }
- /** 读取已保存的首页风格(无则返回 null,损坏数据安全兜底) */
- export function getSavedHomeStyle(): HomeStyleOption | null {
- try {
- const raw = localStorage.getItem(HOME_STYLE_KEY);
- return raw ? (JSON.parse(raw) as HomeStyleOption) : null;
- } catch {
- return null;
- }
- }
- /** 保存首页风格选择;传入 null 表示清除(恢复系统默认) */
- export function saveHomeStyle(option: HomeStyleOption | null): void {
- if (option) {
- localStorage.setItem(HOME_STYLE_KEY, JSON.stringify({ id: option.id, route: option.route }));
- } else {
- localStorage.removeItem(HOME_STYLE_KEY);
- }
- }
- /** 供路由守卫 / 登录流程读取已保存的首页路由(无则返回 '') */
- export function getSavedHomeRoute(): string {
- return getSavedHomeStyle()?.route || '';
- }
|