feat: add report preview
This commit is contained in:
@@ -4,9 +4,11 @@ from fastapi import FastAPI, HTTPException
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.responses import StreamingResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from pydantic import BaseModel
|
||||
import json
|
||||
import re
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
from app.api import upload, llm, skills, users, datasources, projects, semantic
|
||||
@@ -34,6 +36,11 @@ app.add_middleware(
|
||||
# Initialize database tables
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
# Mount static directory for reports
|
||||
data_dir = os.path.join(os.path.dirname(__file__), "data", "data")
|
||||
os.makedirs(data_dir, exist_ok=True)
|
||||
app.mount("/reports", StaticFiles(directory=data_dir), name="reports")
|
||||
|
||||
app.include_router(upload.router, prefix="/api/v1")
|
||||
app.include_router(llm.router, prefix="/api/v1")
|
||||
app.include_router(skills.router, prefix="/api/v1")
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useState, useRef, useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import { User, Loader2, Sparkles, ArrowUp, ChevronDown, Paperclip, Check, X, Square, Plus, Database, Wand2, Search, Zap, LayoutGrid, CheckCircle2, Table, XCircle, Settings } from "lucide-react";
|
||||
import { User, Loader2, Sparkles, ArrowUp, ChevronDown, Paperclip, Check, X, Square, Plus, Database, Wand2, Search, Zap, LayoutGrid, CheckCircle2, Table, XCircle, Settings, ExternalLink } from "lucide-react";
|
||||
import { api } from "@/lib/api";
|
||||
import { type ChartSpec } from "@/store/visualizationStore";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
@@ -50,6 +50,17 @@ const splitReportHtml = (content: string): { markdown: string; reportHtml: strin
|
||||
return { markdown, reportHtml: reportHtml || null };
|
||||
};
|
||||
|
||||
const HTML_FILE_REGEX = /data[\\\/]data[\\\/]([a-zA-Z0-9_\-]+\.html?)/i;
|
||||
|
||||
const extractExternalReport = (content: string): string | null => {
|
||||
if (!content) return null;
|
||||
const match = content.match(HTML_FILE_REGEX);
|
||||
if (match && match[1]) {
|
||||
return `/reports/${match[1]}`;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
interface ModelConfig {
|
||||
id: string;
|
||||
name?: string;
|
||||
@@ -926,6 +937,7 @@ export function ChatInterface() {
|
||||
<div className="max-w-3xl mx-auto px-4 py-8 space-y-8">
|
||||
{messages.map((msg) => {
|
||||
const { markdown, reportHtml } = splitReportHtml(msg.content);
|
||||
const externalReportUrl = extractExternalReport(msg.content);
|
||||
return (
|
||||
<div
|
||||
key={msg.id}
|
||||
@@ -993,6 +1005,19 @@ export function ChatInterface() {
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{externalReportUrl ? (
|
||||
<div className="mt-4 flex">
|
||||
<a
|
||||
href={externalReportUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-2 px-4 py-2 bg-blue-50 text-blue-600 hover:bg-blue-100 hover:text-blue-700 rounded-lg text-sm font-medium transition-colors"
|
||||
>
|
||||
<ExternalLink className="h-4 w-4" />
|
||||
在新标签页中打开分析报告
|
||||
</a>
|
||||
</div>
|
||||
) : null}
|
||||
{msg.viz ? (
|
||||
<div className="mt-3 pt-3 border-t border-zinc-100">
|
||||
<InlineVisualizationCard viz={msg.viz} />
|
||||
|
||||
@@ -20,6 +20,10 @@ export default defineConfig({
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/reports': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user