fix: 修复 tags 无法解析颜色的问题

This commit is contained in:
Montia37
2025-09-08 10:34:47 +08:00
parent 5dc65c9cba
commit 4d4da8d3b8
2 changed files with 36 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
import { useContext } from "react";
import type { ConfigOptions } from "./default";
import { ConfigContext } from "./ConfigContext";
import { DEFAULT_CONFIG } from "./default";
/**
* 使用全局配置 Hook用于获取当前应用配置
@@ -13,13 +14,14 @@ export function useAppConfig(): ConfigOptions {
/**
* 使用特定配置项 Hook直接获取某个配置项的值
* @param key 配置项键名
* @returns 配置项的值
* @returns 配置项的值,如果为 undefined 则返回默认配置中的值
*/
export function useConfigItem<K extends keyof ConfigOptions>(
key: K
): ConfigOptions[K] {
): NonNullable<ConfigOptions[K]> {
const config = useContext(ConfigContext);
return config[key];
// 如果配置项为 undefined则回退到默认配置
return (config[key] ?? DEFAULT_CONFIG[key]) as NonNullable<ConfigOptions[K]>;
}
// 导出配置类型