diff --git a/business-css/frontend/src/views/business/algorithmModel/index.vue b/business-css/frontend/src/views/business/algorithmModel/index.vue index 197b4d6..9cac49b 100644 --- a/business-css/frontend/src/views/business/algorithmModel/index.vue +++ b/business-css/frontend/src/views/business/algorithmModel/index.vue @@ -14,6 +14,7 @@ import { searchAlgorithmsModelPage} from "@/api/business/algorithmModel"; import Page from '@/components/Pagination/page.vue' import { getDictItemById } from '@/api/dict'; +const apiUrl = import.meta.env.VITE_APP_BASE_API; // 基础路径 const menuData:any = ref([]); const algorithmData:any = ref([]); // 查询字典项 @@ -341,7 +342,7 @@ function changeShowResult(isShow:boolean){ // 切换显示结果模型
@@ -379,7 +380,7 @@ function changeShowResult(isShow:boolean){ // 切换显示结果模型
- +
diff --git a/framework/src/main/java/com/yfd/platform/config/WebConfig.java b/framework/src/main/java/com/yfd/platform/config/WebConfig.java index 45b051a..081988e 100644 --- a/framework/src/main/java/com/yfd/platform/config/WebConfig.java +++ b/framework/src/main/java/com/yfd/platform/config/WebConfig.java @@ -4,11 +4,14 @@ import cn.hutool.cache.Cache; import cn.hutool.cache.CacheUtil; import lombok.SneakyThrows; import jakarta.annotation.Resource; + +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; +import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -17,7 +20,20 @@ public class WebConfig implements WebMvcConfigurer { @Resource private FileSpaceProperties fileSpaceProperties; + @Value("${file-space.model-path:E:/python_coding/keffCenter/models/}") + private String modelPath; + + /** + * 跨域配置:允许前端访问 /models/** 资源 + */ + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/models/**") // 仅放行 /models/** 路径 + .allowedOrigins("http://localhost:3000") // 前端地址 + .allowedMethods("GET") // 仅允许 GET + .allowCredentials(true); // 如需带 cookie + } @Bean public Cache loginuserCache() { @@ -41,6 +57,7 @@ public class WebConfig implements WebMvcConfigurer { @SneakyThrows @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { + System.out.println("[WebConfig] modelPath in addResourceHandlers = " + modelPath); registry.addResourceHandler("/icon/**") .addResourceLocations("classpath:/static/icon/") .setCachePeriod(0); @@ -52,9 +69,19 @@ public class WebConfig implements WebMvcConfigurer { registry.addResourceHandler("swagger-ui.html").addResourceLocations( "classpath:/META-INF/resources/"); + // 把本地 modelPath 映射到 /models/** URL + String path = modelPath.replace("\\", "/"); + if (!path.endsWith("/")) { + path += "/"; + } + registry.addResourceHandler("/models/**") + .addResourceLocations("file:" + path); + String systemUrl = "file:" + fileSpaceProperties.getSystem().replace("\\", "/")+"user\\"; registry.addResourceHandler("/avatar/**").addResourceLocations(systemUrl).setCachePeriod(0); + + }