feat: 更新样式管理和依赖配置

- 移除旧的 CSS 文件,改用 Tailwind CSS 进行样式管理
- 更新 tsconfig 和 Vite 配置以支持路径别名
- 添加 Node 类型定义以增强 TypeScript 支持
This commit is contained in:
zhongyidian committed 2026-01-23 17:41:02 +08:00
1 parent 8b32e84206
commit 33121e3f6d
19 files changed
+100 -69

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
// 图片资源映射 - 使用静态导入确保构建时包含所有图片
const imageModules = import.meta.glob(
"../assets/images/**/*.{png,jpg,jpeg,gif,svg,webp}",
{
eager: true,
},
);
// 访问静态图片 - 使用静态导入确保构建后路径正确
export const getStaticImage = (path: string) => {
try {
// 确保路径以正确的格式结尾
const imagePath =
path.endsWith(".png") ||
path.endsWith(".jpg") ||
path.endsWith(".jpeg") ||
path.endsWith(".gif") ||
path.endsWith(".svg") ||
path.endsWith(".webp")
? `../assets/images/${path}`
: `../assets/images/${path}.png`;
// 使用静态导入的模块
const module = imageModules[imagePath];
if (module && typeof module === "object" && "default" in module) {
return (module as { default: string }).default;
}
// 回退到 URL 方式
return new URL(imagePath, import.meta.url).href;
} catch (error) {
console.error("Failed to load image:", path, error);
return "";
}
};
// 获取背景图片的专用函数
export const getBackgroundImage = (path: string) => {
const imageUrl = getStaticImage(path);
return imageUrl ? `url(${imageUrl})` : "none";
};
// 获取 public 文件夹中的资源路径(用于 Word 文档等)
export const getPublicPath = (path: string) => {
// 移除开头的斜杠(如果有)
const cleanPath = path.startsWith("/") ? path.slice(1) : path;
// 使用 Vite 的 BASE_URL 环境变量来处理基础路径
return `${import.meta.env.BASE_URL}${cleanPath}`;
};
+2
View File
@@ -0,0 +1,2 @@
export * from "./assets";
export * from "./tailwind";
+10
View File
@@ -0,0 +1,10 @@
import { twMerge } from "tailwind-merge";
/**
* 合并 Tailwind CSS 类名,自动处理冲突
* @param classes - 要合并的类名
* @returns 合并后的类名字符串
*/
export function cn(...classes: (string | undefined | null | false)[]): string {
return twMerge(classes.filter(Boolean).join(" "));
}