fix: support local entry module icons

This commit is contained in:
wren
2026-04-29 19:50:10 +08:00
parent 55e65e00f5
commit b544b1a795
2 changed files with 27 additions and 4 deletions
+14 -3
View File
@@ -48,6 +48,18 @@ interface LoaderData {
error?: string; error?: string;
} }
function resolveModuleLogoUrl(path?: string | null): string | null {
if (!path) {
return null;
}
if (path.startsWith("/images/") || path.startsWith("http://") || path.startsWith("https://")) {
return path;
}
return `${DOCUMENT_URL}${path}`;
}
// 🔑 客户端加载函数 - 在浏览器端执行,axios-client 会自动添加 JWT // 🔑 客户端加载函数 - 在浏览器端执行,axios-client 会自动添加 JWT
export async function clientLoader({ request }: ClientLoaderFunctionArgs) { export async function clientLoader({ request }: ClientLoaderFunctionArgs) {
try { try {
@@ -259,11 +271,10 @@ export default function EntryModulesList() {
title: 'Logo图片', title: 'Logo图片',
width: '150px', width: '150px',
render: (_: any, record: EntryModule) => { render: (_: any, record: EntryModule) => {
if (!record.path) { const logoUrl = resolveModuleLogoUrl(record.path);
if (!logoUrl) {
return <span className="text-gray-400"></span>; return <span className="text-gray-400"></span>;
} }
const logoUrl = `${DOCUMENT_URL}${record.path}`;
const hasFailed = failedImages.has(record.id!); const hasFailed = failedImages.has(record.id!);
return ( return (
+13 -1
View File
@@ -79,6 +79,18 @@ const AREA_OPTIONS = [
{ value: "省局", label: "省局" } { value: "省局", label: "省局" }
]; ];
function resolveModuleLogoUrl(path?: string | null): string | null {
if (!path) {
return null;
}
if (path.startsWith("/images/") || path.startsWith("http://") || path.startsWith("https://")) {
return path;
}
return `${DOCUMENT_URL}${path}`;
}
// 入口模块新建/编辑组件 // 入口模块新建/编辑组件
export default function EntryModuleNew() { export default function EntryModuleNew() {
const navigate = useNavigate(); const navigate = useNavigate();
@@ -106,7 +118,7 @@ export default function EntryModuleNew() {
); );
const [logoFile, setLogoFile] = useState<File | null>(null); const [logoFile, setLogoFile] = useState<File | null>(null);
const [logoPreview, setLogoPreview] = useState<string | null>( const [logoPreview, setLogoPreview] = useState<string | null>(
module?.path ? `${DOCUMENT_URL}${module.path}` : null resolveModuleLogoUrl(module?.path)
); );
const [isSubmitting, setIsSubmitting] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false);