Files
shanghai-residences/src/utils/index.ts
T
zhongyidian 4ce7520066 feat: enhance modal functionality and integrate new components
- Added keyframes and animation for a smooth scale-in effect in the Tailwind configuration.
- Updated Image component to improve quality handling and style definitions.
- Introduced WordViewer and WordViewerModal components for document viewing capabilities.
- Enhanced Modal component to support embedded mode with customizable position and dimensions.
- Integrated IframeModal across various pages for user assistance and content display.
- Updated Content and Menu pages to utilize new components and improve user interaction.
- Added utility function to retrieve public paths for resources.
2025-10-29 00:18:06 +08:00

50 lines
1.5 KiB
TypeScript

// 图片资源映射 - 使用静态导入确保构建时包含所有图片
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.default as string;
}
// 回退到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}`;
};