11'use client' ;
2- import React , { useState } from 'react' ;
2+ import React , { useEffect , useMemo , useState } from 'react' ;
33import {
44 TextField ,
55 Card ,
@@ -10,7 +10,11 @@ import {
1010 Chip ,
1111 InputAdornment ,
1212 CardActionArea ,
13- Stack
13+ Stack ,
14+ Paper ,
15+ Button ,
16+ Snackbar ,
17+ Alert
1418} from '@mui/material' ;
1519import SearchIcon from '@mui/icons-material/Search' ;
1620import Link from 'next/link' ;
@@ -51,6 +55,30 @@ function buildIntro(investor: Investor) {
5155export default function InvestorList ( { investors } : { investors : Investor [ ] } ) {
5256 const [ search , setSearch ] = useState ( '' ) ;
5357 const [ missingAvatar , setMissingAvatar ] = useState < Record < string , boolean > > ( { } ) ;
58+ const [ origin , setOrigin ] = useState ( '' ) ;
59+ const [ toast , setToast ] = useState < { open : boolean ; text : string } > ( { open : false , text : '' } ) ;
60+
61+ useEffect ( ( ) => {
62+ if ( typeof window !== 'undefined' ) setOrigin ( window . location . origin ) ;
63+ } , [ ] ) ;
64+
65+ const api = useMemo ( ( ) => {
66+ const base = origin || '' ;
67+ return {
68+ health : `${ base } /health` ,
69+ query : `${ base } /api/rag/query` ,
70+ queryImh : `${ base } /imh/api/rag/query` ,
71+ } ;
72+ } , [ origin ] ) ;
73+
74+ async function copy ( text : string ) {
75+ try {
76+ await navigator . clipboard . writeText ( text ) ;
77+ setToast ( { open : true , text : '已复制到剪贴板' } ) ;
78+ } catch {
79+ setToast ( { open : true , text : '复制失败(浏览器权限限制)' } ) ;
80+ }
81+ }
5482
5583 const filtered = investors . filter ( i =>
5684 i . full_name . toLowerCase ( ) . includes ( search . toLowerCase ( ) ) ||
@@ -87,6 +115,69 @@ export default function InvestorList({ investors }: { investors: Investor[] }) {
87115 } }
88116 />
89117 </ Box >
118+
119+ < Box sx = { { mt : 2 , display : 'flex' , justifyContent : 'center' } } >
120+ < Paper
121+ variant = "outlined"
122+ sx = { {
123+ px : 2 ,
124+ py : 1 ,
125+ borderRadius : 3 ,
126+ bgcolor : 'background.paper' ,
127+ borderColor : 'rgba(2,6,23,0.10)' ,
128+ } }
129+ >
130+ < Stack
131+ direction = { { xs : 'column' , sm : 'row' } }
132+ spacing = { 1 }
133+ alignItems = { { xs : 'stretch' , sm : 'center' } }
134+ justifyContent = "center"
135+ >
136+ < Typography variant = "caption" color = "text.secondary" sx = { { fontWeight : 700 } } >
137+ API(给网页 / 其他系统调用)
138+ </ Typography >
139+
140+ < Chip
141+ label = "GET /health"
142+ size = "small"
143+ component = "a"
144+ href = "/health"
145+ clickable
146+ variant = "outlined"
147+ />
148+
149+ < Stack direction = "row" spacing = { 1 } alignItems = "center" justifyContent = "center" >
150+ < Chip label = "POST /api/rag/query" size = "small" color = "primary" variant = "outlined" />
151+ < Button
152+ size = "small"
153+ variant = "text"
154+ onClick = { ( ) =>
155+ copy (
156+ `curl -s -X POST \"${ api . query } \" -H \"Content-Type: application/json\" -d \"{\\\"query\\\":\\\"护城河\\\",\\\"top_k\\\":3}\"` ,
157+ )
158+ }
159+ >
160+ 复制 curl
161+ </ Button >
162+ </ Stack >
163+
164+ < Typography variant = "caption" color = "text.secondary" sx = { { opacity : 0.85 } } >
165+ 若你用 /imh 集成(代理):POST /imh/api/rag/query
166+ </ Typography >
167+ < Button
168+ size = "small"
169+ variant = "text"
170+ onClick = { ( ) =>
171+ copy (
172+ `curl -s -X POST \"${ api . queryImh } \" -H \"Content-Type: application/json\" -d \"{\\\"query\\\":\\\"护城河\\\",\\\"top_k\\\":3}\"` ,
173+ )
174+ }
175+ >
176+ 复制 /imh curl
177+ </ Button >
178+ </ Stack >
179+ </ Paper >
180+ </ Box >
90181 </ Box >
91182
92183 < Box
@@ -185,6 +276,17 @@ export default function InvestorList({ investors }: { investors: Investor[] }) {
185276 </ Box >
186277 ) ) }
187278 </ Box >
279+
280+ < Snackbar
281+ open = { toast . open }
282+ autoHideDuration = { 2500 }
283+ onClose = { ( ) => setToast ( { open : false , text : '' } ) }
284+ anchorOrigin = { { vertical : 'bottom' , horizontal : 'center' } }
285+ >
286+ < Alert severity = "info" variant = "filled" onClose = { ( ) => setToast ( { open : false , text : '' } ) } >
287+ { toast . text }
288+ </ Alert >
289+ </ Snackbar >
188290 </ Box >
189291 ) ;
190292}
0 commit comments