update
This commit is contained in:
184
frontend/src/App.css
Normal file
184
frontend/src/App.css
Normal file
@@ -0,0 +1,184 @@
|
||||
.counter {
|
||||
font-size: 16px;
|
||||
padding: 5px 10px;
|
||||
border-radius: 5px;
|
||||
color: var(--accent);
|
||||
background: var(--accent-bg);
|
||||
border: 2px solid transparent;
|
||||
transition: border-color 0.3s;
|
||||
margin-bottom: 24px;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--accent-border);
|
||||
}
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.hero {
|
||||
position: relative;
|
||||
|
||||
.base,
|
||||
.framework,
|
||||
.vite {
|
||||
inset-inline: 0;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.base {
|
||||
width: 170px;
|
||||
position: relative;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.framework,
|
||||
.vite {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.framework {
|
||||
z-index: 1;
|
||||
top: 34px;
|
||||
height: 28px;
|
||||
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg)
|
||||
scale(1.4);
|
||||
}
|
||||
|
||||
.vite {
|
||||
z-index: 0;
|
||||
top: 107px;
|
||||
height: 26px;
|
||||
width: auto;
|
||||
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg)
|
||||
scale(0.8);
|
||||
}
|
||||
}
|
||||
|
||||
#center {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 25px;
|
||||
place-content: center;
|
||||
place-items: center;
|
||||
flex-grow: 1;
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
padding: 32px 20px 24px;
|
||||
gap: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
#next-steps {
|
||||
display: flex;
|
||||
border-top: 1px solid var(--border);
|
||||
text-align: left;
|
||||
|
||||
& > div {
|
||||
flex: 1 1 0;
|
||||
padding: 32px;
|
||||
@media (max-width: 1024px) {
|
||||
padding: 24px 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.icon {
|
||||
margin-bottom: 16px;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
flex-direction: column;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
#docs {
|
||||
border-right: 1px solid var(--border);
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
border-right: none;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
}
|
||||
|
||||
#next-steps ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin: 32px 0 0;
|
||||
|
||||
.logo {
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--text-h);
|
||||
font-size: 16px;
|
||||
border-radius: 6px;
|
||||
background: var(--social-bg);
|
||||
display: flex;
|
||||
padding: 6px 12px;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
text-decoration: none;
|
||||
transition: box-shadow 0.3s;
|
||||
|
||||
&:hover {
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
.button-icon {
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
margin-top: 20px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
|
||||
li {
|
||||
flex: 1 1 calc(50% - 8px);
|
||||
}
|
||||
|
||||
a {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#spacer {
|
||||
height: 88px;
|
||||
border-top: 1px solid var(--border);
|
||||
@media (max-width: 1024px) {
|
||||
height: 48px;
|
||||
}
|
||||
}
|
||||
|
||||
.ticks {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
|
||||
&::before,
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: -4.5px;
|
||||
border: 5px solid transparent;
|
||||
}
|
||||
|
||||
&::before {
|
||||
left: 0;
|
||||
border-left-color: var(--border);
|
||||
}
|
||||
&::after {
|
||||
right: 0;
|
||||
border-right-color: var(--border);
|
||||
}
|
||||
}
|
||||
48
frontend/src/App.tsx
Normal file
48
frontend/src/App.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import './styles/globals.css';
|
||||
import { ThemeProvider, AppProvider, useApp, useTheme } from './contexts';
|
||||
import { Header, Tabs } from './components/layout';
|
||||
import { CompliancePage } from './pages/Compliance';
|
||||
import { DocsPage } from './pages/Docs';
|
||||
import { StatusPage } from './pages/Status';
|
||||
import { RagChatPage } from './pages/RagChat';
|
||||
|
||||
const PageContent = () => {
|
||||
const { activeTab } = useApp();
|
||||
|
||||
switch (activeTab) {
|
||||
case 'docs':
|
||||
return <DocsPage />;
|
||||
case 'compliance':
|
||||
return <CompliancePage />;
|
||||
case 'status':
|
||||
return <StatusPage />;
|
||||
case 'rag':
|
||||
return <RagChatPage />;
|
||||
default:
|
||||
return <CompliancePage />;
|
||||
}
|
||||
};
|
||||
|
||||
const AppContent = () => {
|
||||
const { theme } = useTheme();
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col min-h-screen" style={{ backgroundColor: theme.bg }}>
|
||||
<Header />
|
||||
<Tabs />
|
||||
<PageContent />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<ThemeProvider>
|
||||
<AppProvider>
|
||||
<AppContent />
|
||||
</AppProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
43
frontend/src/api/compliance.ts
Normal file
43
frontend/src/api/compliance.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { streamSSE, type ComplianceResult, type SSEMessage } from './index';
|
||||
|
||||
// Upload and analyze a design document
|
||||
export async function analyzeDocument(file: File): Promise<{ task_id: string; status: string }> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const response = await fetch('/api/compliance/analyze', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Upload failed: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// Get analysis result
|
||||
export async function getComplianceResult(taskId: string): Promise<ComplianceResult | { status: string; message: string }> {
|
||||
const response = await fetch(`/api/compliance/result/${taskId}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Get result failed: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// Compliance chat with SSE streaming
|
||||
export function complianceChat(
|
||||
segmentId: number,
|
||||
query: string,
|
||||
onMessage: (data: SSEMessage) => void,
|
||||
onError?: (error: Error) => void,
|
||||
onComplete?: () => void
|
||||
): void {
|
||||
streamSSE(`/compliance/chat/${segmentId}`, { query }, onMessage, onError, onComplete);
|
||||
}
|
||||
|
||||
// Export types
|
||||
export type { ComplianceResult, SSEMessage };
|
||||
144
frontend/src/api/docs.ts
Normal file
144
frontend/src/api/docs.ts
Normal file
@@ -0,0 +1,144 @@
|
||||
import type { DocInfo, DocListResponse, DocUploadResponse } from './index';
|
||||
|
||||
const DOCS_API_BASE = '/api/v1';
|
||||
|
||||
interface BackendDocumentItem {
|
||||
doc_id: string;
|
||||
filename: string;
|
||||
size: number;
|
||||
object_name: string;
|
||||
download_url: string;
|
||||
last_modified?: string | null;
|
||||
}
|
||||
|
||||
interface BackendDocumentListResponse {
|
||||
documents: BackendDocumentItem[];
|
||||
total: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
interface BackendKnowledgeResult {
|
||||
id: number;
|
||||
content: string;
|
||||
score: number;
|
||||
metadata: Record<string, unknown>;
|
||||
}
|
||||
|
||||
interface BackendKnowledgeResponse {
|
||||
query: string;
|
||||
total: number;
|
||||
results: BackendKnowledgeResult[];
|
||||
}
|
||||
|
||||
export interface RegulationSearchItem {
|
||||
id: number;
|
||||
file: string;
|
||||
clause: string;
|
||||
score: number;
|
||||
content: string;
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
export interface RegulationSearchResponse {
|
||||
query: string;
|
||||
total: number;
|
||||
results: RegulationSearchItem[];
|
||||
}
|
||||
|
||||
function formatFileSize(bytes: number): string {
|
||||
if (!bytes) return '0 B';
|
||||
if (bytes >= 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
||||
if (bytes >= 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
||||
return `${bytes}B`;
|
||||
}
|
||||
|
||||
function mapDoc(item: BackendDocumentItem): DocInfo {
|
||||
return {
|
||||
id: item.doc_id,
|
||||
name: item.filename,
|
||||
chunks: 0,
|
||||
status: 'indexed',
|
||||
created_at: item.last_modified || undefined,
|
||||
download_url: `${DOCS_API_BASE}/documents/download/${item.doc_id}`,
|
||||
size_text: formatFileSize(item.size),
|
||||
};
|
||||
}
|
||||
|
||||
export async function uploadDocument(file: File): Promise<DocUploadResponse> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('doc_name', file.name);
|
||||
formData.append('generate_summary', 'true');
|
||||
|
||||
const response = await fetch(`${DOCS_API_BASE}/documents/upload`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Upload failed: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return {
|
||||
doc_id: data.doc_id,
|
||||
filename: data.doc_name || file.name,
|
||||
size: file.size,
|
||||
status: data.status,
|
||||
num_chunks: data.num_chunks,
|
||||
summary: data.summary,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getDocumentList(): Promise<DocListResponse> {
|
||||
const response = await fetch(`${DOCS_API_BASE}/documents/management-list`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`List failed: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json() as BackendDocumentListResponse;
|
||||
return {
|
||||
docs: data.documents.map(mapDoc),
|
||||
};
|
||||
}
|
||||
|
||||
export async function searchRegulations(query: string, topK: number = 8): Promise<RegulationSearchResponse> {
|
||||
const response = await fetch(`${DOCS_API_BASE}/knowledge/retrieval`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ query, top_k: topK }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Search failed: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json() as BackendKnowledgeResponse;
|
||||
return {
|
||||
query: data.query,
|
||||
total: data.total,
|
||||
results: data.results.map((item) => {
|
||||
const metadata = item.metadata || {};
|
||||
return {
|
||||
id: item.id,
|
||||
file: String(metadata.doc_name || metadata.filename || metadata.source || '法规知识库'),
|
||||
clause: String(metadata.chunk_type || metadata.section || metadata.clause || '法规片段'),
|
||||
score: item.score,
|
||||
content: item.content,
|
||||
tags: [
|
||||
metadata.regulation_type ? String(metadata.regulation_type) : '',
|
||||
metadata.version ? `v${String(metadata.version)}` : '',
|
||||
].filter(Boolean),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export function getDocumentDownloadUrl(docId: string): string {
|
||||
return `${DOCS_API_BASE}/documents/download/${docId}`;
|
||||
}
|
||||
|
||||
export type { DocInfo, DocListResponse, DocUploadResponse };
|
||||
213
frontend/src/api/index.ts
Normal file
213
frontend/src/api/index.ts
Normal file
@@ -0,0 +1,213 @@
|
||||
// API configuration - 使用相对路径,通过 Vite proxy 转发
|
||||
const API_BASE_URL = '/api';
|
||||
|
||||
// Helper function for fetch requests
|
||||
async function fetchAPI<T>(endpoint: string, options?: RequestInit): Promise<T> {
|
||||
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
||||
...options,
|
||||
headers: {
|
||||
...options?.headers,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`API Error: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// SSE helper for streaming responses
|
||||
function createSSEConnection(endpoint: string, body: unknown): EventSource {
|
||||
// For POST requests with SSE, we need to use fetch with ReadableStream
|
||||
// since EventSource only supports GET requests
|
||||
const url = `${API_BASE_URL}${endpoint}`;
|
||||
|
||||
return new EventSource(url); // This won't work for POST, we'll handle it differently
|
||||
}
|
||||
|
||||
// SSE streaming helper for POST requests
|
||||
async function streamSSE(
|
||||
endpoint: string,
|
||||
body: unknown,
|
||||
onMessage: (data: unknown) => void,
|
||||
onError?: (error: Error) => void,
|
||||
onComplete?: () => void
|
||||
): Promise<void> {
|
||||
const url = `${API_BASE_URL}${endpoint}`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'text/event-stream',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
if (onError) {
|
||||
onError(new Error(`HTTP error! status: ${response.status}`));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const reader = response.body?.getReader();
|
||||
if (!reader) {
|
||||
if (onError) {
|
||||
onError(new Error('No response body'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = '';
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
|
||||
// Process SSE events
|
||||
const lines = buffer.split('\n');
|
||||
buffer = '';
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('data:')) {
|
||||
const data = line.slice(5).trim();
|
||||
if (data) {
|
||||
try {
|
||||
const parsed = JSON.parse(data);
|
||||
onMessage(parsed);
|
||||
} catch {
|
||||
// Handle non-JSON data
|
||||
onMessage({ type: 'raw', text: data });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (onComplete) {
|
||||
onComplete();
|
||||
}
|
||||
} catch (error) {
|
||||
if (onError) {
|
||||
onError(error instanceof Error ? error : new Error(String(error)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Export types
|
||||
export interface DocInfo {
|
||||
id: string;
|
||||
name: string;
|
||||
chunks: number;
|
||||
status: string;
|
||||
created_at?: string;
|
||||
download_url?: string;
|
||||
size_text?: string;
|
||||
}
|
||||
|
||||
export interface DocListResponse {
|
||||
docs: DocInfo[];
|
||||
}
|
||||
|
||||
export interface DocUploadResponse {
|
||||
doc_id: string;
|
||||
filename: string;
|
||||
size: number;
|
||||
status: string;
|
||||
num_chunks?: number;
|
||||
summary?: string;
|
||||
}
|
||||
|
||||
export interface QuickQuestion {
|
||||
id: string;
|
||||
question: string;
|
||||
category: string;
|
||||
}
|
||||
|
||||
export interface QuickQuestionsResponse {
|
||||
questions: QuickQuestion[];
|
||||
}
|
||||
|
||||
export interface RetrievedDoc {
|
||||
id: string;
|
||||
score: number;
|
||||
preview: string;
|
||||
doc_name: string;
|
||||
clause: string;
|
||||
doc_id?: string;
|
||||
download_url?: string;
|
||||
}
|
||||
|
||||
export interface SSEMessage {
|
||||
type: string;
|
||||
text?: string;
|
||||
docs?: RetrievedDoc[];
|
||||
}
|
||||
|
||||
export interface Regulation {
|
||||
id: number;
|
||||
name: string;
|
||||
clause: string;
|
||||
score: number;
|
||||
match_keyword: string;
|
||||
category: string;
|
||||
full_content: string;
|
||||
}
|
||||
|
||||
export interface ComplianceSegment {
|
||||
id: number;
|
||||
index: number;
|
||||
intent: string;
|
||||
start_pos: number;
|
||||
end_pos: number;
|
||||
content: string;
|
||||
risk_level: string;
|
||||
regulations: Regulation[];
|
||||
}
|
||||
|
||||
export interface RiskDashboard {
|
||||
score: number;
|
||||
high_risk_count: number;
|
||||
medium_risk_count: number;
|
||||
low_risk_count: number;
|
||||
need_fix_segments: number;
|
||||
status: string;
|
||||
status_label: string;
|
||||
}
|
||||
|
||||
export interface PriorityAction {
|
||||
regulation: string;
|
||||
issue: string;
|
||||
suggestion: string;
|
||||
severity: string;
|
||||
}
|
||||
|
||||
export interface ComplianceResult {
|
||||
task_id: string;
|
||||
dashboard: RiskDashboard;
|
||||
segments: ComplianceSegment[];
|
||||
priority_actions: PriorityAction[];
|
||||
}
|
||||
|
||||
export interface SystemStats {
|
||||
docs: number;
|
||||
chunks: number;
|
||||
vectors: number;
|
||||
segments: number;
|
||||
}
|
||||
|
||||
export interface SystemConfig {
|
||||
llm: { model: string };
|
||||
embedding: { model: string; dimension: number };
|
||||
milvus: { host: string; port: number };
|
||||
retrieval: { vector_top_k: number; final_top_k: number };
|
||||
}
|
||||
|
||||
export { fetchAPI, streamSSE, API_BASE_URL };
|
||||
114
frontend/src/api/rag.ts
Normal file
114
frontend/src/api/rag.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
import type { QuickQuestionsResponse, SSEMessage } from './index';
|
||||
|
||||
const AGENT_API_BASE = '/api/v1';
|
||||
|
||||
export async function getQuickQuestions(): Promise<QuickQuestionsResponse> {
|
||||
return {
|
||||
questions: [
|
||||
{ id: '1', question: '请总结最新入库法规对电池安全的核心要求', category: '法规解读' },
|
||||
{ id: '2', question: '我上传的制度文档与新能源法规有哪些潜在冲突?', category: '差距分析' },
|
||||
{ id: '3', question: '请给出法规依据,并按条款列出整改建议', category: '整改建议' },
|
||||
{ id: '4', question: '请解释 UN-ECE 与 GB 标准在网络安全方面的差异', category: '标准对比' },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function parseSSEChunk(raw: string, onMessage: (data: SSEMessage) => void) {
|
||||
const blocks = raw.split('\n\n');
|
||||
for (const block of blocks) {
|
||||
if (!block.trim()) continue;
|
||||
|
||||
let eventName = 'message';
|
||||
const dataLines: string[] = [];
|
||||
|
||||
for (const line of block.split('\n')) {
|
||||
if (line.startsWith('event:')) {
|
||||
eventName = line.slice(6).trim();
|
||||
} else if (line.startsWith('data:')) {
|
||||
dataLines.push(line.slice(5).trim());
|
||||
}
|
||||
}
|
||||
|
||||
const joined = dataLines.join('\n');
|
||||
if (!joined) continue;
|
||||
|
||||
if (eventName === 'sources') {
|
||||
try {
|
||||
const docs = JSON.parse(joined) as Array<Record<string, unknown>>;
|
||||
onMessage({
|
||||
type: 'retrieved',
|
||||
docs: docs.map((doc, index) => ({
|
||||
id: String(doc.doc_id || doc.index || index + 1),
|
||||
score: Number(doc.score || 0),
|
||||
preview: String(doc.content || doc.snippet || ''),
|
||||
doc_name: String(doc.doc_name || doc.filename || `引用 ${index + 1}`),
|
||||
clause: String(doc.clause_number || doc.section_title || '法规片段'),
|
||||
doc_id: doc.doc_id ? String(doc.doc_id) : undefined,
|
||||
download_url: doc.doc_id ? `${AGENT_API_BASE}/documents/download/${String(doc.doc_id)}` : undefined,
|
||||
})),
|
||||
});
|
||||
} catch {
|
||||
// Ignore malformed source payloads.
|
||||
}
|
||||
} else if (eventName === 'content') {
|
||||
onMessage({ type: 'chunk', text: joined });
|
||||
} else if (eventName === 'done') {
|
||||
onMessage({ type: 'done', text: joined });
|
||||
} else if (eventName === 'error') {
|
||||
onMessage({ type: 'error', text: joined });
|
||||
} else if (eventName === 'status') {
|
||||
onMessage({ type: 'status', text: joined });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function ragChat(
|
||||
query: string,
|
||||
topK: number = 5,
|
||||
onMessage: (data: SSEMessage) => void,
|
||||
onError?: (error: Error) => void,
|
||||
onComplete?: () => void
|
||||
): Promise<void> {
|
||||
try {
|
||||
const response = await fetch(`${AGENT_API_BASE}/agent/chat/stream`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'text/event-stream',
|
||||
},
|
||||
body: JSON.stringify({ query, top_k: topK }),
|
||||
});
|
||||
|
||||
if (!response.ok || !response.body) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = '';
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
const parts = buffer.split('\n\n');
|
||||
buffer = parts.pop() || '';
|
||||
parseSSEChunk(parts.join('\n\n'), onMessage);
|
||||
}
|
||||
|
||||
if (buffer.trim()) {
|
||||
parseSSEChunk(buffer, onMessage);
|
||||
}
|
||||
|
||||
if (onComplete) {
|
||||
onComplete();
|
||||
}
|
||||
} catch (error) {
|
||||
if (onError) {
|
||||
onError(error instanceof Error ? error : new Error(String(error)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type { QuickQuestionsResponse, SSEMessage };
|
||||
19
frontend/src/api/status.ts
Normal file
19
frontend/src/api/status.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { fetchAPI, type SystemStats, type SystemConfig } from './index';
|
||||
|
||||
// Get system statistics
|
||||
export async function getSystemStats(): Promise<SystemStats> {
|
||||
return fetchAPI<SystemStats>('/status/stats');
|
||||
}
|
||||
|
||||
// Get system configuration
|
||||
export async function getSystemConfig(): Promise<SystemConfig> {
|
||||
return fetchAPI<SystemConfig>('/status/config');
|
||||
}
|
||||
|
||||
// Get Milvus health status
|
||||
export async function getMilvusHealth(): Promise<{ connected: boolean; collections: string[] }> {
|
||||
return fetchAPI('/status/milvus/health');
|
||||
}
|
||||
|
||||
// Export types
|
||||
export type { SystemStats, SystemConfig };
|
||||
BIN
frontend/src/assets/hero.png
Normal file
BIN
frontend/src/assets/hero.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
1
frontend/src/assets/react.svg
Normal file
1
frontend/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
1
frontend/src/assets/vite.svg
Normal file
1
frontend/src/assets/vite.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 8.5 KiB |
15
frontend/src/components/common/TLogo.tsx
Normal file
15
frontend/src/components/common/TLogo.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
|
||||
interface TLogoProps {
|
||||
size?: number;
|
||||
}
|
||||
|
||||
export const TLogo: React.FC<TLogoProps> = ({ size = 40 }) => (
|
||||
<img
|
||||
src="/logo/t_mobile_logo_transparent.png"
|
||||
alt="T-Systems"
|
||||
width={size}
|
||||
height={size}
|
||||
style={{ objectFit: 'contain' }}
|
||||
/>
|
||||
);
|
||||
30
frontend/src/components/common/TPattern.tsx
Normal file
30
frontend/src/components/common/TPattern.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
export const TPattern: React.FC = () => {
|
||||
const { theme, isDark } = useTheme();
|
||||
const patternOpacity = isDark ? 0.03 : 0.04;
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
right: 0,
|
||||
width: 300,
|
||||
height: 300,
|
||||
opacity: patternOpacity,
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
>
|
||||
<svg width="300" height="300" viewBox="0 0 300 300">
|
||||
<defs>
|
||||
<pattern id="grid" width="30" height="30" patternUnits="userSpaceOnUse">
|
||||
<path d="M 30 0 L 0 0 0 30" fill="none" stroke={theme.accent} strokeWidth="1"/>
|
||||
</pattern>
|
||||
</defs>
|
||||
<rect width="300" height="300" fill="url(#grid)"/>
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
35
frontend/src/components/common/ThemeToggle.tsx
Normal file
35
frontend/src/components/common/ThemeToggle.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
export const ThemeToggle: React.FC = () => {
|
||||
const { isDark, toggleTheme, theme } = useTheme();
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={toggleTheme}
|
||||
style={{
|
||||
width: 44,
|
||||
height: 44,
|
||||
borderRadius: 10,
|
||||
background: isDark ? theme.bgHover : theme.bgCard,
|
||||
border: `1px solid ${theme.border}`,
|
||||
cursor: 'pointer',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
transition: 'all 0.3s ease',
|
||||
}}
|
||||
>
|
||||
{isDark ? (
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="12" cy="12" r="4" fill={theme.accent}/>
|
||||
<path d="M12 2V4M12 20V22M4 12H2M22 12H20M6.34 6.34L4.93 4.93M19.07 19.07L17.66 17.66M6.34 17.66L4.93 19.07M19.07 4.93L17.66 6.34" stroke={theme.accent} strokeWidth="2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
) : (
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" fill={theme.accent} stroke={theme.accent} strokeWidth="1"/>
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
3
frontend/src/components/common/index.ts
Normal file
3
frontend/src/components/common/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { TLogo } from './TLogo';
|
||||
export { ThemeToggle } from './ThemeToggle';
|
||||
export { TPattern } from './TPattern';
|
||||
27
frontend/src/components/layout/Content.tsx
Normal file
27
frontend/src/components/layout/Content.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
interface ContentProps {
|
||||
children: React.ReactNode;
|
||||
wide?: boolean;
|
||||
}
|
||||
|
||||
export const Content: React.FC<ContentProps> = ({ children, wide = false }) => {
|
||||
const { theme } = useTheme();
|
||||
|
||||
return (
|
||||
<main
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: '48px 56px',
|
||||
maxWidth: wide ? 1400 : 1100,
|
||||
margin: '0 auto',
|
||||
width: '100%',
|
||||
position: 'relative',
|
||||
backgroundColor: theme.bg,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</main>
|
||||
);
|
||||
};
|
||||
47
frontend/src/components/layout/Header.tsx
Normal file
47
frontend/src/components/layout/Header.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
import { TLogo } from '../common/TLogo';
|
||||
import { ThemeToggle } from '../common/ThemeToggle';
|
||||
|
||||
export const Header: React.FC = () => {
|
||||
const { theme } = useTheme();
|
||||
|
||||
return (
|
||||
<header
|
||||
className="h-[72px] flex items-center justify-between sticky top-0 z-[100]"
|
||||
style={{
|
||||
padding: '0 48px',
|
||||
borderBottom: `1px solid ${theme.border}`,
|
||||
backgroundColor: theme.bg,
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center" style={{ gap: 20 }}>
|
||||
<TLogo size={80} />
|
||||
<div className="flex items-baseline" style={{ gap: 12 }}>
|
||||
<span style={{ fontWeight: 700, fontSize: 20, letterSpacing: '-0.5px', color: theme.text }}>
|
||||
T-Systems
|
||||
</span>
|
||||
<span style={{ fontWeight: 300, fontSize: 16, color: theme.text2 }}>
|
||||
Regulation
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center" style={{ gap: 16 }}>
|
||||
<ThemeToggle />
|
||||
<div
|
||||
className="flex items-center rounded-lg"
|
||||
style={{
|
||||
padding: '8px 16px',
|
||||
gap: 8,
|
||||
backgroundColor: theme.bgHover,
|
||||
borderRadius: 8,
|
||||
}}
|
||||
>
|
||||
<span className="mono" style={{ fontSize: 11, color: theme.text3 }}>v1.0.0</span>
|
||||
<div style={{ width: 1, height: 12, background: theme.border }} />
|
||||
<span className="mono" style={{ fontSize: 12, color: theme.green }}>● ONLINE</span>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
47
frontend/src/components/layout/Tabs.tsx
Normal file
47
frontend/src/components/layout/Tabs.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import React from 'react';
|
||||
import { useTheme, useApp } from '../../contexts';
|
||||
|
||||
const tabs = [
|
||||
{ id: 'docs', label: '文档管理' },
|
||||
{ id: 'compliance', label: '合规分析' },
|
||||
{ id: 'status', label: '系统状态' },
|
||||
{ id: 'rag', label: '法规对话' },
|
||||
];
|
||||
|
||||
export const Tabs: React.FC = () => {
|
||||
const { theme } = useTheme();
|
||||
const { activeTab, setActiveTab } = useApp();
|
||||
|
||||
return (
|
||||
<nav
|
||||
className="h-[56px] flex items-center"
|
||||
style={{
|
||||
padding: '0 48px',
|
||||
borderBottom: `1px solid ${theme.border}`,
|
||||
backgroundColor: theme.bg,
|
||||
}}
|
||||
>
|
||||
{tabs.map((tab) => (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setActiveTab(tab.id as any)}
|
||||
style={{
|
||||
height: 56,
|
||||
padding: '0 32px',
|
||||
fontSize: 15,
|
||||
fontWeight: activeTab === tab.id ? 600 : 400,
|
||||
color: activeTab === tab.id ? theme.accent : theme.text3,
|
||||
background: 'transparent',
|
||||
border: 'none',
|
||||
borderBottom: activeTab === tab.id ? `3px solid ${theme.accent}` : '3px solid transparent',
|
||||
marginBottom: -1,
|
||||
cursor: 'pointer',
|
||||
transition: 'all 0.2s ease',
|
||||
}}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
3
frontend/src/components/layout/index.ts
Normal file
3
frontend/src/components/layout/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { Header } from './Header';
|
||||
export { Tabs } from './Tabs';
|
||||
export { Content } from './Content';
|
||||
40
frontend/src/components/ui/Badge.tsx
Normal file
40
frontend/src/components/ui/Badge.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
interface BadgeProps {
|
||||
children: React.ReactNode;
|
||||
color?: 'accent' | 'green' | 'orange' | 'red';
|
||||
size?: 'sm' | 'md';
|
||||
}
|
||||
|
||||
export const Badge: React.FC<BadgeProps> = ({
|
||||
children,
|
||||
color = 'accent',
|
||||
size = 'sm',
|
||||
}) => {
|
||||
const { theme } = useTheme();
|
||||
|
||||
const colorStyles = {
|
||||
accent: { bg: theme.gradientAccent, text: '#fff' },
|
||||
green: { bg: theme.green, text: '#fff' },
|
||||
orange: { bg: theme.orange, text: '#fff' },
|
||||
red: { bg: '#ff4444', text: '#fff' },
|
||||
};
|
||||
|
||||
const sizeStyles = {
|
||||
sm: 'px-2 py-0.5 text-xs',
|
||||
md: 'px-3 py-1 text-sm',
|
||||
};
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`${sizeStyles[size]} rounded font-mono font-medium`}
|
||||
style={{
|
||||
background: colorStyles[color].bg,
|
||||
color: colorStyles[color].text,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
60
frontend/src/components/ui/Button.tsx
Normal file
60
frontend/src/components/ui/Button.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
interface ButtonProps {
|
||||
variant?: 'primary' | 'secondary';
|
||||
size?: 'sm' | 'md' | 'lg';
|
||||
children: React.ReactNode;
|
||||
onClick?: () => void;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const Button: React.FC<ButtonProps> = ({
|
||||
variant = 'primary',
|
||||
size = 'md',
|
||||
children,
|
||||
onClick,
|
||||
disabled = false,
|
||||
className = '',
|
||||
}) => {
|
||||
const { theme } = useTheme();
|
||||
|
||||
const baseStyles = `
|
||||
inline-flex items-center justify-center
|
||||
font-semibold rounded-xl cursor-pointer
|
||||
transition-all duration-300 ease
|
||||
disabled:cursor-not-allowed disabled:opacity-50
|
||||
`;
|
||||
|
||||
const sizeStyles = {
|
||||
sm: 'px-3 py-1.5 text-xs',
|
||||
md: 'px-5 py-3 text-sm',
|
||||
lg: 'px-8 py-5 text-base',
|
||||
};
|
||||
|
||||
const variantStyles = {
|
||||
primary: `
|
||||
bg-gradient-to-r from-t-accent to-t-accent-dark
|
||||
text-white hover:shadow-t-accent hover:-translate-y-0.5
|
||||
hover:from-[#f0208a] hover:to-[#d01070]
|
||||
`,
|
||||
secondary: `
|
||||
bg-t-bg-hover border border-t-border
|
||||
text-t-text2 hover:bg-t-bg-elevated
|
||||
`,
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
className={`${baseStyles} ${sizeStyles[size]} ${variantStyles[variant]} ${className}`}
|
||||
style={{
|
||||
color: variant === 'primary' ? '#fff' : theme.text2,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
54
frontend/src/components/ui/Card.tsx
Normal file
54
frontend/src/components/ui/Card.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
interface CardProps {
|
||||
accent?: boolean;
|
||||
highlight?: boolean;
|
||||
padding?: 'sm' | 'md' | 'lg';
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
export const Card: React.FC<CardProps> = ({
|
||||
accent = false,
|
||||
highlight = false,
|
||||
padding = 'md',
|
||||
children,
|
||||
className = '',
|
||||
onClick,
|
||||
}) => {
|
||||
const { theme, isDark } = useTheme();
|
||||
|
||||
const paddingStyles = {
|
||||
sm: 'p-4',
|
||||
md: 'p-5',
|
||||
lg: 'p-8',
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={onClick}
|
||||
className={`
|
||||
rounded-xl border transition-all duration-200 cursor-default
|
||||
${paddingStyles[padding]}
|
||||
${accent ? 'border-t-accent' : 'border-t-border'}
|
||||
${highlight ? 'border-2 border-t-accent' : ''}
|
||||
${!isDark ? 'shadow-t-card' : ''}
|
||||
${onClick ? 'cursor-pointer hover:border-t-accent' : ''}
|
||||
${className}
|
||||
`}
|
||||
style={{
|
||||
backgroundColor: theme.bgCard,
|
||||
}}
|
||||
>
|
||||
{accent && (
|
||||
<div
|
||||
className="absolute top-0 left-0 right-0 h-[3px] rounded-t-xl"
|
||||
style={{ background: theme.gradientAccent }}
|
||||
/>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
45
frontend/src/components/ui/Input.tsx
Normal file
45
frontend/src/components/ui/Input.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
interface InputProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
placeholder?: string;
|
||||
onKeyDown?: (e: React.KeyboardEvent) => void;
|
||||
className?: string;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export const Input: React.FC<InputProps> = ({
|
||||
value,
|
||||
onChange,
|
||||
placeholder = '',
|
||||
onKeyDown,
|
||||
className = '',
|
||||
type = 'text',
|
||||
}) => {
|
||||
const { theme } = useTheme();
|
||||
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
onKeyDown={onKeyDown}
|
||||
placeholder={placeholder}
|
||||
className={`
|
||||
w-full px-4 py-3 text-sm
|
||||
bg-t-bg-card border border-t-border rounded-lg
|
||||
text-t-text outline-none
|
||||
focus:border-t-accent focus:ring-1 focus:ring-t-accent
|
||||
placeholder:text-t-text3
|
||||
${className}
|
||||
`}
|
||||
style={{
|
||||
backgroundColor: theme.bgCard,
|
||||
borderColor: theme.border,
|
||||
color: theme.text,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
43
frontend/src/components/ui/ProgressBar.tsx
Normal file
43
frontend/src/components/ui/ProgressBar.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
interface ProgressBarProps {
|
||||
percent: number;
|
||||
color?: 'accent' | 'green' | 'orange' | 'red';
|
||||
showLabel?: boolean;
|
||||
}
|
||||
|
||||
export const ProgressBar: React.FC<ProgressBarProps> = ({
|
||||
percent,
|
||||
color = 'accent',
|
||||
showLabel = false,
|
||||
}) => {
|
||||
const { theme } = useTheme();
|
||||
|
||||
const colorStyles = {
|
||||
accent: theme.gradientAccent,
|
||||
green: `linear-gradient(90deg, ${theme.green}, #00ff88)`,
|
||||
orange: `linear-gradient(90deg, ${theme.orange}, #ffaa00)`,
|
||||
red: '#ff4444',
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
<div
|
||||
className="h-2 rounded-full flex-1"
|
||||
style={{ backgroundColor: theme.bgHover }}
|
||||
>
|
||||
<div
|
||||
className="h-full rounded-full transition-all duration-300"
|
||||
style={{
|
||||
width: `${percent}%`,
|
||||
background: colorStyles[color],
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{showLabel && (
|
||||
<span className="font-mono text-xs text-t-accent">{percent}%</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
52
frontend/src/components/ui/ScoreBar.tsx
Normal file
52
frontend/src/components/ui/ScoreBar.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
interface ScoreBarProps {
|
||||
score: number; // 0-100
|
||||
label?: string;
|
||||
accent?: boolean;
|
||||
}
|
||||
|
||||
export const ScoreBar: React.FC<ScoreBarProps> = ({
|
||||
score,
|
||||
label,
|
||||
accent = false,
|
||||
}) => {
|
||||
const { theme } = useTheme();
|
||||
|
||||
return (
|
||||
<div
|
||||
className="p-5 rounded-xl border"
|
||||
style={{
|
||||
backgroundColor: theme.bgCard,
|
||||
borderColor: accent ? theme.accent : theme.border,
|
||||
}}
|
||||
>
|
||||
{label && (
|
||||
<div
|
||||
className="font-mono text-xs mb-2"
|
||||
style={{ color: theme.text3, letterSpacing: '1px' }}
|
||||
>
|
||||
{label}
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
className="font-mono text-3xl font-bold"
|
||||
style={{ color: accent ? theme.accent : theme.text }}
|
||||
>
|
||||
{score}
|
||||
</div>
|
||||
<div className="flex gap-1 mt-2">
|
||||
{[...Array(10)].map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="w-2 h-4 rounded-sm"
|
||||
style={{
|
||||
backgroundColor: i < score / 10 ? theme.accent : theme.bgHover,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
6
frontend/src/components/ui/index.ts
Normal file
6
frontend/src/components/ui/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export { Button } from './Button';
|
||||
export { Card } from './Card';
|
||||
export { Input } from './Input';
|
||||
export { Badge } from './Badge';
|
||||
export { ProgressBar } from './ProgressBar';
|
||||
export { ScoreBar } from './ScoreBar';
|
||||
32
frontend/src/contexts/AppContext.tsx
Normal file
32
frontend/src/contexts/AppContext.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import { createContext, useContext, useState, type ReactNode } from 'react';
|
||||
|
||||
type TabId = 'docs' | 'compliance' | 'status' | 'rag';
|
||||
|
||||
interface AppContextValue {
|
||||
activeTab: TabId;
|
||||
setActiveTab: (tab: TabId) => void;
|
||||
}
|
||||
|
||||
const AppContext = createContext<AppContextValue | undefined>(undefined);
|
||||
|
||||
export const useApp = (): AppContextValue => {
|
||||
const context = useContext(AppContext);
|
||||
if (!context) {
|
||||
throw new Error('useApp must be used within an AppProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
interface AppProviderProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const AppProvider: React.FC<AppProviderProps> = ({ children }) => {
|
||||
const [activeTab, setActiveTab] = useState<TabId>('compliance');
|
||||
|
||||
return (
|
||||
<AppContext.Provider value={{ activeTab, setActiveTab }}>
|
||||
{children}
|
||||
</AppContext.Provider>
|
||||
);
|
||||
};
|
||||
49
frontend/src/contexts/ThemeContext.tsx
Normal file
49
frontend/src/contexts/ThemeContext.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import React, { createContext, useContext, useState, useEffect, type ReactNode } from 'react';
|
||||
import { darkTheme, lightTheme } from '../types/theme';
|
||||
import type { ThemeColors } from '../types/theme';
|
||||
|
||||
interface ThemeContextValue {
|
||||
isDark: boolean;
|
||||
theme: ThemeColors;
|
||||
toggleTheme: () => void;
|
||||
}
|
||||
|
||||
const ThemeContext = createContext<ThemeContextValue | undefined>(undefined);
|
||||
|
||||
export const useTheme = (): ThemeContextValue => {
|
||||
const context = useContext(ThemeContext);
|
||||
if (!context) {
|
||||
throw new Error('useTheme must be used within a ThemeProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
interface ThemeProviderProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
|
||||
const [isDark, setIsDark] = useState<boolean>(true);
|
||||
const theme = isDark ? darkTheme : lightTheme;
|
||||
|
||||
const toggleTheme = () => {
|
||||
setIsDark((prev) => !prev);
|
||||
};
|
||||
|
||||
// Apply class to document for Tailwind dark mode + body background
|
||||
useEffect(() => {
|
||||
if (isDark) {
|
||||
document.documentElement.classList.add('dark');
|
||||
document.body.style.background = '#0a0a12';
|
||||
} else {
|
||||
document.documentElement.classList.remove('dark');
|
||||
document.body.style.background = '#ffffff';
|
||||
}
|
||||
}, [isDark]);
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider value={{ isDark, theme, toggleTheme }}>
|
||||
{children}
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
};
|
||||
2
frontend/src/contexts/index.ts
Normal file
2
frontend/src/contexts/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { ThemeProvider, useTheme } from './ThemeContext';
|
||||
export { AppProvider, useApp } from './AppContext';
|
||||
7
frontend/src/data/index.ts
Normal file
7
frontend/src/data/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export * from './mockDocs';
|
||||
export * from './mockResults';
|
||||
export * from './mockDocumentContent';
|
||||
export * from './mockComplianceChunks';
|
||||
export * from './mockPriorityActions';
|
||||
export * from './mockRetrievalData';
|
||||
export * from './mockAIResponses';
|
||||
21
frontend/src/data/mockAIResponses.ts
Normal file
21
frontend/src/data/mockAIResponses.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export const mockAIResponses: Record<string, {
|
||||
compliance: string;
|
||||
interpretation: string;
|
||||
suggestion: string;
|
||||
}> = {
|
||||
'车身结构设计': {
|
||||
compliance: '根据GB 26112-2010第4.2条,车顶结构需承受1.5倍整备质量的载荷。您的设计提到"满足GB 26112-2010抗压强度要求",但缺少具体的承载数值说明。\n\n建议补充:实际测试承载值为XX倍整备质量,以满足法规要求。',
|
||||
interpretation: '热成型钢板(厚度2.5mm)用于A柱和B柱是合理的设计选择。C-NCAP管理规则第3.1条要求正面碰撞后车门应能打开,建议在设计中明确说明碰撞后车门开启性能。',
|
||||
suggestion: '建议补充以下细节以完善合规性:\n1. 车顶抗压强度具体数值\n2. A柱/B柱材料认证标准\n3. 碰撞测试验证数据',
|
||||
},
|
||||
'动力系统配置': {
|
||||
compliance: '充电接口符合GB/T 18487.1-2015标准,电池能量密度180Wh/kg远超GB/T 31484-2015要求的120Wh/kg最低标准,合规性良好。\n\n注意:需提供电池热失控测试报告以满足GB 38031-2020要求。',
|
||||
interpretation: '快充30分钟充至80%符合行业标准,但需确保充电系统具备以下安全功能:\n- 过充保护\n- 温度监控\n- 通信协议符合GB/T 27930',
|
||||
suggestion: '建议补充:\n1. 电池热失控测试报告\n2. 充电系统通信协议版本\n3. 快充循环寿命测试数据',
|
||||
},
|
||||
'安全配置设计': {
|
||||
compliance: '6个安全气囊配置符合GB 27887-2011对乘用车的基本要求。AEB和FCW功能是C-NCAP评分加分项。\n\n方向盘疲劳监测摄像头符合高级辅助驾驶趋势,但法规暂无强制要求。',
|
||||
interpretation: '博世第9代ESP具备碰撞预警和AEB功能,符合当前主流安全标准。建议明确AEB的触发条件和响应时间参数。',
|
||||
suggestion: '建议完善:\n1. AEB触发条件说明\n2. 安全气囊预紧器响应时间\n3. ESP系统认证文件',
|
||||
},
|
||||
};
|
||||
46
frontend/src/data/mockComplianceChunks.ts
Normal file
46
frontend/src/data/mockComplianceChunks.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import type { ComplianceChunk } from '../types';
|
||||
|
||||
export const mockComplianceChunks: ComplianceChunk[] = [
|
||||
{
|
||||
id: 1,
|
||||
index: 1,
|
||||
intent: '车身结构设计',
|
||||
startPos: 45,
|
||||
endPos: 230,
|
||||
content: '车身采用高强度钢铝混合结构,A柱和B柱使用热成型钢板,厚度2.5mm。车顶结构设计满足GB 26112-2010抗压强度要求,正面碰撞能量吸收区域采用渐进式变形设计,确保碰撞时能量有效分散。',
|
||||
regulations: [
|
||||
{ id: 1, name: 'GB 26112-2010', clause: '第4.2条', score: 0.95, matchKeyword: '车顶抗压强度', category: 'high', fullContent: '车顶结构应能承受相当于车辆整备质量1.5倍的载荷...' },
|
||||
{ id: 2, name: 'C-NCAP管理规则', clause: '第3.1条', score: 0.88, matchKeyword: '正面碰撞', category: 'high', fullContent: '正面碰撞试验速度为50km/h,碰撞后车门应能打开...' },
|
||||
{ id: 3, name: 'GB 11551-2014', clause: '第5条', score: 0.72, matchKeyword: '碰撞能量吸收', category: 'medium', fullContent: '车辆正面碰撞时应有效保护乘员...' },
|
||||
{ id: 4, name: '机动车安全技术条件', clause: '第12条', score: 0.58, matchKeyword: 'A柱强度', category: 'medium', fullContent: 'A柱应具备足够的抗变形能力...' },
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
index: 2,
|
||||
intent: '动力系统配置',
|
||||
startPos: 298,
|
||||
endPos: 425,
|
||||
content: '搭载永磁同步电机,最大功率150kW,峰值扭矩310Nm。电池组采用三元锂离子电池,容量75kWh,能量密度180Wh/kg。充电接口支持快充(30分钟充至80%)和慢充(8小时充满),符合GB/T 18487.1-2015标准。',
|
||||
regulations: [
|
||||
{ id: 5, name: 'GB/T 18487.1-2015', clause: '第6条', score: 0.94, matchKeyword: '充电接口标准', category: 'high', fullContent: '电动汽车传导充电接口应符合标准要求...' },
|
||||
{ id: 6, name: 'GB/T 31484-2015', clause: '第4条', score: 0.85, matchKeyword: '电池能量密度', category: 'high', fullContent: '动力电池能量密度不低于120Wh/kg...' },
|
||||
{ id: 7, name: '新能源汽车生产企业准入', clause: '第8条', score: 0.65, matchKeyword: '电机功率', category: 'medium', fullContent: '驱动电机应符合相关技术标准...' },
|
||||
{ id: 8, name: '电动汽车安全要求', clause: '第7条', score: 0.45, matchKeyword: '充电时间', category: 'low', fullContent: '充电系统应具备过充保护功能...' },
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
index: 3,
|
||||
intent: '安全配置设计',
|
||||
startPos: 570,
|
||||
endPos: 725,
|
||||
content: '配备6个安全气囊(前排双气囊、侧气囊、侧气帘),采用预紧式安全带。ABS系统采用博世第9代ESP,具备碰撞预警功能(FCW)和自动紧急制动(AEB)。方向盘集成驾驶员疲劳监测摄像头。',
|
||||
regulations: [
|
||||
{ id: 9, name: 'GB 27887-2011', clause: '第5条', score: 0.92, matchKeyword: '安全气囊', category: 'high', fullContent: '乘用车应配备驾驶员和乘客安全气囊...' },
|
||||
{ id: 10, name: 'GB/T 26991-2011', clause: '第3条', score: 0.78, matchKeyword: 'ABS系统', category: 'medium', fullContent: '车辆应配备防抱死制动系统...' },
|
||||
{ id: 11, name: 'C-NCAP管理规则', clause: '第4.2条', score: 0.71, matchKeyword: 'AEB自动制动', category: 'medium', fullContent: '主动安全配置评分包含AEB功能...' },
|
||||
{ id: 12, name: '机动车运行安全技术条件', clause: '第15条', score: 0.38, matchKeyword: '疲劳监测', category: 'low', fullContent: '建议配备驾驶员状态监测系统...' },
|
||||
]
|
||||
},
|
||||
];
|
||||
9
frontend/src/data/mockDocs.ts
Normal file
9
frontend/src/data/mockDocs.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { Doc } from '../types';
|
||||
|
||||
export const mockDocs: Doc[] = [
|
||||
{ id: 1, name: '道路交通安全法.pdf', chunks: 156, size: '1.8MB', status: 'indexed' },
|
||||
{ id: 2, name: '机动车登记规定.docx', chunks: 89, size: '1.1MB', status: 'indexed' },
|
||||
{ id: 3, name: '电动自行车规范.pdf', chunks: 42, size: '345KB', status: 'indexed' },
|
||||
{ id: 4, name: 'GB 38031-2020 电动汽车安全要求.pdf', chunks: 128, size: '2.2MB', status: 'indexed' },
|
||||
{ id: 5, name: 'C-NCAP管理规则(2021版).pdf', chunks: 95, size: '1.5MB', status: 'indexed' },
|
||||
];
|
||||
31
frontend/src/data/mockDocumentContent.ts
Normal file
31
frontend/src/data/mockDocumentContent.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export const fullDocumentContent = `
|
||||
车辆设计方案 v2.0
|
||||
|
||||
一、车身结构设计
|
||||
|
||||
车身采用高强度钢铝混合结构,A柱和B柱使用热成型钢板,厚度2.5mm。车顶结构设计满足GB 26112-2010抗压强度要求,正面碰撞能量吸收区域采用渐进式变形设计,确保碰撞时能量有效分散。
|
||||
|
||||
车身侧面采用铝合金板材,减轻整车重量约15%。底盘结构采用模块化设计,便于后续维修和零部件更换。车门内部设置防撞梁,提升侧面碰撞安全性。
|
||||
|
||||
二、动力系统配置
|
||||
|
||||
搭载永磁同步电机,最大功率150kW,峰值扭矩310Nm。电池组采用三元锂离子电池,容量75kWh,能量密度180Wh/kg。充电接口支持快充(30分钟充至80%)和慢充(8小时充满),符合GB/T 18487.1-2015标准。
|
||||
|
||||
电机控制器采用水冷散热系统,工作温度范围-30℃至60℃。电池包内置BMS管理系统,实时监控电池状态,具备过充、过放、过温等多重保护功能。
|
||||
|
||||
三、安全配置设计
|
||||
|
||||
配备6个安全气囊(前排双气囊、侧气囊、侧气帘),采用预紧式安全带。ABS系统采用博世第9代ESP,具备碰撞预警功能(FCW)和自动紧急制动(AEB)。方向盘集成驾驶员疲劳监测摄像头。
|
||||
|
||||
安全带预紧器在碰撞发生前0.1秒自动收紧,配合气囊提供最佳保护效果。AEB系统在城市工况下可有效避免85%以上的碰撞事故。疲劳监测系统通过面部特征识别,实时提醒驾驶员注意休息。
|
||||
|
||||
四、车身外观设计
|
||||
|
||||
车身尺寸:长4650mm,宽1850mm,高1450mm,轴距2800mm。前大灯采用LED矩阵式设计,具备自适应远近光切换功能。尾灯采用贯穿式设计,提升视觉辨识度。
|
||||
|
||||
五、内饰设计方案
|
||||
|
||||
驾驶舱采用环抱式设计,中控台配备12.3英寸触摸屏。仪表盘采用全液晶显示,支持多种主题切换。座椅采用真皮包裹,具备8向电动调节和加热通风功能。
|
||||
|
||||
方向盘采用三辐式设计,集成多功能控制按键。车内氛围灯采用可调色设计,支持256色自定义。音响系统配备12扬声器,支持环绕声效果。
|
||||
`;
|
||||
28
frontend/src/data/mockPriorityActions.ts
Normal file
28
frontend/src/data/mockPriorityActions.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { PriorityAction } from '../types';
|
||||
|
||||
export const mockPriorityActions: PriorityAction[] = [
|
||||
{
|
||||
id: 1,
|
||||
regulation: 'GB 26112-2010 第4.2条',
|
||||
issue: '车顶抗压强度',
|
||||
suggestion: '建议补充具体承载测试数据,明确车顶结构承受载荷倍数达到1.5倍以上',
|
||||
chunkId: 1,
|
||||
severity: 'high',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
regulation: 'GB/T 31484-2015 第4条',
|
||||
issue: '电池能量密度',
|
||||
suggestion: '当前180Wh/kg已达标,建议补充热失控测试报告以满足GB 38031-2020',
|
||||
chunkId: 2,
|
||||
severity: 'medium',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
regulation: 'C-NCAP管理规则 第3.1条',
|
||||
issue: '正面碰撞验证',
|
||||
suggestion: '建议提供碰撞后车门开启性能测试数据',
|
||||
chunkId: 1,
|
||||
severity: 'medium',
|
||||
},
|
||||
];
|
||||
7
frontend/src/data/mockResults.ts
Normal file
7
frontend/src/data/mockResults.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { SearchResult } from '../types';
|
||||
|
||||
export const mockResults: SearchResult[] = [
|
||||
{ id: 1, score: 0.92, law: '《道路交通安全法》第十八条', preview: '电动自行车应当符合国家标准,应当登记后方可上路行驶...', source: '道路交通安全法.pdf' },
|
||||
{ id: 2, score: 0.87, law: '《电动自行车安全技术规范》第二条', preview: '最高设计车速不超过25km/h,整车质量≤55kg...', source: '电动自行车规范.pdf' },
|
||||
{ id: 3, score: 0.79, law: '《道路交通安全法实施条例》第七十二条', preview: '驾驶电动自行车应当遵守下列规定...', source: '道路交通安全法.pdf' },
|
||||
];
|
||||
16
frontend/src/data/mockRetrievalData.ts
Normal file
16
frontend/src/data/mockRetrievalData.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { RetrievalData } from '../types';
|
||||
|
||||
export const mockRetrievalData: RetrievalData[] = [
|
||||
{ id: 1, file: '道路交通安全法.pdf', clause: '第十八条', score: 0.92, content: '电动自行车应当符合国家标准,应当登记后方可上路行驶。电动自行车的设计最高车速、整车质量、外形尺寸等应当符合国家标准。' },
|
||||
{ id: 2, file: '电动自行车规范.pdf', clause: '第二条', score: 0.87, content: '最高设计车速不超过25km/h,整车质量(含电池)不超过55kg,具有脚踏骑行能力,蓄电池标称电压不超过48V。' },
|
||||
{ id: 3, file: '道路交通安全法.pdf', clause: '第七十二条', score: 0.79, content: '驾驶电动自行车在道路上行驶,应当遵守下列规定:佩戴安全头盔;不得逆向行驶;不得在机动车道内行驶。' },
|
||||
{ id: 4, file: '机动车登记规定.pdf', clause: '第五条', score: 0.72, content: '初次申领机动车号牌、行驶证的,应当向住所地的车辆管理所申请注册登记,填写申请表,交验机动车。' },
|
||||
{ id: 5, file: 'GB 38031-2020 电动汽车安全要求.pdf', clause: '5.1 热失控要求', score: 0.95, content: '电池系统发生热失控后,应在5分钟内不起火不爆炸,为乘员预留逃生时间。电池包需通过针刺、过充、短路等安全测试。' },
|
||||
{ id: 6, file: 'C-NCAP管理规则(2021版).pdf', clause: '4.2 正面碰撞', score: 0.88, content: '正面100%重叠刚性壁障碰撞试验,碰撞速度50km/h。试验后车门应能打开,燃油系统无泄漏,座椅及安全带功能正常。' },
|
||||
{ id: 7, file: '道路交通安全法.pdf', clause: '第九十条', score: 0.76, content: '机动车驾驶人违反道路交通安全法律、法规关于道路通行规定的,处警告或者二十元以上二百元以下罚款。' },
|
||||
{ id: 8, file: '机动车登记规定.pdf', clause: '第十二条', score: 0.65, content: '机动车所有人的住所迁出车辆管理所管辖区域的,车辆管理所应当自受理之日起三日内,在机动车登记证书上签注变更事项。' },
|
||||
{ id: 9, file: 'GB 38031-2020 电动汽车安全要求.pdf', clause: '6.2 充电安全', score: 0.91, content: '充电系统应具备过充保护功能,当电池SOC达到100%时应自动停止充电。充电接口应符合GB/T 18487.1标准要求。' },
|
||||
{ id: 10, file: 'C-NCAP管理规则(2021版).pdf', clause: '5.3.1 AEB功能', score: 0.84, content: '自动紧急制动系统(AEB)应在检测到前方障碍物时主动减速或停车。AEB系统测试分为目标车静止、移动、制动三种场景。' },
|
||||
{ id: 11, file: '道路交通安全法.pdf', clause: '第六十七条', score: 0.70, content: '机动车在高速公路上行驶,车速超过100km/h时,应当与同车道前车保持100米以上的距离;车速低于100km/h时,距离可适当缩短。' },
|
||||
{ id: 12, file: '道路交通安全法.pdf', clause: '第五十三条', score: 0.68, content: '警车、消防车、救护车、工程救险车执行紧急任务时,可以使用警报器、标志灯具,在确保安全的前提下,不受行驶路线、行驶方向、行驶速度和信号灯的限制。' },
|
||||
];
|
||||
111
frontend/src/index.css
Normal file
111
frontend/src/index.css
Normal file
@@ -0,0 +1,111 @@
|
||||
:root {
|
||||
--text: #6b6375;
|
||||
--text-h: #08060d;
|
||||
--bg: #fff;
|
||||
--border: #e5e4e7;
|
||||
--code-bg: #f4f3ec;
|
||||
--accent: #aa3bff;
|
||||
--accent-bg: rgba(170, 59, 255, 0.1);
|
||||
--accent-border: rgba(170, 59, 255, 0.5);
|
||||
--social-bg: rgba(244, 243, 236, 0.5);
|
||||
--shadow:
|
||||
rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px;
|
||||
|
||||
--sans: system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||
--heading: system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||
--mono: ui-monospace, Consolas, monospace;
|
||||
|
||||
font: 18px/145% var(--sans);
|
||||
letter-spacing: 0.18px;
|
||||
color-scheme: light dark;
|
||||
color: var(--text);
|
||||
background: var(--bg);
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--text: #9ca3af;
|
||||
--text-h: #f3f4f6;
|
||||
--bg: #16171d;
|
||||
--border: #2e303a;
|
||||
--code-bg: #1f2028;
|
||||
--accent: #c084fc;
|
||||
--accent-bg: rgba(192, 132, 252, 0.15);
|
||||
--accent-border: rgba(192, 132, 252, 0.5);
|
||||
--social-bg: rgba(47, 48, 58, 0.5);
|
||||
--shadow:
|
||||
rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px;
|
||||
}
|
||||
|
||||
#social .button-icon {
|
||||
filter: invert(1) brightness(2);
|
||||
}
|
||||
}
|
||||
|
||||
#root {
|
||||
width: 1126px;
|
||||
max-width: 100%;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
border-inline: 1px solid var(--border);
|
||||
min-height: 100svh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2 {
|
||||
font-family: var(--heading);
|
||||
font-weight: 500;
|
||||
color: var(--text-h);
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 56px;
|
||||
letter-spacing: -1.68px;
|
||||
margin: 32px 0;
|
||||
@media (max-width: 1024px) {
|
||||
font-size: 36px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
}
|
||||
h2 {
|
||||
font-size: 24px;
|
||||
line-height: 118%;
|
||||
letter-spacing: -0.24px;
|
||||
margin: 0 0 8px;
|
||||
@media (max-width: 1024px) {
|
||||
font-size: 20px;
|
||||
}
|
||||
}
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
code,
|
||||
.counter {
|
||||
font-family: var(--mono);
|
||||
display: inline-flex;
|
||||
border-radius: 4px;
|
||||
color: var(--text-h);
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 15px;
|
||||
line-height: 135%;
|
||||
padding: 4px 8px;
|
||||
background: var(--code-bg);
|
||||
}
|
||||
85
frontend/src/lib/api.ts
Normal file
85
frontend/src/lib/api.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import type {
|
||||
AgentChatResponse,
|
||||
DocumentListResponse,
|
||||
KnowledgeSearchResponse,
|
||||
UploadDocumentResponse,
|
||||
} from '../types';
|
||||
|
||||
const API_BASE = (
|
||||
import.meta.env.VITE_API_BASE_URL ||
|
||||
`${window.location.protocol}//${window.location.hostname}:8000/api/v1`
|
||||
).replace(/\/$/, '');
|
||||
|
||||
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const response = await fetch(`${API_BASE}${path}`, {
|
||||
...init,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
...(init?.headers || {}),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let message = `Request failed: ${response.status}`;
|
||||
try {
|
||||
const data = await response.json();
|
||||
message = data.detail || data.message || message;
|
||||
} catch {
|
||||
// Fall back to HTTP status when the response body is not JSON.
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
listDocuments: () => request<DocumentListResponse>('/documents/list'),
|
||||
|
||||
listDocumentManagementItems: () => request<DocumentListResponse>('/documents/management-list'),
|
||||
|
||||
uploadDocument: async (payload: {
|
||||
file: File;
|
||||
docName?: string;
|
||||
regulationType?: string;
|
||||
version?: string;
|
||||
generateSummary?: boolean;
|
||||
}) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', payload.file);
|
||||
if (payload.docName) formData.append('doc_name', payload.docName);
|
||||
if (payload.regulationType) formData.append('regulation_type', payload.regulationType);
|
||||
if (payload.version) formData.append('version', payload.version);
|
||||
formData.append('generate_summary', String(Boolean(payload.generateSummary)));
|
||||
|
||||
return request<UploadDocumentResponse>('/documents/upload', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
},
|
||||
|
||||
searchKnowledge: (query: string, topK = 8) =>
|
||||
request<KnowledgeSearchResponse>('/knowledge/retrieval', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ query, top_k: topK }),
|
||||
}),
|
||||
|
||||
chat: (payload: { query: string; sessionId?: string }) =>
|
||||
request<AgentChatResponse>('/agent/chat', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: payload.query,
|
||||
session_id: payload.sessionId,
|
||||
}),
|
||||
}),
|
||||
|
||||
get downloadBase() {
|
||||
return API_BASE.replace(/\/api\/v1$/, '');
|
||||
},
|
||||
};
|
||||
9
frontend/src/main.tsx
Normal file
9
frontend/src/main.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { StrictMode } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import App from './App.tsx';
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
);
|
||||
246
frontend/src/pages/Compliance/ChatPanel.tsx
Normal file
246
frontend/src/pages/Compliance/ChatPanel.tsx
Normal file
@@ -0,0 +1,246 @@
|
||||
import React from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
import type { ComplianceChunk } from '../../types';
|
||||
|
||||
interface ChatPanelProps {
|
||||
activeChunkId: number;
|
||||
chunks: ComplianceChunk[];
|
||||
messages: Array<{ id: number; role: 'user' | 'assistant'; content: string }>;
|
||||
chatInput: string;
|
||||
setChatInput: (value: string) => void;
|
||||
chatLoading: boolean;
|
||||
sendChatMessage: () => void;
|
||||
closeChat: () => void;
|
||||
quickQuestions?: string[];
|
||||
}
|
||||
|
||||
export const ChatPanel: React.FC<ChatPanelProps> = ({
|
||||
activeChunkId,
|
||||
chunks,
|
||||
messages,
|
||||
chatInput,
|
||||
setChatInput,
|
||||
chatLoading,
|
||||
sendChatMessage,
|
||||
closeChat,
|
||||
quickQuestions = [
|
||||
'这个设计是否合规?',
|
||||
'需要修改哪些内容?',
|
||||
'法规的具体要求是什么?',
|
||||
],
|
||||
}) => {
|
||||
const { theme } = useTheme();
|
||||
const activeChunk = chunks.find(c => c.id === activeChunkId);
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
right: 0,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
width: 420,
|
||||
background: theme.bgCard,
|
||||
borderLeft: `1px solid ${theme.border}`,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
zIndex: 50,
|
||||
animation: 'slideIn 0.3s ease-out forwards',
|
||||
}}
|
||||
>
|
||||
{/* Chat Header */}
|
||||
<div style={{
|
||||
padding: '20px 24px',
|
||||
borderBottom: `1px solid ${theme.border}`,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
}}>
|
||||
<div>
|
||||
<div style={{ fontSize: 14, fontWeight: 600, color: theme.text }}>合规对话</div>
|
||||
<div className="mono" style={{ fontSize: 11, color: theme.text3 }}>
|
||||
段落 #{activeChunk?.index} · {activeChunk?.regulations.length} 条法规
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={closeChat}
|
||||
style={{
|
||||
width: 32,
|
||||
height: 32,
|
||||
borderRadius: 8,
|
||||
background: theme.bgHover,
|
||||
border: 'none',
|
||||
cursor: 'pointer',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M18 6L6 18M6 6L18 18" stroke={theme.text3} strokeWidth="2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Current Chunk Info */}
|
||||
<div style={{
|
||||
padding: '16px 24px',
|
||||
background: theme.bgHover,
|
||||
borderBottom: `1px solid ${theme.border}`,
|
||||
}}>
|
||||
<div style={{ fontSize: 13, fontWeight: 500, marginBottom: 8, color: theme.text }}>
|
||||
{activeChunk?.intent}
|
||||
</div>
|
||||
<div style={{
|
||||
fontSize: 12,
|
||||
color: theme.text2,
|
||||
lineHeight: 1.5,
|
||||
maxHeight: 60,
|
||||
overflow: 'hidden',
|
||||
}}>
|
||||
{activeChunk?.content.substring(0, 100)}...
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Chat Messages */}
|
||||
<div style={{
|
||||
flex: 1,
|
||||
overflowY: 'auto',
|
||||
padding: '20px 24px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 16,
|
||||
}}>
|
||||
{messages.map(msg => (
|
||||
<div key={msg.id} style={{
|
||||
display: 'flex',
|
||||
gap: 12,
|
||||
flexDirection: msg.role === 'user' ? 'row-reverse' : 'row',
|
||||
}}>
|
||||
{msg.role === 'assistant' && (
|
||||
<div style={{
|
||||
width: 32,
|
||||
height: 32,
|
||||
borderRadius: 8,
|
||||
background: theme.gradientAccent,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
flexShrink: 0,
|
||||
}}>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="12" cy="12" r="6" fill="#fff"/>
|
||||
</svg>
|
||||
</div>
|
||||
)}
|
||||
<div style={{
|
||||
maxWidth: '80%',
|
||||
padding: '12px 16px',
|
||||
background: msg.role === 'user' ? theme.gradientAccent : theme.bgElevated,
|
||||
borderRadius: 12,
|
||||
color: msg.role === 'user' ? '#fff' : theme.text,
|
||||
fontSize: 14,
|
||||
lineHeight: 1.6,
|
||||
whiteSpace: 'pre-wrap',
|
||||
border: msg.role === 'assistant' ? `1px solid ${theme.border}` : 'none',
|
||||
}}>
|
||||
{msg.content}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{chatLoading && (
|
||||
<div style={{ display: 'flex', gap: 12 }}>
|
||||
<div style={{
|
||||
width: 32,
|
||||
height: 32,
|
||||
borderRadius: 8,
|
||||
background: theme.gradientAccent,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="12" cy="12" r="6" fill="#fff"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div style={{
|
||||
padding: '12px 16px',
|
||||
background: theme.bgElevated,
|
||||
borderRadius: 12,
|
||||
border: `1px solid ${theme.border}`,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 8,
|
||||
}}>
|
||||
<div style={{ width: 6, height: 6, borderRadius: '50%', background: theme.accent, animation: 'pulse 1s infinite' }} />
|
||||
<span style={{ fontSize: 13, color: theme.text2 }}>分析中...</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Quick Questions */}
|
||||
<div style={{
|
||||
padding: '12px 24px',
|
||||
display: 'flex',
|
||||
gap: 8,
|
||||
flexWrap: 'wrap',
|
||||
}}>
|
||||
{quickQuestions.map(q => (
|
||||
<button
|
||||
key={q}
|
||||
onClick={() => { setChatInput(q); }}
|
||||
style={{
|
||||
padding: '6px 12px',
|
||||
fontSize: 12,
|
||||
background: theme.bgHover,
|
||||
border: `1px solid ${theme.border}`,
|
||||
borderRadius: 6,
|
||||
color: theme.text2,
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
>{q}</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Chat Input */}
|
||||
<div style={{
|
||||
padding: '16px 24px',
|
||||
borderTop: `1px solid ${theme.border}`,
|
||||
display: 'flex',
|
||||
gap: 12,
|
||||
}}>
|
||||
<input
|
||||
value={chatInput}
|
||||
onChange={e => setChatInput(e.target.value)}
|
||||
onKeyDown={e => e.key === 'Enter' && sendChatMessage()}
|
||||
placeholder="输入问题..."
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: 12,
|
||||
fontSize: 14,
|
||||
background: theme.bgHover,
|
||||
border: `1px solid ${theme.border}`,
|
||||
borderRadius: 8,
|
||||
color: theme.text,
|
||||
outline: 'none',
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
onClick={sendChatMessage}
|
||||
disabled={chatLoading || !chatInput.trim()}
|
||||
style={{
|
||||
padding: '12px 20px',
|
||||
fontSize: 14,
|
||||
fontWeight: 600,
|
||||
background: chatLoading || !chatInput.trim() ? theme.bgHover : theme.gradientAccent,
|
||||
color: chatLoading || !chatInput.trim() ? theme.text3 : '#fff',
|
||||
border: 'none',
|
||||
borderRadius: 8,
|
||||
cursor: chatLoading || !chatInput.trim() ? 'not-allowed' : 'pointer',
|
||||
}}
|
||||
>发送</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
1916
frontend/src/pages/Compliance/CompliancePage.tsx
Normal file
1916
frontend/src/pages/Compliance/CompliancePage.tsx
Normal file
File diff suppressed because it is too large
Load Diff
2
frontend/src/pages/Compliance/index.ts
Normal file
2
frontend/src/pages/Compliance/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { CompliancePage } from './CompliancePage';
|
||||
export { ChatPanel } from './ChatPanel';
|
||||
668
frontend/src/pages/Docs/DocsPage.tsx
Normal file
668
frontend/src/pages/Docs/DocsPage.tsx
Normal file
@@ -0,0 +1,668 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
import { Content } from '../../components/layout/Content';
|
||||
import { TPattern } from '../../components/common/TPattern';
|
||||
import { getDocumentList, searchRegulations, uploadDocument, type RegulationSearchItem } from '../../api/docs';
|
||||
import type { Doc } from '../../types';
|
||||
|
||||
type PipelineStatus = 'idle' | 'running' | 'completed' | 'error';
|
||||
|
||||
const PIPELINE_STEPS = [
|
||||
{ name: 'LOAD' },
|
||||
{ name: 'PARSE' },
|
||||
{ name: 'CHUNK' },
|
||||
{ name: 'EMBED' },
|
||||
{ name: 'STORE' },
|
||||
];
|
||||
|
||||
const STEP_DURATION_MS = 700;
|
||||
|
||||
function wait(ms: number) {
|
||||
return new Promise<void>((resolve) => {
|
||||
window.setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
export const DocsPage: React.FC = () => {
|
||||
const { theme, isDark } = useTheme();
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const pipelineRunIdRef = useRef(0);
|
||||
|
||||
const [activeStep, setActiveStep] = useState<number>(-1);
|
||||
const [completedSteps, setCompletedSteps] = useState<number[]>([]);
|
||||
const [pipelineStatus, setPipelineStatus] = useState<PipelineStatus>('idle');
|
||||
const [docs, setDocs] = useState<Doc[]>([]);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [uploadFileName, setUploadFileName] = useState('');
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [searchQuery, setSearchQuery] = useState('新能源汽车电池安全要求');
|
||||
const [searchResults, setSearchResults] = useState<RegulationSearchItem[]>([]);
|
||||
const [searchLoading, setSearchLoading] = useState(false);
|
||||
const [searchError, setSearchError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
void loadDocuments();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
void runSearch(searchQuery);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
pipelineRunIdRef.current += 1;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const resetPipeline = (status: PipelineStatus = 'idle') => {
|
||||
pipelineRunIdRef.current += 1;
|
||||
setActiveStep(-1);
|
||||
setCompletedSteps([]);
|
||||
setPipelineStatus(status);
|
||||
};
|
||||
|
||||
const loadDocuments = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await getDocumentList();
|
||||
const apiDocs: Doc[] = response.docs.map((doc) => ({
|
||||
id: parseInt(String(doc.id).replace('doc-', ''), 10) || Math.floor(Math.random() * 10000),
|
||||
name: doc.name,
|
||||
chunks: doc.chunks,
|
||||
size: doc.size_text || `${((doc.chunks * 8) / 1024).toFixed(1)}MB`,
|
||||
status: doc.status === 'indexed' ? 'indexed' : 'parsing',
|
||||
docId: doc.id,
|
||||
downloadUrl: doc.download_url,
|
||||
}));
|
||||
setDocs(apiDocs);
|
||||
} catch (error) {
|
||||
console.error('Failed to load documents:', error);
|
||||
setDocs([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const runPipelineFlow = async (runId: number, uploadPromise: Promise<Awaited<ReturnType<typeof uploadDocument>>>) => {
|
||||
const guardedSetActiveStep = (step: number) => {
|
||||
if (pipelineRunIdRef.current !== runId) return false;
|
||||
setActiveStep(step);
|
||||
return true;
|
||||
};
|
||||
|
||||
const guardedCompleteStep = (step: number) => {
|
||||
if (pipelineRunIdRef.current !== runId) return false;
|
||||
setCompletedSteps((prev) => (prev.includes(step) ? prev : [...prev, step]));
|
||||
return true;
|
||||
};
|
||||
|
||||
for (let index = 0; index < PIPELINE_STEPS.length - 1; index += 1) {
|
||||
if (!guardedSetActiveStep(index)) return;
|
||||
await wait(STEP_DURATION_MS);
|
||||
if (!guardedCompleteStep(index)) return;
|
||||
}
|
||||
|
||||
if (!guardedSetActiveStep(PIPELINE_STEPS.length - 1)) return;
|
||||
await uploadPromise;
|
||||
if (!guardedCompleteStep(PIPELINE_STEPS.length - 1)) return;
|
||||
|
||||
await wait(240);
|
||||
if (pipelineRunIdRef.current !== runId) return;
|
||||
|
||||
setActiveStep(-1);
|
||||
setPipelineStatus('completed');
|
||||
};
|
||||
|
||||
const handleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (!file || uploading) return;
|
||||
|
||||
const runId = pipelineRunIdRef.current + 1;
|
||||
pipelineRunIdRef.current = runId;
|
||||
|
||||
setUploading(true);
|
||||
setUploadFileName(file.name);
|
||||
setActiveStep(-1);
|
||||
setCompletedSteps([]);
|
||||
setPipelineStatus('running');
|
||||
|
||||
const fileSizeMB = (file.size / (1024 * 1024)).toFixed(1);
|
||||
const tempDocId = `pending-${Date.now()}`;
|
||||
const newDoc: Doc = {
|
||||
id: Date.now(),
|
||||
name: file.name,
|
||||
chunks: 0,
|
||||
size: `${fileSizeMB}MB`,
|
||||
status: 'parsing',
|
||||
docId: tempDocId,
|
||||
};
|
||||
|
||||
setDocs((prev) => [newDoc, ...prev]);
|
||||
|
||||
const uploadPromise = uploadDocument(file);
|
||||
void runPipelineFlow(runId, uploadPromise);
|
||||
|
||||
try {
|
||||
const uploadRes = await uploadPromise;
|
||||
if (pipelineRunIdRef.current !== runId) return;
|
||||
|
||||
setDocs((prev) =>
|
||||
prev.map((doc) =>
|
||||
doc.id === newDoc.id
|
||||
? {
|
||||
...doc,
|
||||
status: 'indexed',
|
||||
docId: uploadRes.doc_id,
|
||||
chunks: uploadRes.num_chunks || doc.chunks,
|
||||
summary: uploadRes.summary,
|
||||
}
|
||||
: doc
|
||||
)
|
||||
);
|
||||
|
||||
setUploading(false);
|
||||
setUploadFileName('');
|
||||
void loadDocuments();
|
||||
} catch (error) {
|
||||
console.error('Upload failed:', error);
|
||||
if (pipelineRunIdRef.current !== runId) return;
|
||||
|
||||
setUploading(false);
|
||||
setUploadFileName('');
|
||||
setDocs((prev) => prev.filter((doc) => doc.id !== newDoc.id));
|
||||
setPipelineStatus('error');
|
||||
setActiveStep(-1);
|
||||
setCompletedSteps([]);
|
||||
} finally {
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = '';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const triggerFileUpload = () => {
|
||||
if (uploading) return;
|
||||
fileInputRef.current?.click();
|
||||
};
|
||||
|
||||
const handleDragOver = (event: React.DragEvent) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
const handleDrop = (event: React.DragEvent) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const files = event.dataTransfer.files;
|
||||
if (files.length === 0 || uploading) return;
|
||||
|
||||
const droppedFile = files[0];
|
||||
if (fileInputRef.current) {
|
||||
const dataTransfer = new DataTransfer();
|
||||
dataTransfer.items.add(droppedFile);
|
||||
fileInputRef.current.files = dataTransfer.files;
|
||||
}
|
||||
|
||||
void handleFileSelect({
|
||||
target: { files: [droppedFile] as unknown as FileList },
|
||||
} as React.ChangeEvent<HTMLInputElement>);
|
||||
};
|
||||
|
||||
const runSearch = async (query: string) => {
|
||||
if (!query.trim()) return;
|
||||
setSearchLoading(true);
|
||||
setSearchError('');
|
||||
try {
|
||||
const response = await searchRegulations(query.trim(), 8);
|
||||
setSearchResults(response.results);
|
||||
} catch (error) {
|
||||
console.error('Failed to search regulations:', error);
|
||||
setSearchError(error instanceof Error ? error.message : '检索失败');
|
||||
setSearchResults([]);
|
||||
} finally {
|
||||
setSearchLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const getStepStyle = (index: number) => {
|
||||
const isActive = activeStep === index;
|
||||
const isCompleted = completedSteps.includes(index);
|
||||
|
||||
if (isActive) {
|
||||
return {
|
||||
background: theme.bgCard,
|
||||
border: `2px solid ${theme.accent}`,
|
||||
boxShadow: `0 0 12px ${theme.accent}40`,
|
||||
};
|
||||
}
|
||||
|
||||
if (isCompleted) {
|
||||
return {
|
||||
background: theme.bgCard,
|
||||
border: `1px solid ${theme.green}`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
background: theme.bgCard,
|
||||
border: `1px solid ${theme.border}`,
|
||||
};
|
||||
};
|
||||
|
||||
const getCheckStyle = (index: number) => {
|
||||
const isActive = activeStep === index;
|
||||
const isCompleted = completedSteps.includes(index);
|
||||
|
||||
if (isActive) {
|
||||
return {
|
||||
background: theme.gradientAccent,
|
||||
color: '#fff',
|
||||
animation: 'pulse 0.6s infinite',
|
||||
};
|
||||
}
|
||||
|
||||
if (isCompleted) {
|
||||
return {
|
||||
background: theme.green,
|
||||
color: '#fff',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
background: theme.bgHover,
|
||||
color: theme.text3,
|
||||
};
|
||||
};
|
||||
|
||||
const getPipelineHint = () => {
|
||||
if (pipelineStatus === 'running') {
|
||||
return activeStep >= 0 ? `${PIPELINE_STEPS[activeStep].name} · ${uploadFileName}` : `LOAD · ${uploadFileName}`;
|
||||
}
|
||||
if (pipelineStatus === 'completed') {
|
||||
return 'PIPELINE COMPLETE';
|
||||
}
|
||||
if (pipelineStatus === 'error') {
|
||||
return 'PIPELINE FAILED';
|
||||
}
|
||||
return 'WAITING FOR UPLOAD';
|
||||
};
|
||||
|
||||
return (
|
||||
<Content>
|
||||
<TPattern />
|
||||
|
||||
<section style={{ marginBottom: 56 }}>
|
||||
<h2
|
||||
style={{
|
||||
fontSize: 14,
|
||||
fontWeight: 600,
|
||||
color: theme.accent,
|
||||
marginBottom: 20,
|
||||
letterSpacing: '1px',
|
||||
}}
|
||||
>
|
||||
UPLOAD
|
||||
</h2>
|
||||
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept=".pdf,.docx,.doc"
|
||||
onChange={handleFileSelect}
|
||||
style={{ display: 'none' }}
|
||||
/>
|
||||
|
||||
<div
|
||||
onClick={triggerFileUpload}
|
||||
onDragOver={handleDragOver}
|
||||
onDrop={handleDrop}
|
||||
style={{
|
||||
border: `2px solid ${uploading ? theme.accent : theme.border}`,
|
||||
borderRadius: 16,
|
||||
padding: 64,
|
||||
textAlign: 'center',
|
||||
background: theme.bgCard,
|
||||
transition: 'all 0.3s ease',
|
||||
cursor: uploading ? 'wait' : 'pointer',
|
||||
boxShadow: !isDark ? '0 4px 16px rgba(226,0,116,0.08)' : 'none',
|
||||
opacity: uploading ? 0.78 : 1,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: 80,
|
||||
height: 80,
|
||||
borderRadius: 20,
|
||||
background: theme.bgHover,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
margin: '0 auto 20px',
|
||||
}}
|
||||
>
|
||||
{uploading ? (
|
||||
<div style={{ animation: 'spin 1s linear infinite' }}>
|
||||
<svg width="36" height="36" viewBox="0 0 24 24" fill="none">
|
||||
<circle
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke={theme.accent}
|
||||
strokeWidth="2"
|
||||
strokeDasharray="60"
|
||||
strokeDashoffset="20"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
) : (
|
||||
<svg width="36" height="36" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M12 4L12 16M12 4L7 9M12 4L17 9" stroke={theme.accent} strokeWidth="2" strokeLinecap="round" />
|
||||
<path d="M4 18H20" stroke={theme.accent} strokeWidth="2" strokeLinecap="round" />
|
||||
</svg>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div style={{ fontSize: 16, fontWeight: 500, marginBottom: 8 }}>
|
||||
{uploading ? '正在上传并启动处理链路...' : '拖拽文件或点击上传'}
|
||||
</div>
|
||||
<div className="mono" style={{ fontSize: 12, color: theme.text3 }}>
|
||||
{uploading ? uploadFileName : 'PDF · DOCX · DOC · MAX 100MB'}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section style={{ marginBottom: 40 }}>
|
||||
<h2
|
||||
style={{
|
||||
fontSize: 14,
|
||||
fontWeight: 600,
|
||||
color: theme.accent,
|
||||
marginBottom: 20,
|
||||
letterSpacing: '1px',
|
||||
}}
|
||||
>
|
||||
PROCESSING PIPELINE
|
||||
</h2>
|
||||
|
||||
<div
|
||||
className="mono"
|
||||
style={{
|
||||
fontSize: 11,
|
||||
color:
|
||||
pipelineStatus === 'error'
|
||||
? '#d64545'
|
||||
: pipelineStatus === 'completed'
|
||||
? theme.green
|
||||
: theme.text3,
|
||||
letterSpacing: '1px',
|
||||
marginBottom: 12,
|
||||
}}
|
||||
>
|
||||
{getPipelineHint()}
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', gap: 16 }}>
|
||||
{PIPELINE_STEPS.map((step, index) => {
|
||||
const stepStyle = getStepStyle(index);
|
||||
const checkStyle = getCheckStyle(index);
|
||||
const arrowActive = activeStep > index || completedSteps.includes(index);
|
||||
const isCompleted = completedSteps.includes(index);
|
||||
const isActive = activeStep === index;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={step.name}
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: 20,
|
||||
textAlign: 'center',
|
||||
borderRadius: 12,
|
||||
position: 'relative',
|
||||
boxShadow: !isDark ? '0 2px 8px rgba(226,0,116,0.04)' : 'none',
|
||||
transition: 'all 0.3s ease',
|
||||
...stepStyle,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: 36,
|
||||
height: 36,
|
||||
borderRadius: 8,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
margin: '0 auto 12px',
|
||||
fontSize: 16,
|
||||
transition: 'all 0.3s ease',
|
||||
...checkStyle,
|
||||
}}
|
||||
>
|
||||
{isActive ? step.name : isCompleted ? '✓' : step.name}
|
||||
</div>
|
||||
|
||||
<div className="mono" style={{ fontSize: 12, fontWeight: 600 }}>
|
||||
{step.name}
|
||||
</div>
|
||||
<div className="mono" style={{ fontSize: 10, color: theme.text3, marginTop: 8 }}>
|
||||
{isCompleted ? 'DONE' : isActive ? 'RUNNING' : 'PENDING'}
|
||||
</div>
|
||||
|
||||
{index < PIPELINE_STEPS.length - 1 && (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
right: -8,
|
||||
top: '50%',
|
||||
transform: 'translateY(-50%)',
|
||||
color: arrowActive ? theme.green : theme.borderLight,
|
||||
fontWeight: arrowActive ? 700 : 400,
|
||||
opacity: arrowActive ? 1 : 0.45,
|
||||
transition: 'all 0.3s ease',
|
||||
}}
|
||||
>
|
||||
→
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 24, marginBottom: 56 }}>
|
||||
<div>
|
||||
<h2
|
||||
style={{
|
||||
fontSize: 14,
|
||||
fontWeight: 600,
|
||||
color: theme.accent,
|
||||
marginBottom: 20,
|
||||
letterSpacing: '1px',
|
||||
}}
|
||||
>
|
||||
文档管理清单 ({loading ? '...' : docs.length})
|
||||
</h2>
|
||||
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
{docs.map((doc) => (
|
||||
<div
|
||||
key={doc.id}
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
padding: 20,
|
||||
background: theme.bgCard,
|
||||
borderRadius: 12,
|
||||
border: `1px solid ${doc.status === 'parsing' ? theme.accent : theme.border}`,
|
||||
transition: 'all 0.2s ease',
|
||||
boxShadow: !isDark ? '0 2px 8px rgba(226,0,116,0.04)' : 'none',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
|
||||
<div
|
||||
style={{
|
||||
width: 44,
|
||||
height: 44,
|
||||
borderRadius: 10,
|
||||
background: theme.bgHover,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
|
||||
<path
|
||||
d="M14 2H6C5 2 4 3 4 4V20C4 21 5 22 6 22H18C19 22 20 21 20 20V8L14 2Z"
|
||||
stroke={theme.accent}
|
||||
strokeWidth="1.5"
|
||||
/>
|
||||
<path d="M14 2V8H20" stroke={theme.accent} strokeWidth="1.5" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div style={{ fontSize: 15, fontWeight: 500 }}>{doc.name}</div>
|
||||
<div className="mono" style={{ fontSize: 11, color: theme.text3 }}>
|
||||
{doc.size}
|
||||
{doc.docId ? ` · ${doc.docId}` : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 20 }}>
|
||||
{doc.downloadUrl && (
|
||||
<a
|
||||
href={doc.downloadUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
style={{ fontSize: 12, color: theme.accent, textDecoration: 'none' }}
|
||||
>
|
||||
下载
|
||||
</a>
|
||||
)}
|
||||
<div
|
||||
className="mono"
|
||||
style={{
|
||||
fontSize: 12,
|
||||
padding: '6px 12px',
|
||||
background: theme.bgHover,
|
||||
borderRadius: 6,
|
||||
color: theme.text2,
|
||||
}}
|
||||
>
|
||||
{doc.status === 'parsing' ? '处理中...' : `${doc.chunks} chunks`}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2
|
||||
style={{
|
||||
fontSize: 14,
|
||||
fontWeight: 600,
|
||||
color: theme.accent,
|
||||
marginBottom: 20,
|
||||
letterSpacing: '1px',
|
||||
}}
|
||||
>
|
||||
文档管理内法规检索
|
||||
</h2>
|
||||
|
||||
<div style={{ display: 'flex', gap: 10, marginBottom: 16 }}>
|
||||
<input
|
||||
value={searchQuery}
|
||||
onChange={(event) => setSearchQuery(event.target.value)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Enter') {
|
||||
void runSearch(searchQuery);
|
||||
}
|
||||
}}
|
||||
placeholder="输入法规关键词、条款或制度主题"
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: 12,
|
||||
fontSize: 14,
|
||||
background: theme.bgCard,
|
||||
border: `1px solid ${theme.border}`,
|
||||
borderRadius: 8,
|
||||
color: theme.text,
|
||||
outline: 'none',
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
onClick={() => void runSearch(searchQuery)}
|
||||
disabled={searchLoading || !searchQuery.trim()}
|
||||
style={{
|
||||
padding: '12px 18px',
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
background: searchLoading || !searchQuery.trim() ? theme.bgHover : theme.gradientAccent,
|
||||
color: searchLoading || !searchQuery.trim() ? theme.text3 : '#fff',
|
||||
border: 'none',
|
||||
borderRadius: 8,
|
||||
cursor: searchLoading || !searchQuery.trim() ? 'not-allowed' : 'pointer',
|
||||
}}
|
||||
>
|
||||
检索
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{searchError && (
|
||||
<div style={{ marginBottom: 12, fontSize: 13, color: '#d64545' }}>
|
||||
{searchError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
{searchResults.map((item) => (
|
||||
<div
|
||||
key={`${item.id}-${item.file}`}
|
||||
style={{
|
||||
padding: 18,
|
||||
background: theme.bgCard,
|
||||
borderRadius: 12,
|
||||
border: `1px solid ${theme.border}`,
|
||||
boxShadow: !isDark ? '0 2px 8px rgba(226,0,116,0.04)' : 'none',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 12, marginBottom: 6 }}>
|
||||
<div style={{ fontSize: 14, fontWeight: 600, color: theme.text }}>{item.file}</div>
|
||||
<div className="mono" style={{ fontSize: 11, color: theme.accent }}>
|
||||
{(item.score * 100).toFixed(1)}%
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mono" style={{ fontSize: 11, color: theme.text3, marginBottom: 8 }}>
|
||||
{item.clause}
|
||||
{item.tags.length > 0 ? ` · ${item.tags.join(' · ')}` : ''}
|
||||
</div>
|
||||
|
||||
<div style={{ fontSize: 12, color: theme.text2, lineHeight: 1.6 }}>{item.content}</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{!searchLoading && searchResults.length === 0 && (
|
||||
<div
|
||||
style={{
|
||||
padding: 24,
|
||||
borderRadius: 12,
|
||||
background: theme.bgCard,
|
||||
border: `1px solid ${theme.border}`,
|
||||
textAlign: 'center',
|
||||
color: theme.text3,
|
||||
}}
|
||||
>
|
||||
暂无检索结果
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</Content>
|
||||
);
|
||||
};
|
||||
1
frontend/src/pages/Docs/index.ts
Normal file
1
frontend/src/pages/Docs/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { DocsPage } from './DocsPage';
|
||||
700
frontend/src/pages/RagChat/RagChatPage.tsx
Normal file
700
frontend/src/pages/RagChat/RagChatPage.tsx
Normal file
@@ -0,0 +1,700 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
import type { ChatMessage, RetrievalData } from '../../types';
|
||||
import { getQuickQuestions, ragChat } from '../../api/rag';
|
||||
|
||||
const ragQuickQuestionsDefault = [
|
||||
'电动自行车上路需要什么条件?',
|
||||
'驾驶证如何申请?',
|
||||
'超速行驶如何处罚?',
|
||||
'车辆年检有哪些规定?',
|
||||
'电动汽车电池安全标准?',
|
||||
'正面碰撞测试要求?',
|
||||
'AEB系统测试标准?',
|
||||
'高速公路安全距离?',
|
||||
];
|
||||
|
||||
export const RagChatPage: React.FC = () => {
|
||||
const { theme } = useTheme();
|
||||
const [messages, setMessages] = useState<ChatMessage[]>([]);
|
||||
const [retrievals, setRetrievals] = useState<RetrievalData[]>([]);
|
||||
const [input, setInput] = useState<string>('');
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [showClearConfirm, setShowClearConfirm] = useState<boolean>(false);
|
||||
const [selectedRetrieval, setSelectedRetrieval] = useState<RetrievalData | null>(null);
|
||||
const [quickQuestions, setQuickQuestions] = useState<string[]>(ragQuickQuestionsDefault);
|
||||
|
||||
useEffect(() => {
|
||||
void loadQuickQuestions();
|
||||
}, []);
|
||||
|
||||
const loadQuickQuestions = async () => {
|
||||
try {
|
||||
const response = await getQuickQuestions();
|
||||
setQuickQuestions(response.questions.map(q => q.question));
|
||||
} catch (error) {
|
||||
console.error('Failed to load quick questions:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const sendMessage = (text: string) => {
|
||||
if (!text.trim()) return;
|
||||
|
||||
const userMsg = { id: Date.now(), role: 'user' as const, content: text };
|
||||
setMessages((prev) => [...prev, userMsg]);
|
||||
setInput('');
|
||||
setLoading(true);
|
||||
setRetrievals([]);
|
||||
|
||||
let currentResponse = '';
|
||||
|
||||
void ragChat(
|
||||
text,
|
||||
5,
|
||||
(data: unknown) => {
|
||||
const sseData = data as {
|
||||
type: string;
|
||||
text?: string;
|
||||
docs?: Array<{
|
||||
id: string;
|
||||
score: number;
|
||||
preview: string;
|
||||
doc_name: string;
|
||||
clause: string;
|
||||
doc_id?: string;
|
||||
download_url?: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
if (sseData.type === 'retrieved' && sseData.docs) {
|
||||
const retrievedDocs: RetrievalData[] = sseData.docs.map(d => ({
|
||||
id: parseInt(d.id.replace('chunk-', ''), 10) || 1,
|
||||
file: d.doc_name,
|
||||
clause: d.clause,
|
||||
score: d.score,
|
||||
content: d.preview,
|
||||
docId: d.doc_id,
|
||||
downloadUrl: d.download_url,
|
||||
}));
|
||||
setRetrievals(retrievedDocs);
|
||||
} else if (sseData.type === 'chunk' && sseData.text) {
|
||||
currentResponse += sseData.text;
|
||||
setMessages((prev) => {
|
||||
const lastMsg = prev[prev.length - 1];
|
||||
if (lastMsg?.role === 'assistant') {
|
||||
return [...prev.slice(0, -1), { ...lastMsg, content: currentResponse }];
|
||||
}
|
||||
return [...prev, { id: Date.now() + 1, role: 'assistant' as const, content: currentResponse }];
|
||||
});
|
||||
} else if (sseData.type === 'done') {
|
||||
setLoading(false);
|
||||
} else if (sseData.type === 'error') {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
(error: Error) => {
|
||||
console.error('RAG chat error:', error);
|
||||
setLoading(false);
|
||||
setMessages((prev) => [
|
||||
...prev,
|
||||
{ id: Date.now() + 1, role: 'assistant' as const, content: '抱歉,连接服务器时出错,请稍后再试。' }
|
||||
]);
|
||||
},
|
||||
() => {
|
||||
setLoading(false);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const clearMessages = () => {
|
||||
setMessages([]);
|
||||
setRetrievals([]);
|
||||
setShowClearConfirm(false);
|
||||
};
|
||||
|
||||
const regenerateLastAnswer = () => {
|
||||
if (messages.length < 2) return;
|
||||
const lastUserMsg = messages.filter((m) => m.role === 'user').pop();
|
||||
if (!lastUserMsg) return;
|
||||
|
||||
setLoading(true);
|
||||
setMessages((prev) => [...prev.slice(0, -1)]);
|
||||
setRetrievals([]);
|
||||
|
||||
let currentResponse = '';
|
||||
|
||||
void ragChat(
|
||||
lastUserMsg.content,
|
||||
5,
|
||||
(data: unknown) => {
|
||||
const sseData = data as {
|
||||
type: string;
|
||||
text?: string;
|
||||
docs?: Array<{
|
||||
id: string;
|
||||
score: number;
|
||||
preview: string;
|
||||
doc_name: string;
|
||||
clause: string;
|
||||
doc_id?: string;
|
||||
download_url?: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
if (sseData.type === 'retrieved' && sseData.docs) {
|
||||
const retrievedDocs: RetrievalData[] = sseData.docs.map(d => ({
|
||||
id: parseInt(d.id.replace('chunk-', ''), 10) || 1,
|
||||
file: d.doc_name,
|
||||
clause: d.clause,
|
||||
score: d.score,
|
||||
content: d.preview,
|
||||
docId: d.doc_id,
|
||||
downloadUrl: d.download_url,
|
||||
}));
|
||||
setRetrievals(retrievedDocs);
|
||||
} else if (sseData.type === 'chunk' && sseData.text) {
|
||||
currentResponse += sseData.text;
|
||||
setMessages((prev) => {
|
||||
const lastMsg = prev[prev.length - 1];
|
||||
if (lastMsg?.role === 'assistant') {
|
||||
return [...prev.slice(0, -1), { ...lastMsg, content: currentResponse }];
|
||||
}
|
||||
return [...prev, { id: Date.now() + 1, role: 'assistant' as const, content: currentResponse }];
|
||||
});
|
||||
} else if (sseData.type === 'done') {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
(error: Error) => {
|
||||
console.error('RAG chat error:', error);
|
||||
setLoading(false);
|
||||
setMessages((prev) => [
|
||||
...prev,
|
||||
{ id: Date.now() + 1, role: 'assistant' as const, content: '抱歉,连接服务器时出错,请稍后再试。' }
|
||||
]);
|
||||
},
|
||||
() => {
|
||||
setLoading(false);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
flex: 1,
|
||||
display: 'flex',
|
||||
height: 'calc(100vh - 128px)',
|
||||
}}>
|
||||
<div style={{
|
||||
flex: '0 0 60%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
borderRight: `1px solid ${theme.border}`,
|
||||
}}>
|
||||
<div style={{
|
||||
flex: 1,
|
||||
overflowY: 'auto',
|
||||
padding: '24px 32px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 20,
|
||||
}}>
|
||||
{messages.length === 0 ? (
|
||||
<div style={{
|
||||
textAlign: 'center',
|
||||
padding: 60,
|
||||
color: theme.text3,
|
||||
}}>
|
||||
<div style={{
|
||||
width: 72,
|
||||
height: 72,
|
||||
borderRadius: 16,
|
||||
background: theme.bgCard,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
margin: '0 auto 20px',
|
||||
border: `1px solid ${theme.border}`,
|
||||
}}>
|
||||
<svg width="28" height="28" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" stroke={theme.accent} strokeWidth="1.5"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div style={{ fontSize: 15, fontWeight: 500, marginBottom: 6, color: theme.text }}>开始法规对话</div>
|
||||
<div className="mono" style={{ fontSize: 11 }}>选择快捷问题或输入您的问题</div>
|
||||
</div>
|
||||
) : (
|
||||
messages.map(msg => (
|
||||
<div key={msg.id} style={{
|
||||
display: 'flex',
|
||||
gap: 12,
|
||||
flexDirection: msg.role === 'user' ? 'row-reverse' : 'row',
|
||||
}}>
|
||||
{msg.role === 'assistant' && (
|
||||
<div style={{
|
||||
width: 32,
|
||||
height: 32,
|
||||
borderRadius: 8,
|
||||
background: theme.gradientAccent,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
flexShrink: 0,
|
||||
}}>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="12" cy="12" r="6" fill="#fff"/>
|
||||
</svg>
|
||||
</div>
|
||||
)}
|
||||
<div style={{
|
||||
maxWidth: '80%',
|
||||
padding: msg.role === 'user' ? '12px 18px' : '14px 18px',
|
||||
background: msg.role === 'user' ? theme.gradientAccent : theme.bgCard,
|
||||
borderRadius: 12,
|
||||
color: msg.role === 'user' ? '#fff' : theme.text,
|
||||
fontSize: 14,
|
||||
lineHeight: 1.6,
|
||||
whiteSpace: 'pre-wrap',
|
||||
border: msg.role === 'assistant' ? `1px solid ${theme.border}` : 'none',
|
||||
}}>
|
||||
{msg.content}
|
||||
{msg.role === 'assistant' && msg.retrievalIds && msg.retrievalIds.length > 0 && (
|
||||
<div style={{
|
||||
marginTop: 10,
|
||||
paddingTop: 10,
|
||||
borderTop: `1px solid ${theme.border}`,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 6,
|
||||
}}>
|
||||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M14 2H6C5 2 4 3 4 4V20C4 21 5 22 6 22H18C19 22 20 21 20 20V8L14 2Z" stroke={theme.accent} strokeWidth="1.5"/>
|
||||
</svg>
|
||||
<span className="mono" style={{ fontSize: 11, color: theme.accent }}>
|
||||
{msg.retrievalIds.length} 个法规引用
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
{loading && (
|
||||
<div style={{ display: 'flex', gap: 12 }}>
|
||||
<div style={{
|
||||
width: 32,
|
||||
height: 32,
|
||||
borderRadius: 8,
|
||||
background: theme.gradientAccent,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="12" cy="12" r="6" fill="#fff"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div style={{
|
||||
padding: '14px 18px',
|
||||
background: theme.bgCard,
|
||||
borderRadius: 12,
|
||||
border: `1px solid ${theme.border}`,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 8,
|
||||
}}>
|
||||
<div style={{
|
||||
width: 6,
|
||||
height: 6,
|
||||
borderRadius: '50%',
|
||||
background: theme.accent,
|
||||
animation: 'pulse 1s infinite',
|
||||
}} />
|
||||
<span style={{ fontSize: 13, color: theme.text2 }}>检索中...</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div style={{
|
||||
padding: '16px 32px 20px',
|
||||
background: theme.bg,
|
||||
borderTop: `1px solid ${theme.border}`,
|
||||
}}>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
gap: 8,
|
||||
marginBottom: 12,
|
||||
flexWrap: 'wrap',
|
||||
}}>
|
||||
{quickQuestions.map(q => (
|
||||
<button
|
||||
key={q}
|
||||
onClick={() => sendMessage(q)}
|
||||
style={{
|
||||
padding: '6px 14px',
|
||||
fontSize: 12,
|
||||
background: theme.bgCard,
|
||||
border: `1px solid ${theme.border}`,
|
||||
borderRadius: 6,
|
||||
color: theme.text2,
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
>{q}</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', gap: 10 }}>
|
||||
<input
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
onKeyDown={(e) => e.key === 'Enter' && sendMessage(input)}
|
||||
placeholder="输入法规问题..."
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: 12,
|
||||
fontSize: 14,
|
||||
background: theme.bgCard,
|
||||
border: `1px solid ${theme.border}`,
|
||||
borderRadius: 8,
|
||||
color: theme.text,
|
||||
outline: 'none',
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
onClick={() => sendMessage(input)}
|
||||
disabled={loading || !input.trim()}
|
||||
style={{
|
||||
padding: '12px 24px',
|
||||
fontSize: 14,
|
||||
fontWeight: 600,
|
||||
background: loading || !input.trim() ? theme.bgHover : theme.gradientAccent,
|
||||
color: loading || !input.trim() ? theme.text3 : '#fff',
|
||||
border: 'none',
|
||||
borderRadius: 8,
|
||||
cursor: loading || !input.trim() ? 'not-allowed' : 'pointer',
|
||||
}}
|
||||
>发送</button>
|
||||
{messages.length > 0 && (
|
||||
<button
|
||||
onClick={() => setShowClearConfirm(true)}
|
||||
style={{
|
||||
padding: '12px 16px',
|
||||
fontSize: 13,
|
||||
background: theme.bgCard,
|
||||
border: `1px solid ${theme.border}`,
|
||||
borderRadius: 8,
|
||||
color: theme.text2,
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
>清空</button>
|
||||
)}
|
||||
{messages.filter(m => m.role === 'assistant').length > 0 && (
|
||||
<button
|
||||
onClick={regenerateLastAnswer}
|
||||
disabled={loading}
|
||||
style={{
|
||||
padding: '12px 16px',
|
||||
fontSize: 13,
|
||||
background: theme.bgCard,
|
||||
border: `1px solid ${theme.border}`,
|
||||
borderRadius: 8,
|
||||
color: theme.text2,
|
||||
cursor: loading ? 'not-allowed' : 'pointer',
|
||||
}}
|
||||
>重生成</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{
|
||||
flex: '0 0 40%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
background: theme.bgCard,
|
||||
}}>
|
||||
<div style={{
|
||||
padding: '20px 24px',
|
||||
borderBottom: `1px solid ${theme.border}`,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 10,
|
||||
}}>
|
||||
<div style={{
|
||||
width: 28,
|
||||
height: 28,
|
||||
borderRadius: 6,
|
||||
background: theme.gradientAccent,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M14 2H6C5 2 4 3 4 4V20C4 21 5 22 6 22H18C19 22 20 21 20 20V8L14 2Z" stroke="#fff" strokeWidth="1.5"/>
|
||||
</svg>
|
||||
</div>
|
||||
<span className="mono" style={{ fontSize: 12, fontWeight: 600, color: theme.accent, letterSpacing: '1px' }}>
|
||||
RETRIEVED FRAGMENTS
|
||||
</span>
|
||||
{retrievals.length > 0 && (
|
||||
<span className="mono" style={{
|
||||
fontSize: 11,
|
||||
padding: '4px 10px',
|
||||
background: theme.bgHover,
|
||||
borderRadius: 4,
|
||||
color: theme.text3,
|
||||
}}>{retrievals.length}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div style={{
|
||||
flex: 1,
|
||||
overflowY: 'auto',
|
||||
padding: '16px 24px',
|
||||
}}>
|
||||
{retrievals.length > 0 ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
{retrievals.map((r, i) => (
|
||||
<div
|
||||
key={r.id}
|
||||
onClick={() => setSelectedRetrieval(r)}
|
||||
style={{
|
||||
padding: 16,
|
||||
background: theme.bgHover,
|
||||
borderRadius: 10,
|
||||
border: `1px solid ${theme.border}`,
|
||||
cursor: 'pointer',
|
||||
position: 'relative',
|
||||
}}
|
||||
>
|
||||
<div style={{
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
top: 16,
|
||||
bottom: 16,
|
||||
width: 3,
|
||||
background: theme.gradientAccent,
|
||||
borderRadius: 2,
|
||||
}} />
|
||||
<div style={{ paddingLeft: 8 }}>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
marginBottom: 8,
|
||||
}}>
|
||||
<span className="mono" style={{ fontSize: 11, fontWeight: 700, color: theme.accent }}>#{i + 1}</span>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
||||
{r.downloadUrl && (
|
||||
<a
|
||||
href={r.downloadUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
style={{ fontSize: 11, color: theme.accent, textDecoration: 'none' }}
|
||||
>
|
||||
下载文档
|
||||
</a>
|
||||
)}
|
||||
<span className="mono" style={{
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
color: theme.accent,
|
||||
}}>{(r.score * 100).toFixed(0)}%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ fontSize: 13, fontWeight: 500, marginBottom: 4, color: theme.text }}>{r.file}</div>
|
||||
<div className="mono" style={{ fontSize: 11, color: theme.text3, marginBottom: 8 }}>
|
||||
{r.clause}{r.docId ? ` · ${r.docId}` : ''}
|
||||
</div>
|
||||
<div style={{
|
||||
fontSize: 12,
|
||||
color: theme.text2,
|
||||
lineHeight: 1.5,
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
}}>{r.content}</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{
|
||||
textAlign: 'center',
|
||||
padding: 40,
|
||||
color: theme.text3,
|
||||
}}>
|
||||
<div style={{
|
||||
width: 48,
|
||||
height: 48,
|
||||
borderRadius: 10,
|
||||
background: theme.bgHover,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
margin: '0 auto 16px',
|
||||
}}>
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M14 2H6C5 2 4 3 4 4V20C4 21 5 22 6 22H18C19 22 20 21 20 20V8L14 2Z" stroke={theme.text3} strokeWidth="1.5"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div className="mono" style={{ fontSize: 11 }}>对话后显示相关法规</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{showClearConfirm && (
|
||||
<div style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
background: 'rgba(0,0,0,0.6)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
zIndex: 1000,
|
||||
}}>
|
||||
<div style={{
|
||||
padding: 24,
|
||||
background: theme.bgCard,
|
||||
borderRadius: 16,
|
||||
maxWidth: 400,
|
||||
border: `1px solid ${theme.border}`,
|
||||
}}>
|
||||
<div style={{ fontSize: 15, fontWeight: 600, marginBottom: 12, color: theme.text }}>确定清空对话?</div>
|
||||
<div style={{ fontSize: 13, color: theme.text2, marginBottom: 20 }}>此操作不可恢复</div>
|
||||
<div style={{ display: 'flex', gap: 10, justifyContent: 'flex-end' }}>
|
||||
<button
|
||||
onClick={() => setShowClearConfirm(false)}
|
||||
style={{
|
||||
padding: '10px 18px',
|
||||
fontSize: 13,
|
||||
background: theme.bgHover,
|
||||
border: 'none',
|
||||
borderRadius: 8,
|
||||
color: theme.text2,
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
>取消</button>
|
||||
<button
|
||||
onClick={clearMessages}
|
||||
style={{
|
||||
padding: '10px 18px',
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
background: theme.accent,
|
||||
border: 'none',
|
||||
borderRadius: 8,
|
||||
color: '#fff',
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
>确认</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selectedRetrieval && (
|
||||
<div
|
||||
onClick={() => setSelectedRetrieval(null)}
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
background: 'rgba(0,0,0,0.6)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
zIndex: 1000,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
style={{
|
||||
width: 520,
|
||||
maxWidth: '90%',
|
||||
maxHeight: '80%',
|
||||
padding: 24,
|
||||
background: theme.bgCard,
|
||||
borderRadius: 16,
|
||||
border: `1px solid ${theme.accent}`,
|
||||
boxShadow: '0 8px 32px rgba(0,0,0,0.3)',
|
||||
}}
|
||||
>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
marginBottom: 16,
|
||||
}}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
|
||||
<div style={{
|
||||
padding: '4px 10px',
|
||||
background: theme.gradientAccent,
|
||||
borderRadius: 6,
|
||||
}}>
|
||||
<span className="mono" style={{ fontSize: 11, fontWeight: 600, color: '#fff' }}>
|
||||
{(selectedRetrieval.score * 100).toFixed(0)}%
|
||||
</span>
|
||||
</div>
|
||||
<span style={{ fontSize: 14, fontWeight: 600, color: theme.text }}>{selectedRetrieval.file}</span>
|
||||
{selectedRetrieval.downloadUrl && (
|
||||
<a
|
||||
href={selectedRetrieval.downloadUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
style={{ fontSize: 12, color: theme.accent, textDecoration: 'none' }}
|
||||
>
|
||||
下载关联文档
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setSelectedRetrieval(null)}
|
||||
style={{
|
||||
width: 28,
|
||||
height: 28,
|
||||
background: theme.bgHover,
|
||||
border: 'none',
|
||||
borderRadius: 6,
|
||||
cursor: 'pointer',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M18 6L6 18M6 6L18 18" stroke={theme.text3} strokeWidth="2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div style={{
|
||||
padding: '10px 14px',
|
||||
background: theme.bgHover,
|
||||
borderRadius: 8,
|
||||
marginBottom: 16,
|
||||
}}>
|
||||
<span className="mono" style={{ fontSize: 12, color: theme.accent }}>{selectedRetrieval.clause}</span>
|
||||
{selectedRetrieval.docId && (
|
||||
<span className="mono" style={{ fontSize: 11, color: theme.text3, marginLeft: 8 }}>{selectedRetrieval.docId}</span>
|
||||
)}
|
||||
</div>
|
||||
<div style={{
|
||||
fontSize: 14,
|
||||
lineHeight: 1.7,
|
||||
color: theme.text2,
|
||||
whiteSpace: 'pre-wrap',
|
||||
}}>{selectedRetrieval.content}</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
1
frontend/src/pages/RagChat/index.ts
Normal file
1
frontend/src/pages/RagChat/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { RagChatPage } from './RagChatPage';
|
||||
257
frontend/src/pages/Status/StatusPage.tsx
Normal file
257
frontend/src/pages/Status/StatusPage.tsx
Normal file
@@ -0,0 +1,257 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
import { Content } from '../../components/layout/Content';
|
||||
import { TPattern } from '../../components/common/TPattern';
|
||||
import { getSystemStats, getSystemConfig, type SystemStats, type SystemConfig } from '../../api/status';
|
||||
import { getDocumentList, type DocInfo } from '../../api/docs';
|
||||
|
||||
const StatsCard = ({ label, value, accent = false }: {
|
||||
label: string;
|
||||
value: number;
|
||||
accent?: boolean;
|
||||
}) => {
|
||||
const { theme, isDark } = useTheme();
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
padding: 20,
|
||||
background: theme.bgCard,
|
||||
borderRadius: 12,
|
||||
border: `1px solid ${accent ? theme.accent : theme.border}`,
|
||||
position: 'relative',
|
||||
overflow: 'hidden',
|
||||
boxShadow: !isDark ? '0 2px 8px rgba(226,0,116,0.06)' : 'none',
|
||||
}}>
|
||||
<div style={{
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: 3,
|
||||
background: theme.gradientAccent,
|
||||
}} />
|
||||
<div className="mono" style={{ fontSize: 11, color: theme.text3, marginBottom: 8, letterSpacing: '1px' }}>{label}</div>
|
||||
<div className="mono" style={{ fontSize: 32, fontWeight: 700, color: accent ? theme.accent : theme.text }}>{value}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const StatusPage: React.FC = () => {
|
||||
const { theme, isDark } = useTheme();
|
||||
const [stats, setStats] = useState<SystemStats>({ docs: 0, chunks: 0, vectors: 0, segments: 0 });
|
||||
const [config, setConfig] = useState<SystemConfig | null>(null);
|
||||
const [docs, setDocs] = useState<DocInfo[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, []);
|
||||
|
||||
const loadData = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const [statsRes, configRes, docsRes] = await Promise.all([
|
||||
getSystemStats(),
|
||||
getSystemConfig(),
|
||||
getDocumentList(),
|
||||
]);
|
||||
setStats(statsRes);
|
||||
setConfig(configRes);
|
||||
setDocs(docsRes.docs);
|
||||
} catch (error) {
|
||||
console.error('Failed to load status data:', error);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
// 计算总chunks
|
||||
const totalChunks = docs.reduce((sum, d) => sum + d.chunks, 0);
|
||||
|
||||
return (
|
||||
<Content>
|
||||
<TPattern />
|
||||
{/* System Stats */}
|
||||
<section style={{ marginBottom: 48 }}>
|
||||
<div style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'repeat(4, 1fr)',
|
||||
gap: 16,
|
||||
}}>
|
||||
<StatsCard label="DOCUMENTS" value={stats.docs} />
|
||||
<StatsCard label="CHUNKS" value={stats.chunks} />
|
||||
<StatsCard label="DIMENSIONS" value={config?.embedding.dimension || 1536} />
|
||||
<StatsCard label="CLAUSES" value={stats.vectors} accent />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Configuration */}
|
||||
<section style={{ marginBottom: 48 }}>
|
||||
<h2 style={{
|
||||
fontSize: 14,
|
||||
fontWeight: 600,
|
||||
color: theme.accent,
|
||||
marginBottom: 20,
|
||||
letterSpacing: '1px',
|
||||
}}>SYSTEM CONFIGURATION</h2>
|
||||
|
||||
{/* ChromaDB Config */}
|
||||
<div style={{ marginBottom: 20 }}>
|
||||
<div className="mono" style={{ fontSize: 11, color: theme.text3, marginBottom: 12, letterSpacing: '1px' }}>VECTOR DATABASE</div>
|
||||
<div style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: '1fr 1fr 1fr',
|
||||
gap: 12,
|
||||
}}>
|
||||
{[
|
||||
['Vector DB', 'Milvus'],
|
||||
['Host', config?.milvus.host || 'localhost'],
|
||||
['Port', String(config?.milvus.port || 19530)],
|
||||
].map(([k, v]) => (
|
||||
<div key={k} style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
padding: 16,
|
||||
background: theme.bgCard,
|
||||
borderRadius: 10,
|
||||
border: `1px solid ${theme.border}`,
|
||||
boxShadow: !isDark ? '0 2px 8px rgba(226,0,116,0.04)' : 'none',
|
||||
}}>
|
||||
<span className="mono" style={{ fontSize: 12, color: theme.text3 }}>{k}</span>
|
||||
<span style={{ fontSize: 14, fontWeight: 500 }}>{v}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* LLM Config */}
|
||||
<div style={{ marginBottom: 20 }}>
|
||||
<div className="mono" style={{ fontSize: 11, color: theme.text3, marginBottom: 12, letterSpacing: '1px' }}>LLM CONFIGURATION</div>
|
||||
<div style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: '1fr 1fr',
|
||||
gap: 12,
|
||||
}}>
|
||||
{[
|
||||
['LLM Model', config?.llm.model || 'qwen-max'],
|
||||
['Embedding Model', config?.embedding.model || 'text-embedding-v3'],
|
||||
['Embedding Dim', String(config?.embedding.dimension || 1536)],
|
||||
['Temperature', '0.1'],
|
||||
].map(([k, v]) => (
|
||||
<div key={k} style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
padding: 16,
|
||||
background: theme.bgCard,
|
||||
borderRadius: 10,
|
||||
border: `1px solid ${theme.border}`,
|
||||
boxShadow: !isDark ? '0 2px 8px rgba(226,0,116,0.04)' : 'none',
|
||||
}}>
|
||||
<span className="mono" style={{ fontSize: 12, color: theme.text3 }}>{k}</span>
|
||||
<span style={{ fontSize: 14, fontWeight: 500 }}>{v}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Retrieval Config */}
|
||||
<div style={{ marginBottom: 20 }}>
|
||||
<div className="mono" style={{ fontSize: 11, color: theme.text3, marginBottom: 12, letterSpacing: '1px' }}>RETRIEVAL CONFIGURATION (HYBRID)</div>
|
||||
<div style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: '1fr 1fr 1fr',
|
||||
gap: 12,
|
||||
}}>
|
||||
{[
|
||||
['Vector Top-K', String(config?.retrieval.vector_top_k || 10)],
|
||||
['BM25 Top-K', '10'],
|
||||
['Final Top-K', String(config?.retrieval.final_top_k || 5)],
|
||||
].map(([k, v]) => (
|
||||
<div key={k} style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
padding: 16,
|
||||
background: theme.bgCard,
|
||||
borderRadius: 10,
|
||||
border: `1px solid ${theme.border}`,
|
||||
boxShadow: !isDark ? '0 2px 8px rgba(226,0,116,0.04)' : 'none',
|
||||
}}>
|
||||
<span className="mono" style={{ fontSize: 12, color: theme.text3 }}>{k}</span>
|
||||
<span style={{ fontSize: 14, fontWeight: 500 }}>{v}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Chunk Config */}
|
||||
<div>
|
||||
<div className="mono" style={{ fontSize: 11, color: theme.text3, marginBottom: 12, letterSpacing: '1px' }}>CHUNK CONFIGURATION</div>
|
||||
<div style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: '1fr 1fr',
|
||||
gap: 12,
|
||||
}}>
|
||||
{[
|
||||
['Chunk Size', '800'],
|
||||
['Chunk Overlap', '100'],
|
||||
].map(([k, v]) => (
|
||||
<div key={k} style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
padding: 16,
|
||||
background: theme.bgCard,
|
||||
borderRadius: 10,
|
||||
border: `1px solid ${theme.border}`,
|
||||
boxShadow: !isDark ? '0 2px 8px rgba(226,0,116,0.04)' : 'none',
|
||||
}}>
|
||||
<span className="mono" style={{ fontSize: 12, color: theme.text3 }}>{k}</span>
|
||||
<span style={{ fontSize: 14, fontWeight: 500 }}>{v}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Indexed Docs Overview */}
|
||||
<section>
|
||||
<h2 style={{
|
||||
fontSize: 14,
|
||||
fontWeight: 600,
|
||||
color: theme.accent,
|
||||
marginBottom: 20,
|
||||
letterSpacing: '1px',
|
||||
}}>DOCUMENT INDEX</h2>
|
||||
{docs.map(d => (
|
||||
<div key={d.id} style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
padding: 16,
|
||||
background: theme.bgCard,
|
||||
borderRadius: 10,
|
||||
marginBottom: 10,
|
||||
border: `1px solid ${theme.border}`,
|
||||
}}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||
<span style={{ fontSize: 14 }}>{d.name}</span>
|
||||
<span className="mono" style={{ fontSize: 11, color: theme.text3 }}>{(d.chunks * 8 / 1024).toFixed(1)}MB</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
|
||||
<span className="mono" style={{ fontSize: 12, color: theme.text2 }}>{d.chunks} chunks</span>
|
||||
<div style={{
|
||||
padding: '4px 12px',
|
||||
background: theme.green,
|
||||
borderRadius: 6,
|
||||
}}>
|
||||
<span className="mono" style={{ fontSize: 10, fontWeight: 600, color: '#fff' }}>INDEXED</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
</Content>
|
||||
);
|
||||
};
|
||||
1
frontend/src/pages/Status/index.ts
Normal file
1
frontend/src/pages/Status/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { StatusPage } from './StatusPage';
|
||||
274
frontend/src/styles/globals.css
Normal file
274
frontend/src/styles/globals.css
Normal file
@@ -0,0 +1,274 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=TeleNeo:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
|
||||
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
/* Light mode (default) */
|
||||
:root {
|
||||
--t-bg: #ffffff;
|
||||
--t-bg-card: #ffffff;
|
||||
--t-bg-hover: #f8f8fc;
|
||||
--t-bg-elevated: #fafafa;
|
||||
--t-border: #e8e8f0;
|
||||
--t-border-light: #d0d0d8;
|
||||
--t-text: #1a1a2e;
|
||||
--t-text2: #4a4a5a;
|
||||
--t-text3: #7a7a8a;
|
||||
--t-green: #00b89c;
|
||||
--t-orange: #ff7700;
|
||||
--t-accent-glow: rgba(226,0,116,0.08);
|
||||
--t-pattern-opacity: 0.04;
|
||||
}
|
||||
|
||||
/* Dark mode */
|
||||
.dark {
|
||||
--t-bg: #0a0a12;
|
||||
--t-bg-card: #12121f;
|
||||
--t-bg-hover: #1a1a2e;
|
||||
--t-bg-elevated: #1e1e30;
|
||||
--t-border: #2a2a40;
|
||||
--t-border-light: #4a4a60;
|
||||
--t-text: #ffffff;
|
||||
--t-text2: #c0c0d0;
|
||||
--t-text3: #9a9aaa;
|
||||
--t-green: #00d4aa;
|
||||
--t-orange: #ff8800;
|
||||
--t-accent-glow: rgba(226,0,116,0.12);
|
||||
--t-pattern-opacity: 0.03;
|
||||
}
|
||||
|
||||
/* Base styles */
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html, body, #root {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'TeleNeo', 'Segoe UI', system-ui, sans-serif;
|
||||
overflow-x: hidden;
|
||||
font-feature-settings: 'kern' 1;
|
||||
color: #1a1a2e;
|
||||
background: #ffffff;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
/* Dark mode body */
|
||||
.dark body,
|
||||
body.dark-mode {
|
||||
color: #fff;
|
||||
background: #0a0a12;
|
||||
}
|
||||
|
||||
/* Selection */
|
||||
::selection {
|
||||
background: rgba(226, 0, 116, 0.3);
|
||||
}
|
||||
|
||||
/* Scrollbar */
|
||||
::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: linear-gradient(180deg, #e20074, #be0060);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Monospace font class */
|
||||
.mono {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
}
|
||||
|
||||
/* Smooth transitions for theme */
|
||||
* {
|
||||
transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
|
||||
}
|
||||
|
||||
/* Exclude buttons from auto-transition for custom hover effects */
|
||||
button, input {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
/* T-Systems Button Style */
|
||||
.t-btn,
|
||||
.t-btn:hover {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.t-btn {
|
||||
background: linear-gradient(135deg, #e20074 0%, #be0060 100%);
|
||||
}
|
||||
|
||||
.t-btn:hover {
|
||||
background: linear-gradient(135deg, #f0208a 0%, #d01070 100%);
|
||||
box-shadow: 0 4px 20px rgba(226,0,116,0.4);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
/* T-Systems Gradient Background */
|
||||
.t-gradient-bg {
|
||||
background: linear-gradient(135deg, #0a0a12 0%, #1a1a2e 50%, #0a0a12 100%);
|
||||
}
|
||||
|
||||
/* Magenta Glow */
|
||||
.magenta-glow {
|
||||
box-shadow: 0 0 20px rgba(226,0,116,0.15), 0 0 40px rgba(226,0,116,0.05);
|
||||
}
|
||||
|
||||
/* Card gradient for dark mode */
|
||||
.dark .t-card-gradient {
|
||||
background: linear-gradient(180deg, #12121f, #0a0a12);
|
||||
}
|
||||
|
||||
/* Card gradient for light mode */
|
||||
:not(.dark) .t-card-gradient {
|
||||
background: linear-gradient(180deg, #ffffff, #fafafa);
|
||||
}
|
||||
|
||||
/* Light mode shadow for cards */
|
||||
:not(.dark) .t-card-shadow {
|
||||
box-shadow: 0 2px 8px rgba(226,0,116,0.04);
|
||||
}
|
||||
|
||||
:not(.dark) .t-card-shadow-lg {
|
||||
box-shadow: 0 4px 16px rgba(226,0,116,0.08);
|
||||
}
|
||||
|
||||
/* Accent glow */
|
||||
.t-accent-glow {
|
||||
box-shadow: 0 0 12px rgba(226,0,116,0.5), 0 0 24px rgba(226,0,116,0.2);
|
||||
}
|
||||
|
||||
/* High risk glow */
|
||||
.t-risk-high-glow {
|
||||
box-shadow: 0 0 8px rgba(255,68,68,0.3);
|
||||
}
|
||||
|
||||
/* Medium risk glow */
|
||||
.t-risk-medium-glow {
|
||||
box-shadow: 0 0 6px rgba(255,136,0,0.2);
|
||||
}
|
||||
|
||||
/* Low risk glow */
|
||||
.t-risk-low-glow {
|
||||
box-shadow: 0 0 4px rgba(0,212,170,0.15);
|
||||
}
|
||||
|
||||
/* Pulse glow animation */
|
||||
@keyframes pulse-glow {
|
||||
0%, 100% {
|
||||
box-shadow: 0 0 12px rgba(226,0,116,0.5), 0 0 24px rgba(226,0,116,0.2);
|
||||
}
|
||||
50% {
|
||||
box-shadow: 0 0 16px rgba(226,0,116,0.7), 0 0 32px rgba(226,0,116,0.3);
|
||||
}
|
||||
}
|
||||
|
||||
.animate-pulse-glow {
|
||||
animation: pulse-glow 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse-glow {
|
||||
0%, 100% {
|
||||
box-shadow: 0 0 12px rgba(226,0,116,0.5), 0 0 24px rgba(226,0,116,0.2);
|
||||
}
|
||||
50% {
|
||||
box-shadow: 0 0 16px rgba(226,0,116,0.7), 0 0 32px rgba(226,0,116,0.3);
|
||||
}
|
||||
}
|
||||
|
||||
/* Slide up animation */
|
||||
@keyframes slideUp {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.animate-slide-up {
|
||||
animation: slideUp 0.3s ease;
|
||||
}
|
||||
|
||||
/* Slide in animation */
|
||||
@keyframes slideIn {
|
||||
0% {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
.animate-slide-in {
|
||||
animation: slideIn 0.3s ease-out forwards;
|
||||
}
|
||||
|
||||
/* Slide out animation */
|
||||
@keyframes slideOut {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
}
|
||||
|
||||
.animate-slide-out {
|
||||
animation: slideOut 0.3s ease-in forwards;
|
||||
}
|
||||
|
||||
/* Pulse animation for processing steps */
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
opacity: 0.8;
|
||||
transform: scale(0.95);
|
||||
}
|
||||
}
|
||||
|
||||
.animate-pulse {
|
||||
animation: pulse 0.6s ease-in-out infinite;
|
||||
}
|
||||
|
||||
/* Spin animation for loading icons */
|
||||
@keyframes spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
/* Custom utility classes */
|
||||
@layer utilities {
|
||||
.gradient-accent {
|
||||
background: linear-gradient(135deg, #e20074 0%, #be0060 100%);
|
||||
}
|
||||
|
||||
.gradient-accent-hover {
|
||||
background: linear-gradient(135deg, #f0208a 0%, #d01070 100%);
|
||||
}
|
||||
}
|
||||
58
frontend/src/types/compliance.ts
Normal file
58
frontend/src/types/compliance.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
// Compliance types
|
||||
export type RiskLevel = 'high' | 'medium' | 'low';
|
||||
export type ComplianceStatus = 'pass' | 'warning' | 'fail';
|
||||
export type RegulationCategory = 'high' | 'medium' | 'low';
|
||||
|
||||
export interface Regulation {
|
||||
id: number;
|
||||
name: string;
|
||||
clause: string;
|
||||
score: number;
|
||||
matchKeyword: string;
|
||||
category: RegulationCategory;
|
||||
fullContent: string;
|
||||
}
|
||||
|
||||
export interface ComplianceChunk {
|
||||
id: number;
|
||||
index: number;
|
||||
intent: string;
|
||||
startPos: number;
|
||||
endPos: number;
|
||||
content: string;
|
||||
regulations: Regulation[];
|
||||
}
|
||||
|
||||
export interface SegmentRisk {
|
||||
chunkId: number;
|
||||
level: RiskLevel;
|
||||
score: number;
|
||||
highRegsCount: number;
|
||||
riskRegs: number;
|
||||
}
|
||||
|
||||
export interface RiskDashboardData {
|
||||
score: number;
|
||||
highRiskCount: number;
|
||||
mediumRiskCount: number;
|
||||
lowRiskCount: number;
|
||||
needFixSegments: number;
|
||||
status: ComplianceStatus;
|
||||
statusLabel: string;
|
||||
segmentRisks: SegmentRisk[];
|
||||
}
|
||||
|
||||
export interface PriorityAction {
|
||||
id: number;
|
||||
regulation: string;
|
||||
issue: string;
|
||||
suggestion: string;
|
||||
chunkId: number;
|
||||
severity: 'high' | 'medium';
|
||||
}
|
||||
|
||||
// Upload document type
|
||||
export interface UploadedDoc {
|
||||
name: string;
|
||||
size: string;
|
||||
}
|
||||
35
frontend/src/types/doc.ts
Normal file
35
frontend/src/types/doc.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
export interface Doc {
|
||||
id: number;
|
||||
name: string;
|
||||
chunks: number;
|
||||
size: string;
|
||||
status: 'indexed' | 'parsing' | 'pending';
|
||||
docId?: string;
|
||||
downloadUrl?: string;
|
||||
summary?: string;
|
||||
}
|
||||
|
||||
export interface SearchResult {
|
||||
id: number;
|
||||
score: number;
|
||||
law: string;
|
||||
preview: string;
|
||||
source: string;
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
id: number;
|
||||
role: 'user' | 'assistant';
|
||||
content: string;
|
||||
retrievalIds?: number[];
|
||||
}
|
||||
|
||||
export interface RetrievalData {
|
||||
id: number;
|
||||
file: string;
|
||||
clause: string;
|
||||
score: number;
|
||||
content: string;
|
||||
docId?: string;
|
||||
downloadUrl?: string;
|
||||
}
|
||||
4
frontend/src/types/index.ts
Normal file
4
frontend/src/types/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// Re-export all types
|
||||
export * from './theme';
|
||||
export * from './doc';
|
||||
export * from './compliance';
|
||||
56
frontend/src/types/theme.ts
Normal file
56
frontend/src/types/theme.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
// Theme types
|
||||
export type ThemeMode = 'dark' | 'light';
|
||||
|
||||
export interface ThemeColors {
|
||||
bg: string;
|
||||
bgCard: string;
|
||||
bgHover: string;
|
||||
bgElevated: string;
|
||||
border: string;
|
||||
borderLight: string;
|
||||
text: string;
|
||||
text2: string;
|
||||
text3: string;
|
||||
accent: string;
|
||||
accentDark: string;
|
||||
accentLight: string;
|
||||
green: string;
|
||||
orange: string;
|
||||
gradientAccent: string;
|
||||
}
|
||||
|
||||
export const darkTheme: ThemeColors = {
|
||||
bg: '#0a0a12',
|
||||
bgCard: '#12121f',
|
||||
bgHover: '#1a1a2e',
|
||||
bgElevated: '#1e1e30',
|
||||
border: '#2a2a40',
|
||||
borderLight: '#4a4a60',
|
||||
text: '#fff',
|
||||
text2: '#c0c0d0',
|
||||
text3: '#9a9aaa',
|
||||
accent: '#e20074',
|
||||
accentDark: '#be0060',
|
||||
accentLight: '#f04090',
|
||||
green: '#00d4aa',
|
||||
orange: '#ff8800',
|
||||
gradientAccent: 'linear-gradient(135deg, #e20074, #be0060)',
|
||||
};
|
||||
|
||||
export const lightTheme: ThemeColors = {
|
||||
bg: '#ffffff',
|
||||
bgCard: '#ffffff',
|
||||
bgHover: '#f8f8fc',
|
||||
bgElevated: '#fafafa',
|
||||
border: '#e8e8f0',
|
||||
borderLight: '#d0d0d8',
|
||||
text: '#1a1a2e',
|
||||
text2: '#4a4a5a',
|
||||
text3: '#7a7a8a',
|
||||
accent: '#e20074',
|
||||
accentDark: '#be0060',
|
||||
accentLight: '#f04090',
|
||||
green: '#00b89c',
|
||||
orange: '#ff7700',
|
||||
gradientAccent: 'linear-gradient(135deg, #e20074, #be0060)',
|
||||
};
|
||||
Reference in New Issue
Block a user