This commit is contained in:
Ubuntu
2026-07-03 16:58:28 +08:00
commit 32b43f85bd
6240 changed files with 1987678 additions and 0 deletions
+184
View 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);
}
}
+121
View File
@@ -0,0 +1,121 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from './assets/vite.svg'
import heroImg from './assets/hero.png'
import './App.css'
function App() {
const [count, setCount] = useState(0)
return (
<>
<section id="center">
<div className="hero">
<img src={heroImg} className="base" width="170" height="179" alt="" />
<img src={reactLogo} className="framework" alt="React logo" />
<img src={viteLogo} className="vite" alt="Vite logo" />
</div>
<div>
<h1>Get started</h1>
<p>
Edit <code>src/App.jsx</code> and save to test <code>HMR</code>
</p>
</div>
<button
className="counter"
onClick={() => setCount((count) => count + 1)}
>
Count is {count}
</button>
</section>
<div className="ticks"></div>
<section id="next-steps">
<div id="docs">
<svg className="icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#documentation-icon"></use>
</svg>
<h2>Documentation</h2>
<p>Your questions, answered</p>
<ul>
<li>
<a href="https://vite.dev/" target="_blank">
<img className="logo" src={viteLogo} alt="" />
Explore Vite
</a>
</li>
<li>
<a href="https://react.dev/" target="_blank">
<img className="button-icon" src={reactLogo} alt="" />
Learn more
</a>
</li>
</ul>
</div>
<div id="social">
<svg className="icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#social-icon"></use>
</svg>
<h2>Connect with us</h2>
<p>Join the Vite community</p>
<ul>
<li>
<a href="https://github.com/vitejs/vite" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#github-icon"></use>
</svg>
GitHub
</a>
</li>
<li>
<a href="https://chat.vite.dev/" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#discord-icon"></use>
</svg>
Discord
</a>
</li>
<li>
<a href="https://x.com/vite_js" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#x-icon"></use>
</svg>
X.com
</a>
</li>
<li>
<a href="https://bsky.app/profile/vite.dev" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#bluesky-icon"></use>
</svg>
Bluesky
</a>
</li>
</ul>
</div>
</section>
<div className="ticks"></div>
<section id="spacer"></section>
</>
)
}
export default App
+190
View File
@@ -0,0 +1,190 @@
/**
* API 封装 - 后端独立端口 10001
*/
// 后端 API 地址
const API_BASE_URL = 'http://129.211.173.87:10001';
class ApiError extends Error {
constructor(message, status) {
super(message);
this.status = status;
}
}
async function fetchWithAuth(url, options = {}) {
const token = localStorage.getItem('token');
const headers = {
'Content-Type': 'application/json',
...options.headers,
};
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
const fullUrl = `${API_BASE_URL}${url}`;
try {
const response = await fetch(fullUrl, {
...options,
headers,
});
const data = await response.json().catch(() => null);
if (!response.ok) {
if (response.status === 401) {
localStorage.removeItem('token');
window.location.href = '/login';
}
throw new ApiError(data?.detail || '请求失败', response.status);
}
return data;
} catch (error) {
if (error instanceof ApiError) throw error;
throw new ApiError(error.message || '网络错误', 0);
}
}
// 认证 API
export const authApi = {
login: (username, password) => fetchWithAuth('/auth/login', {
method: 'POST',
body: JSON.stringify({ username, password }),
}),
changePassword: (oldPassword, newPassword) => fetchWithAuth('/auth/change-password', {
method: 'POST',
body: JSON.stringify({ old_password: oldPassword, new_password: newPassword }),
}),
getMe: () => fetchWithAuth('/auth/me'),
};
// 客户管理 API
export const customerApi = {
list: () => fetchWithAuth('/customers'),
get: (id) => fetchWithAuth(`/customers/${id}`),
create: (data) => fetchWithAuth('/customers', {
method: 'POST',
body: JSON.stringify(data),
}),
update: (id, data) => fetchWithAuth(`/customers/${id}`, {
method: 'PUT',
body: JSON.stringify(data),
}),
delete: (id) => fetchWithAuth(`/customers/${id}`, {
method: 'DELETE',
}),
};
// 发现 API
export const discoverApi = {
search: (keyword, page = 1, pageSize = 10) => fetchWithAuth('/discover/search', {
method: 'POST',
body: JSON.stringify({ keyword, page, page_size: pageSize }),
}),
getDetail: (name, country = '') => fetchWithAuth('/discover/detail', {
method: 'POST',
body: JSON.stringify({ name, country }),
}),
getCountries: () => fetchWithAuth('/discover/countries'),
};
// 设置 API
export const settingsApi = {
getStatus: () => fetchWithAuth('/settings/status'),
setCookie: (content) => fetchWithAuth('/settings/cookie', {
method: 'POST',
body: JSON.stringify({ cookie_content: content }),
}),
getCookie: () => fetchWithAuth('/settings/cookie'),
getTokens: () => fetchWithAuth('/settings/tokens'),
setTokens: (accessToken, individualAccessToken) => fetchWithAuth('/settings/tokens', {
method: 'POST',
body: JSON.stringify({
access_token: accessToken,
individual_access_token: individualAccessToken
}),
}),
};
// 导入任务 API
export const importTaskApi = {
start: (keyword, pageSize = 10) => fetchWithAuth('/import-tasks/start', {
method: 'POST',
body: JSON.stringify({ keyword, page_size: pageSize }),
}),
cancel: () => fetchWithAuth('/import-tasks/cancel', {
method: 'POST',
body: JSON.stringify({}),
}),
getStatus: () => fetchWithAuth('/import-tasks/status'),
getHistory: (page = 1, pageSize = 10) => fetchWithAuth(`/import-tasks/history?page=${page}&page_size=${pageSize}`),
getDetail: (id) => fetchWithAuth(`/import-tasks/${id}`),
};
// 潜在客户 API
export const potentialCustomerApi = {
list: (params = {}) => {
const query = new URLSearchParams();
if (params.keyword) query.append('keyword', params.keyword);
if (params.country) query.append('country', params.country);
if (params.industry) query.append('industry', params.industry);
if (params.has_contacts !== undefined) query.append('has_contacts', params.has_contacts);
if (params.page) query.append('page', params.page);
if (params.page_size) query.append('page_size', params.page_size);
return fetchWithAuth(`/potential-customers/?${query.toString()}`);
},
get: (id) => fetchWithAuth(`/potential-customers/${id}`),
getContacts: (id, page = 1, pageSize = 20) => fetchWithAuth(`/potential-customers/${id}/contacts?page=${page}&page_size=${pageSize}`),
getCountries: () => fetchWithAuth('/potential-customers/countries'),
getIndustries: () => fetchWithAuth('/potential-customers/industries'),
delete: (id) => fetchWithAuth(`/potential-customers/${id}`, {
method: 'DELETE',
}),
};
// 深度分析 API
export const deepAnalysisApi = {
// 创建分析任务
create: (customerIds) => fetchWithAuth('/deep-analysis/create', {
method: 'POST',
body: JSON.stringify({ customer_ids: customerIds }),
}),
// 获取分析列表
list: (params = {}) => {
const query = new URLSearchParams();
if (params.status) query.append('status', params.status);
if (params.page) query.append('page', params.page);
if (params.page_size) query.append('page_size', params.page_size);
return fetchWithAuth(`/deep-analysis/list?${query.toString()}`);
},
// 获取分析详情
getDetail: (id) => fetchWithAuth(`/deep-analysis/detail/${id}`),
// 获取客户分析状态
getCustomerStatus: (customerId) => fetchWithAuth(`/deep-analysis/status/${customerId}`),
// 批量获取客户分析状态(解决N+1问题)
getBatchStatus: (customerIds) => fetchWithAuth('/deep-analysis/batch-status', {
method: 'POST',
body: JSON.stringify({ customer_ids: customerIds })
}),
// 删除分析记录
delete: (id) => fetchWithAuth(`/deep-analysis/delete/${id}`, {
method: 'DELETE',
}),
// 获取队列状态
getQueueStatus: () => fetchWithAuth('/deep-analysis/queue/status'),
// 获取模型配置
getModelConfig: () => fetchWithAuth('/deep-analysis/config/model'),
// 设置模型配置
setModelConfig: (model, apiKey) => fetchWithAuth('/deep-analysis/config/model', {
method: 'POST',
body: JSON.stringify({ model, api_key: apiKey }),
}),
};
export { fetchWithAuth, ApiError };
Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

+1
View 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

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.5 KiB

@@ -0,0 +1,45 @@
import React from 'react'
const variants = {
primary: 'bg-brutal-pink text-white',
secondary: 'bg-brutal-cyan text-black',
success: 'bg-brutal-green text-black',
warning: 'bg-brutal-yellow text-black',
danger: 'bg-red-500 text-white',
outline: 'bg-white text-black border-2 border-black',
ghost: 'bg-transparent text-black border-2 border-black hover:bg-black/5',
}
const sizes = {
sm: 'px-3 py-1.5 text-xs',
md: 'px-4 py-2 text-sm',
lg: 'px-6 py-3 text-base',
}
export default function Button({
children,
variant = 'primary',
size = 'md',
className = '',
disabled = false,
onClick,
type = 'button',
...props
}) {
const baseClasses = 'inline-flex items-center justify-center font-bold transition-all duration-150 border-2 border-black'
const variantClasses = variants[variant] || variants.primary
const sizeClasses = sizes[size] || sizes.md
const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : 'hover:shadow-none hover:translate-x-[2px] hover:translate-y-[2px]'
return (
<button
type={type}
onClick={onClick}
disabled={disabled}
className={`${baseClasses} ${variantClasses} ${sizeClasses} ${disabledClasses} shadow-brutal ${className}`}
{...props}
>
{children}
</button>
)
}
@@ -0,0 +1,52 @@
import React from 'react'
export default function Card({
children,
className = '',
padding = 'normal',
shadow = 'brutal',
}) {
const paddingClasses = {
none: '',
small: 'p-3',
normal: 'p-4',
large: 'p-6',
}
const shadowClasses = {
none: '',
brutal: 'shadow-brutal',
'brutal-sm': 'shadow-brutal-sm',
'brutal-lg': 'shadow-brutal-lg',
}
return (
<div className={`bg-white border-2 border-black ${shadowClasses[shadow]} ${paddingClasses[padding]} ${className}`}>
{children}
</div>
)
}
export function CardHeader({ children, className = '' }) {
return (
<div className={`border-b-2 border-black pb-3 mb-4 ${className}`}>
{children}
</div>
)
}
export function CardTitle({ children, className = '' }) {
return (
<h3 className={`text-lg font-bold ${className}`}>
{children}
</h3>
)
}
export function CardContent({ children, className = '' }) {
return (
<div className={className}>
{children}
</div>
)
}
@@ -0,0 +1,40 @@
import React from 'react'
export default function Input({
label,
type = 'text',
placeholder = '',
value,
onChange,
error,
disabled = false,
className = '',
...props
}) {
return (
<div className={`w-full ${className}`}>
{label && (
<label className="block text-sm font-bold mb-2">
{label}
</label>
)}
<input
type={type}
value={value}
onChange={onChange}
disabled={disabled}
placeholder={placeholder}
className={`w-full px-3 py-2 border-2 border-black bg-white
focus:outline-none focus:ring-2 focus:ring-brutal-yellow
placeholder:text-black/40
${disabled ? 'opacity-50 cursor-not-allowed' : ''}
${error ? 'border-red-500 focus:ring-red-500' : ''}
`}
{...props}
/>
{error && (
<p className="mt-1 text-sm text-red-600 font-medium">{error}</p>
)}
</div>
)
}
@@ -0,0 +1,16 @@
import React from 'react'
import { Outlet } from 'react-router-dom'
import Sidebar from './Sidebar'
export default function Layout() {
return (
<div className="min-h-screen bg-brutal-cream flex">
<Sidebar />
<main className="flex-1 overflow-auto">
<div className="p-6">
<Outlet />
</div>
</main>
</div>
)
}
@@ -0,0 +1,66 @@
import React from 'react'
import { NavLink, useNavigate } from 'react-router-dom'
const menuItems = [
{ path: '/', label: '📊 概览', icon: '📊' },
{ path: '/customers', label: '👥 客户管理', icon: '👥' },
{ path: '/discover', label: '🔍 发现', icon: '🔍' },
{ path: '/potential-customers', label: '🎯 潜在客户', icon: '🎯' },
{ path: '/deep-analysis', label: '🔬 深度分析', icon: '🔬' },
{ path: '/settings', label: '⚙️ 设置', icon: '⚙️' },
]
export default function Sidebar() {
const navigate = useNavigate()
const handleLogout = () => {
localStorage.removeItem('token')
navigate('/login')
}
return (
<aside className="w-64 min-h-screen bg-white border-r-2 border-black flex flex-col">
{/* Logo */}
<div className="p-6 border-b-2 border-black">
<h1 className="text-xl font-bold">
<span className="text-brutal-pink">fumamx</span>
<span className="text-black">CRM</span>
</h1>
<p className="text-xs text-black/60 mt-1">客户管理系统</p>
</div>
{/* 导航菜单 */}
<nav className="flex-1 p-4">
<ul className="space-y-2">
{menuItems.map((item) => (
<li key={item.path}>
<NavLink
to={item.path}
className={({ isActive }) => `
block px-4 py-3 font-bold text-sm border-2 transition-all duration-150
${isActive
? 'bg-brutal-yellow border-black shadow-brutal-sm'
: 'border-transparent hover:border-black hover:bg-white hover:shadow-brutal-sm'
}
`}
>
{item.label}
</NavLink>
</li>
))}
</ul>
</nav>
{/* 退出按钮 */}
<div className="p-4 border-t-2 border-black">
<button
onClick={handleLogout}
className="w-full px-4 py-2 font-bold text-sm border-2 border-black bg-red-100
hover:bg-red-200 transition-all duration-150 hover:shadow-brutal-sm"
>
🚪 退出登录
</button>
</div>
</aside>
)
}
@@ -0,0 +1,40 @@
import React from 'react'
export default function Textarea({
label,
placeholder = '',
value,
onChange,
error,
disabled = false,
rows = 4,
className = '',
...props
}) {
return (
<div className={`w-full ${className}`}>
{label && (
<label className="block text-sm font-bold mb-2">
{label}
</label>
)}
<textarea
value={value}
onChange={onChange}
disabled={disabled}
placeholder={placeholder}
rows={rows}
className={`w-full px-3 py-2 border-2 border-black bg-white
focus:outline-none focus:ring-2 focus:ring-brutal-yellow
placeholder:text-black/40 resize-y
${disabled ? 'opacity-50 cursor-not-allowed' : ''}
${error ? 'border-red-500 focus:ring-red-500' : ''}
`}
{...props}
/>
{error && (
<p className="mt-1 text-sm text-red-600 font-medium">{error}</p>
)}
</div>
)
}
+45
View File
@@ -0,0 +1,45 @@
@import "tailwindcss";
@theme {
--color-brutal-cream: #FEF9E7;
--color-brutal-yellow: #FFDE59;
--color-brutal-pink: #305C34;
--color-brutal-cyan: #00D9FF;
--color-brutal-lavender: #C084FC;
--color-brutal-green: #4ADE80;
--shadow-brutal: 4px 4px 0px 0px rgba(0,0,0,1);
--shadow-brutal-sm: 2px 2px 0px 0px rgba(0,0,0,1);
--shadow-brutal-lg: 6px 6px 0px 0px rgba(0,0,0,1);
}
html {
scroll-behavior: smooth;
}
body {
background-color: #FEF9E7;
font-family: system-ui, -apple-system, sans-serif;
}
/* 自定义滚动条 - 新粗野主义风格 */
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-track {
background: #FEF9E7;
border-left: 2px solid black;
}
::-webkit-scrollbar-thumb {
background: #000;
border: 2px solid #FEF9E7;
}
/* 文字选中高亮 */
::selection {
background: #FFDE59;
color: #000;
}
+57
View File
@@ -0,0 +1,57 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import { HashRouter, Routes, Route, Navigate } from 'react-router-dom'
import './index.css'
import Login from './pages/Login'
import Layout from './components/Layout'
import Dashboard from './pages/Dashboard'
import Customers from './pages/Customers'
import Discover from './pages/Discover'
import PotentialCustomers from './pages/PotentialCustomers'
import DeepAnalysis from './pages/DeepAnalysis'
import Settings from './pages/Settings'
// 路由守卫
function ProtectedRoute({ children }) {
const token = localStorage.getItem('token')
if (!token) {
return <Navigate to="/login" replace />
}
return children
}
// 登录页面路由
function LoginRoute({ children }) {
const token = localStorage.getItem('token')
if (token) {
return <Navigate to="/" replace />
}
return children
}
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<HashRouter>
<Routes>
<Route path="/login" element={
<LoginRoute>
<Login />
</LoginRoute>
} />
<Route path="/" element={
<ProtectedRoute>
<Layout />
</ProtectedRoute>
}>
<Route index element={<Dashboard />} />
<Route path="customers" element={<Customers />} />
<Route path="discover" element={<Discover />} />
<Route path="potential-customers" element={<PotentialCustomers />} />
<Route path="deep-analysis" element={<DeepAnalysis />} />
<Route path="settings" element={<Settings />} />
</Route>
</Routes>
</HashRouter>
</React.StrictMode>
)
+156
View File
@@ -0,0 +1,156 @@
import React, { useEffect, useState } from 'react'
import Card, { CardHeader, CardTitle, CardContent } from '../components/Card'
import Button from '../components/Button'
import { customerApi } from '../api'
export default function Customers() {
const [customers, setCustomers] = useState([])
const [loading, setLoading] = useState(true)
const [selectedCustomer, setSelectedCustomer] = useState(null)
useEffect(() => {
loadCustomers()
}, [])
const loadCustomers = async () => {
setLoading(true)
try {
const data = await customerApi.list()
setCustomers(data)
} catch (err) {
console.error('加载客户失败:', err)
} finally {
setLoading(false)
}
}
const handleDelete = async (id) => {
if (!confirm('确定要删除这个客户吗?')) return
try {
await customerApi.delete(id)
loadCustomers()
} catch (err) {
alert('删除失败: ' + err.message)
}
}
return (
<div>
<div className="flex items-center justify-between mb-6">
<div>
<h1 className="text-2xl font-bold">👥 客户管理</h1>
<p className="text-black/60 mt-1">管理本地客户数据</p>
</div>
<Button variant="secondary" onClick={() => window.location.href = '#/discover'}>
+ 添加客户
</Button>
</div>
{loading ? (
<Card><CardContent className="p-8 text-center">加载中...</CardContent></Card>
) : customers.length === 0 ? (
<Card>
<CardContent className="p-8 text-center">
<p className="text-black/60 mb-4">暂无客户数据</p>
<Button variant="primary" onClick={() => window.location.href = '#/discover'}>
🔍 去发现新客户
</Button>
</CardContent>
</Card>
) : (
<div className="grid gap-4">
{customers.map((customer) => (
<Card key={customer.id} padding="normal">
<div className="flex items-center justify-between">
<div className="flex-1">
<h3 className="font-bold text-lg">{customer.name}</h3>
<div className="flex gap-4 text-sm text-black/60 mt-1">
{customer.country && <span>🌍 {customer.country}</span>}
{customer.source_country && <span>📍 来源: {customer.source_country}</span>}
</div>
{customer.notes && (
<p className="text-sm text-black/60 mt-2 line-clamp-2">{customer.notes}</p>
)}
</div>
<div className="flex gap-2">
<Button
variant="outline"
size="sm"
onClick={() => setSelectedCustomer(customer)}
>
详情
</Button>
<Button
variant="danger"
size="sm"
onClick={() => handleDelete(customer.id)}
>
删除
</Button>
</div>
</div>
</Card>
))}
</div>
)}
{/* 客户详情弹窗 */}
{selectedCustomer && (
<div className="fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50">
<Card padding="large" shadow="brutal-lg" className="w-full max-w-2xl max-h-[80vh] overflow-auto">
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle>{selectedCustomer.name}</CardTitle>
<button
onClick={() => setSelectedCustomer(null)}
className="w-8 h-8 border-2 border-black flex items-center justify-center hover:bg-black/5"
>
✕
</button>
</div>
</CardHeader>
<CardContent>
<div className="space-y-4 text-sm">
<div className="grid grid-cols-2 gap-4">
<div>
<span className="font-bold text-black/60">国家:</span>
<p>{selectedCustomer.country || '-'}</p>
</div>
<div>
<span className="font-bold text-black/60">数据来源:</span>
<p>{selectedCustomer.source_country || '-'}</p>
</div>
</div>
{selectedCustomer.import_data && Object.keys(selectedCustomer.import_data).length > 0 && (
<div>
<span className="font-bold text-black/60">进口数据:</span>
<pre className="mt-2 p-3 bg-black/5 border border-black/20 rounded text-xs overflow-auto max-h-40">
{JSON.stringify(selectedCustomer.import_data, null, 2)}
</pre>
</div>
)}
{selectedCustomer.export_data && Object.keys(selectedCustomer.export_data).length > 0 && (
<div>
<span className="font-bold text-black/60">出口数据:</span>
<pre className="mt-2 p-3 bg-black/5 border border-black/20 rounded text-xs overflow-auto max-h-40">
{JSON.stringify(selectedCustomer.export_data, null, 2)}
</pre>
</div>
)}
{selectedCustomer.notes && (
<div>
<span className="font-bold text-black/60">备注:</span>
<p className="mt-1 whitespace-pre-wrap">{selectedCustomer.notes}</p>
</div>
)}
</div>
</CardContent>
</Card>
</div>
)}
</div>
)
}
+416
View File
@@ -0,0 +1,416 @@
import React, { useEffect, useState } from 'react'
import Card from '../components/Card'
import Button from '../components/Button'
import { customerApi, settingsApi, importTaskApi, potentialCustomerApi, deepAnalysisApi } from '../api'
export default function Dashboard() {
const [stats, setStats] = useState({
customers: 0,
potentialCustomers: 0,
cookieValid: false,
})
const [loading, setLoading] = useState(true)
// 导入任务状态
const [importTask, setImportTask] = useState(null)
const [taskLoading, setTaskLoading] = useState(false)
const [cancelling, setCancelling] = useState(false)
// 深度分析任务状态
const [analysisQueue, setAnalysisQueue] = useState(null)
const [analysisLoading, setAnalysisLoading] = useState(false)
const [analysisCancelling, setAnalysisCancelling] = useState(false)
useEffect(() => {
loadStats()
loadImportStatus() // 首次加载显示 loading
loadAnalysisStatus() // 首次加载显示 loading
// 定时刷新任务状态(静默模式,不显示 loading)
const timer = setInterval(() => {
loadImportStatus(true) // silent = true
loadAnalysisStatus(true) // silent = true
}, 5000)
return () => clearInterval(timer)
}, [])
const loadStats = async () => {
try {
const [customers, potentialCustomers, status] = await Promise.all([
customerApi.list(),
potentialCustomerApi.list({ page_size: 1 }),
settingsApi.getStatus(),
])
setStats({
customers: customers.length,
potentialCustomers: potentialCustomers.total || 0,
cookieValid: status.cookie_valid,
})
} catch (err) {
console.error('加载统计失败:', err)
} finally {
setLoading(false)
}
}
const loadImportStatus = async (silent = false) => {
if (!silent) setTaskLoading(true)
try {
const result = await importTaskApi.getStatus()
setImportTask(result.task)
} catch (err) {
console.error('加载任务状态失败:', err)
} finally {
if (!silent) setTaskLoading(false)
}
}
const loadAnalysisStatus = async (silent = false) => {
if (!silent) setAnalysisLoading(true)
try {
const result = await deepAnalysisApi.getQueueStatus()
setAnalysisQueue(result)
} catch (err) {
console.error('加载分析队列状态失败:', err)
} finally {
if (!silent) setAnalysisLoading(false)
}
}
const handleCancelTask = async () => {
if (!confirm('确定要取消当前导入任务吗?')) return
setCancelling(true)
try {
const result = await importTaskApi.cancel()
if (result.success) {
alert('✓ 任务已取消')
loadImportStatus()
} else {
alert('取消失败: ' + result.error)
}
} catch (err) {
alert('取消失败: ' + err.message)
} finally {
setCancelling(false)
}
}
const handleCancelAnalysis = async () => {
if (!confirm('确定要取消当前深度分析任务吗?')) return
setAnalysisCancelling(true)
try {
const result = await deepAnalysisApi.cancelQueue()
if (result.success) {
alert('✓ 分析任务已取消')
loadAnalysisStatus()
} else {
alert('取消失败: ' + result.error)
}
} catch (err) {
alert('取消失败: ' + err.message)
} finally {
setAnalysisCancelling(false)
}
}
// 格式化时间显示
const formatTime = (isoString) => {
if (!isoString) return '-'
const date = new Date(isoString)
return date.toLocaleString('zh-CN', {
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
})
}
// 获取状态样式
const getStatusStyle = (status) => {
const styles = {
pending: 'bg-yellow-100 text-yellow-800 border-yellow-300',
running: 'bg-brutal-green text-black border-black animate-pulse',
completed: 'bg-brutal-green text-black border-black',
failed: 'bg-brutal-red text-white border-black',
cancelled: 'bg-gray-200 text-gray-600 border-gray-400',
}
return styles[status] || styles.pending
}
// 获取状态文本
const getStatusText = (status) => {
const texts = {
pending: '等待中',
running: '运行中',
completed: '已完成',
failed: '失败',
cancelled: '已取消',
}
return texts[status] || status
}
return (
<div>
<div className="mb-6">
<h1 className="text-2xl font-bold">📊 概览</h1>
<p className="text-black/60 mt-1">系统状态和数据统计</p>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
<Card padding="large">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-black/60 font-bold">客户总数</p>
<p className="text-3xl font-bold mt-2">{stats.customers}</p>
</div>
<div className="w-12 h-12 bg-brutal-pink border-2 border-black flex items-center justify-center text-2xl">
👥
</div>
</div>
</Card>
<Card padding="large">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-black/60 font-bold">Cookie 状态</p>
<p className={`text-lg font-bold mt-2 ${stats.cookieValid ? 'text-brutal-green' : 'text-red-500'}`}>
{stats.cookieValid ? '✓ 有效' : '✗ 无效或过期'}
</p>
</div>
<div className={`w-12 h-12 border-2 border-black flex items-center justify-center text-2xl ${stats.cookieValid ? 'bg-brutal-green' : 'bg-red-100'}`}>
🔑
</div>
</div>
</Card>
<Card padding="large">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-black/60 font-bold">潜在客户</p>
<p className="text-3xl font-bold mt-2">{stats.potentialCustomers}</p>
</div>
<div className="w-12 h-12 bg-brutal-yellow border-2 border-black flex items-center justify-center text-2xl">
🎯
</div>
</div>
</Card>
</div>
{/* 导入任务状态区域 */}
<Card padding="large" className="mb-6">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-2">
<h2 className="text-lg font-bold">🔄 后台同步任务</h2>
{importTask?.status === 'running' && (
<span className="w-2 h-2 bg-brutal-green rounded-full animate-pulse"></span>
)}
</div>
<div className="flex items-center gap-2">
<Button
variant="secondary"
size="sm"
onClick={loadImportStatus}
disabled={taskLoading}
>
{taskLoading ? '⏳' : '🔄'} 刷新状态
</Button>
{importTask?.status === 'running' && (
<Button
variant="danger"
size="sm"
onClick={handleCancelTask}
disabled={cancelling}
>
{cancelling ? '⏳' : '✕'} 取消任务
</Button>
)}
</div>
</div>
{!importTask ? (
<div className="text-center py-8 text-black/60">
<p className="text-4xl mb-2">📭</p>
<p>暂无同步任务记录</p>
<p className="text-sm mt-1">在「发现」页面搜索并导入企业数据</p>
</div>
) : (
<div className="space-y-4">
{/* 任务基本信息 */}
<div className="flex flex-wrap items-center gap-2">
<span className={`px-3 py-1 border-2 font-bold text-sm ${getStatusStyle(importTask.status)}`}>
{getStatusText(importTask.status)}
</span>
<span className="text-sm text-black/60">
关键词: <strong className="text-black">{importTask.keyword}</strong>
</span>
<span className="text-sm text-black/60">
开始时间: {formatTime(importTask.started_at)}
</span>
{importTask.completed_at && (
<span className="text-sm text-black/60">
结束: {formatTime(importTask.completed_at)}
</span>
)}
</div>
{/* 进度条 */}
<div className="space-y-2">
<div className="flex items-center justify-between text-sm">
<span>总进度</span>
<span className="font-bold">{importTask.processed_count} / {importTask.total_count} ({importTask.progress_percent}%)</span>
</div>
<div className="h-4 bg-gray-200 border-2 border-black overflow-hidden">
<div
className="h-full bg-brutal-green transition-all duration-500"
style={{ width: `${importTask.progress_percent}%` }}
></div>
</div>
</div>
{/* 统计信息 */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 pt-4 border-t-2 border-black/10">
<div className="text-center">
<p className="text-2xl font-bold text-brutal-green">{importTask.success_count}</p>
<p className="text-xs text-black/60">成功导入</p>
</div>
<div className="text-center">
<p className="text-2xl font-bold text-yellow-600">{importTask.duplicate_count}</p>
<p className="text-xs text-black/60">重复跳过</p>
</div>
<div className="text-center">
<p className="text-2xl font-bold text-brutal-red">{importTask.failed_count}</p>
<p className="text-xs text-black/60">失败</p>
</div>
<div className="text-center">
<p className="text-2xl font-bold text-blue-600">{importTask.current_page} / {importTask.total_pages}</p>
<p className="text-xs text-black/60">当前页</p>
</div>
</div>
{/* 错误信息 */}
{importTask.error_msg && (
<div className="p-3 bg-brutal-red/10 border-2 border-brutal-red text-brutal-red text-sm">
<strong>错误:</strong> {importTask.error_msg}
</div>
)}
</div>
)}
</Card>
{/* 深度分析任务状态区域 */}
<Card padding="large" className="mb-6">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-2">
<h2 className="text-lg font-bold">🔬 深度分析任务</h2>
{analysisQueue?.is_processing && (
<span className="w-2 h-2 bg-brutal-pink rounded-full animate-pulse"></span>
)}
</div>
<div className="flex items-center gap-2">
<Button
variant="secondary"
size="sm"
onClick={loadAnalysisStatus}
disabled={analysisLoading}
>
{analysisLoading ? '⏳' : '🔄'} 刷新状态
</Button>
{analysisQueue?.is_processing && (
<Button
variant="danger"
size="sm"
onClick={handleCancelAnalysis}
disabled={analysisCancelling}
>
{analysisCancelling ? '⏳' : '✕'} 取消分析
</Button>
)}
</div>
</div>
{!analysisQueue || (!analysisQueue.is_processing && analysisQueue.queued_count === 0) ? (
<div className="text-center py-8 text-black/60">
<p className="text-4xl mb-2">📭</p>
<p>暂无深度分析任务</p>
<p className="text-sm mt-1">在「深度分析」页面选择潜在客户进行分析</p>
</div>
) : (
<div className="space-y-4">
{/* 队列状态 */}
<div className="flex flex-wrap items-center gap-2">
<span className={`px-3 py-1 border-2 font-bold text-sm ${
analysisQueue.is_processing
? 'bg-brutal-pink text-black border-black animate-pulse'
: 'bg-gray-200 text-gray-700 border-gray-400'
}`}>
{analysisQueue.is_processing ? '分析中' : '空闲'}
</span>
{analysisQueue.queued_count > 0 && (
<span className="text-sm text-black/60">
等待中: <strong className="text-black">{analysisQueue.queued_count} 个任务</strong>
</span>
)}
</div>
{/* 当前任务信息 */}
{analysisQueue.current_task && (
<div className="p-3 bg-brutal-yellow/20 border-2 border-brutal-yellow">
<p className="text-sm font-bold mb-1">🔄 当前分析</p>
<p className="text-sm">
企业ID: {analysisQueue.current_task.customer_id}
{analysisQueue.current_task.analysis_id && (
<span className="ml-2 text-black/60">
(分析 #{analysisQueue.current_task.analysis_id})
</span>
)}
</p>
</div>
)}
{/* 统计信息 */}
{(analysisQueue.total_completed > 0 || analysisQueue.total_failed > 0) && (
<div className="grid grid-cols-2 gap-4 pt-4 border-t-2 border-black/10">
<div className="text-center">
<p className="text-2xl font-bold text-brutal-green">{analysisQueue.total_completed || 0}</p>
<p className="text-xs text-black/60">已完成</p>
</div>
<div className="text-center">
<p className="text-2xl font-bold text-brutal-red">{analysisQueue.total_failed || 0}</p>
<p className="text-xs text-black/60">失败</p>
</div>
</div>
)}
</div>
)}
</Card>
<Card padding="large">
<h2 className="text-lg font-bold mb-4">🚀 快速开始</h2>
<div className="space-y-3 text-sm">
<p className="flex items-start gap-2">
<span className="font-bold text-brutal-pink">1.</span>
<span>在 <strong>设置</strong> 页面配置 Cookie,确保 API 可以正常访问</span>
</p>
<p className="flex items-start gap-2">
<span className="font-bold text-brutal-pink">2.</span>
<span>在 <strong>发现</strong> 页面搜索目标客户,点击「导入数据库」批量导入</span>
</p>
<p className="flex items-start gap-2">
<span className="font-bold text-brutal-pink">3.</span>
<span>在 <strong>潜在客户</strong> 页面查看导入的企业和联系人信息</span>
</p>
<p className="flex items-start gap-2">
<span className="font-bold text-brutal-pink">4.</span>
<span>在 <strong>深度分析</strong> 页面选择客户,使用 AI 进行商业价值评估</span>
</p>
<p className="flex items-start gap-2">
<span className="font-bold text-brutal-pink">5.</span>
<span>在 <strong>客户管理</strong> 页面跟进有意向的客户</span>
</p>
</div>
</Card>
</div>
)
}
@@ -0,0 +1,344 @@
import React, { useState, useEffect, useCallback, useRef } from 'react'
import Card, { CardHeader, CardTitle, CardContent } from '../components/Card'
import Button from '../components/Button'
import { deepAnalysisApi } from '../api'
const PAGE_SIZE = 10
export default function DeepAnalysis() {
const [analyses, setAnalyses] = useState([])
const [loading, setLoading] = useState(true)
const [total, setTotal] = useState(0)
const [page, setPage] = useState(1)
const [queueStatus, setQueueStatus] = useState({ queued_count: 0, is_processing: false })
// 使用 ref 存储处理状态,避免定时器依赖变化
const isProcessingRef = useRef(false)
const loadAnalysesRef = useRef(null)
const loadQueueStatusRef = useRef(null)
// 详情弹窗
const [selectedAnalysis, setSelectedAnalysis] = useState(null)
const [reportContent, setReportContent] = useState('')
const [loadingReport, setLoadingReport] = useState(false)
// 加载分析列表(支持静默模式)
const loadAnalyses = useCallback(async (silent = false) => {
if (!silent) setLoading(true)
try {
const data = await deepAnalysisApi.list({
page,
page_size: PAGE_SIZE,
})
setAnalyses(data.items || [])
setTotal(data.total || 0)
} catch (err) {
if (!silent) alert('加载失败: ' + err.message)
else console.error('加载失败:', err.message)
} finally {
if (!silent) setLoading(false)
}
}, [page])
// 加载队列状态(静默刷新,不显示 loading)
const loadQueueStatus = useCallback(async () => {
try {
const status = await deepAnalysisApi.getQueueStatus()
setQueueStatus(status)
isProcessingRef.current = status.is_processing
} catch (err) {
console.error('加载队列状态失败:', err)
}
}, [])
// 保存 ref(用于定时器)
useEffect(() => {
loadAnalysesRef.current = (silent = false) => loadAnalyses(silent)
loadQueueStatusRef.current = loadQueueStatus
}, [loadAnalyses, loadQueueStatus])
// 初始加载(非静默模式,显示 loading)
useEffect(() => {
loadAnalyses(false)
loadQueueStatus()
}, [loadAnalyses, loadQueueStatus])
// 定时刷新队列状态(使用 ref 避免依赖变化,静默模式)
useEffect(() => {
const timer = setInterval(() => {
if (loadQueueStatusRef.current) {
loadQueueStatusRef.current()
}
// 如果有处理中的任务,静默刷新列表(不显示 loading)
if (isProcessingRef.current && loadAnalysesRef.current) {
loadAnalysesRef.current(true) // silent = true
}
}, 5000) // 改为5秒,减少闪烁
return () => clearInterval(timer)
}, []) // 空依赖数组,只在挂载时启动
// 查看详情
const handleViewDetail = async (analysis) => {
setSelectedAnalysis(analysis)
setLoadingReport(true)
setReportContent('')
try {
const data = await deepAnalysisApi.getDetail(analysis.id)
setReportContent(data.report_content || '暂无报告内容')
} catch (err) {
alert('加载报告失败: ' + err.message)
} finally {
setLoadingReport(false)
}
}
// 删除分析
const handleDelete = async (analysis) => {
if (!confirm(`确定要删除 "${analysis.company_name}" 的分析记录吗?`)) {
return
}
try {
await deepAnalysisApi.delete(analysis.id)
alert('✓ 删除成功')
loadAnalyses()
if (selectedAnalysis?.id === analysis.id) {
setSelectedAnalysis(null)
}
} catch (err) {
alert('删除失败: ' + err.message)
}
}
// 获取状态标签样式
const getStatusBadge = (status) => {
const styles = {
pending: 'bg-gray-200 text-gray-700',
processing: 'bg-brutal-yellow text-black',
completed: 'bg-brutal-green text-black',
failed: 'bg-brutal-red text-white',
}
const labels = {
pending: '等待中',
processing: '分析中',
completed: '已完成',
failed: '失败',
}
return (
<span className={`px-2 py-1 text-xs font-bold border-2 border-black ${styles[status] || styles.pending}`}>
{labels[status] || status}
</span>
)
}
const totalPages = Math.ceil(total / PAGE_SIZE)
return (
<div>
<div className="mb-6">
<h1 className="text-2xl font-black mb-2">🔬 深度分析</h1>
<p className="text-black/60">基于商业画布模型的企业潜在价值分析</p>
</div>
{/* 队列状态 */}
<Card className="mb-6 bg-brutal-cream">
<div className="flex items-center justify-between">
<div className="flex items-center gap-4">
<div className="text-sm">
<span className="text-black/60">队列状态:</span>
<span className="ml-2 font-bold">
{queueStatus.is_processing ? (
<span className="text-brutal-pink">● 正在分析</span>
) : (
<span className="text-brutal-green">○ 空闲</span>
)}
</span>
</div>
{queueStatus.queued_count > 0 && (
<div className="text-sm">
<span className="text-black/60">等待任务:</span>
<span className="ml-2 font-bold">{queueStatus.queued_count} 个</span>
</div>
)}
</div>
<Button variant="secondary" size="sm" onClick={loadAnalyses}>
刷新列表
</Button>
</div>
</Card>
{/* 分析列表 */}
<Card>
<CardHeader>
<CardTitle>分析记录 ({total})</CardTitle>
</CardHeader>
<CardContent>
{loading ? (
<p className="text-center py-8 text-black/60">加载中...</p>
) : analyses.length === 0 ? (
<div className="text-center py-12">
<div className="text-4xl mb-4">📊</div>
<p className="text-black/60">暂无分析记录</p>
<p className="text-sm text-black/40 mt-2">
前往"潜在客户"页面选择企业进行深度分析
</p>
</div>
) : (
<>
<div className="space-y-4">
{analyses.map((analysis) => (
<div
key={analysis.id}
className="p-4 border-2 border-black bg-white hover:shadow-brutal-sm transition-shadow"
>
<div className="flex items-start justify-between">
<div className="flex-1">
<div className="flex items-center gap-3 mb-2">
<h3 className="font-bold text-lg">{analysis.company_name}</h3>
{getStatusBadge(analysis.status)}
</div>
<div className="flex items-center gap-4 text-sm text-black/60">
<span>模型: {analysis.model_used || '-'}</span>
<span>创建: {new Date(analysis.created_at).toLocaleString()}</span>
{analysis.completed_at && (
<span>完成: {new Date(analysis.completed_at).toLocaleString()}</span>
)}
</div>
{/* 摘要信息 */}
{analysis.canvas_summary?.overall_score && (
<div className="mt-3 flex items-center gap-4">
<span className="px-3 py-1 bg-brutal-yellow border-2 border-black text-sm font-bold">
评分: {analysis.canvas_summary.overall_score}分
</span>
{analysis.canvas_summary.recommendation && (
<span className="text-sm text-black/70">
建议: {analysis.canvas_summary.recommendation}
</span>
)}
</div>
)}
{analysis.error_message && (
<p className="mt-2 text-sm text-brutal-red">
错误: {analysis.error_message}
</p>
)}
</div>
<div className="flex items-center gap-2 ml-4">
<Button
variant="primary"
size="sm"
onClick={() => handleViewDetail(analysis)}
disabled={analysis.status !== 'completed'}
>
查看报告
</Button>
<Button
variant="danger"
size="sm"
onClick={() => handleDelete(analysis)}
>
删除
</Button>
</div>
</div>
</div>
))}
</div>
{/* 分页 */}
{totalPages > 1 && (
<div className="flex items-center justify-center gap-2 pt-6">
<Button
variant="secondary"
size="sm"
onClick={() => setPage(p => Math.max(1, p - 1))}
disabled={page === 1}
>
上一页
</Button>
<span className="px-4 py-2 border-2 border-black font-bold">
{page} / {totalPages}
</span>
<Button
variant="secondary"
size="sm"
onClick={() => setPage(p => Math.min(totalPages, p + 1))}
disabled={page === totalPages}
>
下一页
</Button>
</div>
)}
</>
)}
</CardContent>
</Card>
{/* 报告详情弹窗 */}
{selectedAnalysis && (
<div className="fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50">
<Card className="w-full max-w-4xl max-h-[90vh] overflow-auto">
<div className="flex items-center justify-between mb-4">
<h2 className="text-xl font-bold">
{selectedAnalysis.company_name} - 深度分析报告
</h2>
<button
onClick={() => setSelectedAnalysis(null)}
className="w-8 h-8 flex items-center justify-center border-2 border-black hover:bg-brutal-red hover:text-white transition-colors"
>
✕
</button>
</div>
{loadingReport ? (
<p className="text-center py-8">加载报告中...</p>
) : (
<div className="prose prose-sm max-w-none">
<div
className="markdown-content bg-gray-50 p-6 border-2 border-black"
style={{
whiteSpace: 'pre-wrap',
lineHeight: '1.8',
}}
>
{reportContent.split('\n').map((line, idx) => {
// 简单的Markdown渲染
if (line.startsWith('### ')) {
return <h3 key={idx} className="text-lg font-bold mt-6 mb-3 text-brutal-pink">{line.replace('### ', '')}</h3>
}
if (line.startsWith('## ')) {
return <h2 key={idx} className="text-xl font-bold mt-8 mb-4 border-b-2 border-black pb-2">{line.replace('## ', '')}</h2>
}
if (line.startsWith('# ')) {
return <h1 key={idx} className="text-2xl font-black mt-8 mb-4">{line.replace('# ', '')}</h1>
}
if (line.startsWith('- ')) {
return <li key={idx} className="ml-4">{line.replace('- ', '')}</li>
}
if (line.match(/^\d+\./)) {
return <div key={idx} className="ml-4 font-bold mt-2">{line}</div>
}
if (line.trim() === '') {
return <br key={idx} />
}
return <p key={idx} className="mb-2">{line}</p>
})}
</div>
</div>
)}
<div className="mt-4 flex justify-end">
<Button variant="secondary" onClick={() => setSelectedAnalysis(null)}>
关闭
</Button>
</div>
</Card>
</div>
)}
</div>
)
}
+522
View File
@@ -0,0 +1,522 @@
import React, { useState, useCallback } from 'react'
import Card, { CardHeader, CardTitle, CardContent } from '../components/Card'
import Button from '../components/Button'
import Input from '../components/Input'
import { discoverApi, customerApi, importTaskApi } from '../api'
const PAGE_SIZE = 10
export default function Discover() {
const [keyword, setKeyword] = useState('')
const [searching, setSearching] = useState(false)
const [results, setResults] = useState([])
const [selectedCompany, setSelectedCompany] = useState(null)
// 分页状态
const [page, setPage] = useState(1)
const [hasMore, setHasMore] = useState(false)
const [loadingMore, setLoadingMore] = useState(false)
const [total, setTotal] = useState(0)
const [currentKeyword, setCurrentKeyword] = useState('')
const [adding, setAdding] = useState(false)
// 导入状态
const [importing, setImporting] = useState(false)
const [importMessage, setImportMessage] = useState(null)
// 初始搜索
const handleSearch = async (e) => {
e.preventDefault()
if (!keyword.trim()) return
setSearching(true)
setCurrentKeyword(keyword)
try {
const data = await discoverApi.search(keyword, 1, PAGE_SIZE)
setResults(data.results || [])
setTotal(data.total || 0)
setPage(1)
// 如果返回结果数量等于页大小,说明可能还有更多
setHasMore((data.results || []).length === PAGE_SIZE)
} catch (err) {
alert('搜索失败: ' + err.message)
} finally {
setSearching(false)
}
}
// 加载更多
const handleLoadMore = useCallback(async () => {
if (loadingMore || !hasMore) return
const nextPage = page + 1
setLoadingMore(true)
try {
const data = await discoverApi.search(currentKeyword, nextPage, PAGE_SIZE)
const newResults = data.results || []
setResults(prev => [...prev, ...newResults])
setPage(nextPage)
// 如果返回结果数量小于页大小,说明没有更多了
setHasMore(newResults.length === PAGE_SIZE)
} catch (err) {
alert('加载失败: ' + err.message)
} finally {
setLoadingMore(false)
}
}, [page, loadingMore, hasMore, currentKeyword])
const handleViewDetail = async (company) => {
setSelectedCompany(company)
}
const handleAddToCRM = async () => {
if (!selectedCompany) return
setAdding(true)
try {
await customerApi.create({
name: selectedCompany.title || selectedCompany.name,
country: selectedCompany.country,
source_country: 'fumamx',
import_data: selectedCompany.import_data,
export_data: selectedCompany.export_data,
raw_data: selectedCompany,
notes: '',
})
alert('✓ 客户添加成功!')
setSelectedCompany(null)
} catch (err) {
alert('添加失败: ' + err.message)
} finally {
setAdding(false)
}
}
// 导入到数据库
const handleImportToDB = async () => {
if (!currentKeyword || total === 0) {
setImportMessage({ type: 'error', text: '请先搜索企业' })
return
}
if (!confirm(`确定要将 "${currentKeyword}" 的 ${total} 家企业导入数据库吗?\n\n注意:导入过程可能需要 ${Math.ceil(total * 4 / 60)} 分钟,期间请勿重复导入。`)) {
return
}
setImporting(true)
setImportMessage(null)
try {
const result = await importTaskApi.start(currentKeyword, PAGE_SIZE)
if (result.success) {
setImportMessage({
type: 'success',
text: `导入任务已启动!预计处理 ${result.task.total_count} 家企业,请前往「概览」查看进度。`
})
} else {
setImportMessage({
type: 'error',
text: result.error || '启动失败'
})
}
} catch (err) {
setImportMessage({ type: 'error', text: '启动失败: ' + err.message })
} finally {
setImporting(false)
}
}
return (
<div>
<div className="mb-6">
<h1 className="text-2xl font-bold">🔍 发现</h1>
<p className="text-black/60 mt-1">搜索并添加新客户</p>
</div>
{/* 搜索表单 */}
<Card padding="large" className="mb-6">
<form onSubmit={handleSearch} className="flex gap-4">
<div className="flex-1">
<Input
placeholder="输入公司名称或关键词搜索..."
value={keyword}
onChange={(e) => setKeyword(e.target.value)}
required
/>
</div>
<Button
type="submit"
variant="primary"
disabled={searching}
>
{searching ? '搜索中...' : '🔍 搜索'}
</Button>
</form>
</Card>
{/* 导入提示消息 */}
{importMessage && (
<div className={`p-4 border-2 border-black ${importMessage.type === 'success' ? 'bg-brutal-green' : 'bg-brutal-red'} shadow-[4px_4px_0px_0px_rgba(0,0,0,1)]`}>
<div className="flex items-center gap-2">
<span className="text-xl">{importMessage.type === 'success' ? '✓' : '✗'}</span>
<span className="font-bold">{importMessage.text}</span>
<button
onClick={() => setImportMessage(null)}
className="ml-auto px-2 py-1 border-2 border-black bg-white hover:bg-gray-100"
>
✕
</button>
</div>
</div>
)}
{/* 搜索结果 */}
{results.length > 0 && (
<div className="space-y-4">
<div className="flex items-center justify-between flex-wrap gap-2">
<h2 className="text-lg font-bold">搜索结果</h2>
<div className="flex items-center gap-3">
<span className="text-sm text-black/60">
显示 {results.length} / {total} 条
</span>
<Button
variant="primary"
onClick={handleImportToDB}
disabled={importing}
className="text-sm px-3 py-1.5"
>
{importing ? '⏳ 启动中...' : '📥 导入数据库'}
</Button>
</div>
</div>
{results.map((item, index) => (
<Card key={index} padding="normal" className="border-2 border-black shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] hover:translate-x-[2px] hover:translate-y-[2px] hover:shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] transition-all">
{/* 头部:Logo + 公司名 + 国家 + 员工数 */}
<div className="flex items-start gap-3 mb-3">
<div className="w-12 h-12 bg-gray-200 border-2 border-black flex items-center justify-center shrink-0">
<span className="text-xl">🏢</span>
</div>
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 flex-wrap">
<h3 className="font-bold text-lg truncate">{item.title || item.name}</h3>
{item.score && (
<span className="px-2 py-0.5 bg-brutal-yellow text-xs font-bold border border-black">
匹配度 {Math.round(item.score)}%
</span>
)}
</div>
<div className="flex items-center gap-3 text-sm text-black/70 mt-1 flex-wrap">
{item.countryCnName && (
<span className="flex items-center gap-1">
🌍 {item.countryCnName}
</span>
)}
{item.employees && (
<span>👥 {item.employees}人</span>
)}
{(item.website || item.domain) && (
<span className="flex items-center gap-1">
🌐 {item.website || item.domain}
</span>
)}
</div>
</div>
</div>
{/* 描述 */}
{item.description && (
<p className="text-sm text-black/80 line-clamp-2 mb-3 bg-black/5 p-2 border-l-4 border-brutal-cyan">
{item.description}
</p>
)}
{/* 贸易数据 */}
<div className="flex flex-wrap gap-4 text-sm mb-3">
{item.procurementFrequency !== undefined && item.procurementFrequency !== null && (
<span className="flex items-center gap-1">
<span className="font-bold">贸易频次:</span>
<span className="text-brutal-pink font-bold">{item.procurementFrequency}次</span>
</span>
)}
{item.annualPurchaseAmount !== undefined && item.annualPurchaseAmount !== null && (
<span className="flex items-center gap-1">
<span className="font-bold">年采购额:</span>
<span className="text-brutal-green font-bold">${item.annualPurchaseAmount.toLocaleString()}</span>
</span>
)}
</div>
{/* 产品 */}
{item.hsEntity && item.hsEntity.length > 0 && (
<div className="mb-3">
<span className="text-sm font-bold">贸易产品:</span>
<div className="flex flex-wrap gap-1 mt-1">
{item.hsEntity.slice(0, 4).map((product, idx) => (
<span key={idx} className="px-2 py-0.5 bg-brutal-cyan/20 text-xs border border-black">
{product}
</span>
))}
{item.hsEntity.length > 4 && (
<span className="px-2 py-0.5 bg-black/10 text-xs">+{item.hsEntity.length - 4}</span>
)}
</div>
</div>
)}
{/* 推荐摘要 */}
{item.recommendedSummary && (
<div className="mb-3 px-3 py-2 bg-brutal-yellow/30 border-2 border-brutal-yellow text-sm">
<span className="font-bold">🔖 {item.recommendedSummary}</span>
</div>
)}
{/* 底部:社交 + 操作 */}
<div className="flex items-center justify-between pt-3 border-t-2 border-black/10">
<div className="flex items-center gap-2">
{item.profiles && item.profiles.map((profile, idx) => (
<a
key={idx}
href={profile.url}
target="_blank"
rel="noopener noreferrer"
className="w-8 h-8 border-2 border-black flex items-center justify-center hover:bg-black/5"
title={profile.service}
>
{profile.service === 'linkedin' && '💼'}
{profile.service === 'facebook' && '📘'}
{profile.service === 'twitter' && '🐦'}
{!['linkedin', 'facebook', 'twitter'].includes(profile.service) && '🔗'}
</a>
))}
</div>
<Button
variant="primary"
size="sm"
onClick={() => handleViewDetail(item)}
>
查看详情 →
</Button>
</div>
</Card>
))}
{/* 加载更多按钮 */}
{hasMore && (
<div className="flex justify-center pt-4">
<Button
variant="outline"
onClick={handleLoadMore}
disabled={loadingMore}
>
{loadingMore ? '加载中...' : `加载更多 (${results.length}/${total})`}
</Button>
</div>
)}
{/* 已加载全部提示 */}
{!hasMore && results.length >= PAGE_SIZE && (
<div className="text-center text-sm text-black/40 py-4">
— 已加载全部 {total} 条结果 —
</div>
)}
</div>
)}
{/* 空状态 */}
{!searching && results.length === 0 && currentKeyword && (
<Card padding="large" className="text-center text-black/60">
<div className="text-4xl mb-2">🔍</div>
<p>未找到与 "{currentKeyword}" 相关的公司</p>
<p className="text-sm mt-1">请尝试其他关键词</p>
</Card>
)}
{/* 公司详情弹窗 */}
{selectedCompany && (
<div className="fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50">
<Card padding="large" shadow="brutal-lg" className="w-full max-w-4xl max-h-[90vh] overflow-auto">
<CardHeader>
<div className="flex items-start justify-between">
<div className="flex items-start gap-4">
<div className="w-16 h-16 bg-gray-200 border-2 border-black flex items-center justify-center shrink-0">
<span className="text-3xl">🏢</span>
</div>
<div>
<CardTitle className="text-2xl">{selectedCompany.title || selectedCompany.name}</CardTitle>
<div className="flex items-center gap-3 text-sm text-black/60 mt-2 flex-wrap">
{selectedCompany.countryCnName && (
<span className="flex items-center gap-1 px-2 py-1 bg-black/5 border border-black/20">
🌍 {selectedCompany.countryCnName}
</span>
)}
{selectedCompany.employees && (
<span className="px-2 py-1 bg-black/5 border border-black/20">
👥 {selectedCompany.employees}人
</span>
)}
{selectedCompany.score && (
<span className="px-2 py-1 bg-brutal-yellow border border-black font-bold">
匹配度 {Math.round(selectedCompany.score)}%
</span>
)}
</div>
</div>
</div>
<button
onClick={() => setSelectedCompany(null)}
className="w-10 h-10 border-2 border-black flex items-center justify-center hover:bg-black/5 text-xl"
>
✕
</button>
</div>
</CardHeader>
<CardContent>
<div className="space-y-6">
{/* 基本信息 */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{selectedCompany.website && (
<div>
<span className="text-sm text-black/60">网站</span>
<a
href={selectedCompany.website}
target="_blank"
rel="noopener noreferrer"
className="block text-brutal-cyan font-bold hover:underline truncate"
>
{selectedCompany.website}
</a>
</div>
)}
{selectedCompany.domain && (
<div>
<span className="text-sm text-black/60">域名</span>
<p className="font-bold">{selectedCompany.domain}</p>
</div>
)}
{selectedCompany.country && (
<div>
<span className="text-sm text-black/60">国家</span>
<p className="font-bold">{selectedCompany.countryCnName || selectedCompany.country}</p>
</div>
)}
{selectedCompany.employees && (
<div>
<span className="text-sm text-black/60">员工数</span>
<p className="font-bold">{selectedCompany.employees}人</p>
</div>
)}
</div>
{/* 贸易数据 */}
{(selectedCompany.procurementFrequency !== undefined ||
selectedCompany.annualPurchaseAmount !== undefined) && (
<div className="p-4 bg-brutal-cyan/10 border-2 border-brutal-cyan">
<h3 className="font-bold mb-3">📊 贸易数据</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{selectedCompany.procurementFrequency !== undefined && (
<div>
<span className="text-sm text-black/60">贸易频次</span>
<p className="text-2xl font-bold text-brutal-pink">
{selectedCompany.procurementFrequency}次
</p>
</div>
)}
{selectedCompany.annualPurchaseAmount !== undefined && (
<div>
<span className="text-sm text-black/60">年采购额</span>
<p className="text-2xl font-bold text-brutal-green">
${selectedCompany.annualPurchaseAmount.toLocaleString()}
</p>
</div>
)}
</div>
</div>
)}
{/* 描述 */}
{selectedCompany.description && (
<div>
<h3 className="font-bold mb-2">📝 公司简介</h3>
<p className="text-sm leading-relaxed bg-black/5 p-4 border border-black/20">
{selectedCompany.description}
</p>
</div>
)}
{/* 产品列表 */}
{selectedCompany.hsEntity && selectedCompany.hsEntity.length > 0 && (
<div>
<h3 className="font-bold mb-2">📦 贸易产品</h3>
<div className="flex flex-wrap gap-2">
{selectedCompany.hsEntity.map((product, idx) => (
<span key={idx} className="px-3 py-1 bg-brutal-cyan/20 border border-black text-sm">
{product}
</span>
))}
</div>
</div>
)}
{/* 社交媒体 */}
{selectedCompany.profiles && selectedCompany.profiles.length > 0 && (
<div>
<h3 className="font-bold mb-2">🔗 社交媒体</h3>
<div className="flex flex-wrap gap-2">
{selectedCompany.profiles.map((profile, idx) => (
<a
key={idx}
href={profile.url}
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-2 px-3 py-2 border-2 border-black hover:bg-black/5"
>
{profile.service === 'linkedin' && '💼'}
{profile.service === 'facebook' && '📘'}
{profile.service === 'twitter' && '🐦'}
{!['linkedin', 'facebook', 'twitter'].includes(profile.service) && '🔗'}
<span className="text-sm font-bold capitalize">{profile.service}</span>
</a>
))}
</div>
</div>
)}
{/* 匹配原因 */}
{selectedCompany.recommendedSummary && (
<div className="p-4 bg-brutal-yellow/30 border-2 border-brutal-yellow">
<span className="font-bold">🔖 匹配原因:</span>
<p className="mt-1">{selectedCompany.recommendedSummary}</p>
</div>
)}
{/* 操作按钮 */}
<div className="flex gap-4 pt-4 border-t-2 border-black/10">
<Button
variant="success"
onClick={handleAddToCRM}
disabled={adding}
>
{adding ? '添加中...' : '✓ 添加到客户管理'}
</Button>
<Button
variant="outline"
onClick={() => setSelectedCompany(null)}
>
关闭
</Button>
</div>
</div>
</CardContent>
</Card>
</div>
)}
</div>
)
}
+79
View File
@@ -0,0 +1,79 @@
import React, { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import Button from '../components/Button'
import Input from '../components/Input'
import Card from '../components/Card'
import { authApi } from '../api'
export default function Login() {
const navigate = useNavigate()
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
const handleSubmit = async (e) => {
e.preventDefault()
setLoading(true)
setError('')
try {
const res = await authApi.login(username, password)
localStorage.setItem('token', res.access_token)
navigate('/')
} catch (err) {
setError(err.message || '登录失败,请检查账号密码')
} finally {
setLoading(false)
}
}
return (
<div className="min-h-screen bg-brutal-cream flex items-center justify-center p-4">
<Card padding="large" shadow="brutal-lg" className="w-full max-w-md">
<div className="text-center mb-8">
<h1 className="text-3xl font-bold mb-2">
<span className="text-brutal-pink">fumamx</span>
<span className="text-black">CRM</span>
</h1>
<p className="text-black/60">客户管理系统</p>
</div>
{error && (
<div className="mb-4 p-3 bg-red-100 border-2 border-black text-red-800 font-bold text-sm">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="space-y-6">
<Input
label="用户名"
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="请输入用户名"
required
/>
<Input
label="密码"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="请输入密码"
required
/>
<Button
type="submit"
variant="primary"
size="lg"
className="w-full"
disabled={loading}
>
{loading ? '登录中...' : '登录'}
</Button>
</form>
</Card>
</div>
)
}
@@ -0,0 +1,608 @@
import React, { useState, useEffect, useCallback } from 'react'
import Card, { CardHeader, CardTitle, CardContent } from '../components/Card'
import Button from '../components/Button'
import Input from '../components/Input'
import { potentialCustomerApi, deepAnalysisApi } from '../api'
const PAGE_SIZE = 20
export default function PotentialCustomers() {
const [customers, setCustomers] = useState([])
const [loading, setLoading] = useState(true)
const [total, setTotal] = useState(0)
const [page, setPage] = useState(1)
// 筛选条件
const [keyword, setKeyword] = useState('')
const [country, setCountry] = useState('')
const [industry, setIndustry] = useState('')
// 筛选选项
const [countries, setCountries] = useState([])
const [industries, setIndustries] = useState([])
// 详情弹窗
const [selectedCustomer, setSelectedCustomer] = useState(null)
const [contacts, setContacts] = useState([])
const [loadingContacts, setLoadingContacts] = useState(false)
// 注意:分析状态现在直接从 customer.analysis_status 获取(反范式设计)
// 加载客户列表
const loadCustomers = useCallback(async () => {
setLoading(true)
try {
const data = await potentialCustomerApi.list({
keyword: keyword || undefined,
country: country || undefined,
industry: industry || undefined,
page,
page_size: PAGE_SIZE,
})
const loadedCustomers = data.results || []
setCustomers(loadedCustomers)
setTotal(data.total || 0)
// 分析状态已内联在客户数据中(反范式设计),无需额外查询
} catch (err) {
alert('加载失败: ' + err.message)
} finally {
setLoading(false)
}
}, [keyword, country, industry, page])
// 加载筛选选项
const loadFilters = useCallback(async () => {
try {
const [countriesData, industriesData] = await Promise.all([
potentialCustomerApi.getCountries(),
potentialCustomerApi.getIndustries(),
])
setCountries(countriesData || [])
setIndustries(industriesData || [])
} catch (err) {
console.error('加载筛选条件失败:', err)
}
}, [])
useEffect(() => {
loadCustomers()
}, [loadCustomers])
useEffect(() => {
loadFilters()
}, [loadFilters])
// 查看详情
const handleViewDetail = async (customer) => {
setSelectedCustomer(customer)
setLoadingContacts(true)
try {
const data = await potentialCustomerApi.getContacts(customer.id)
setContacts(data.contacts || [])
} catch (err) {
alert('加载联系人失败: ' + err.message)
} finally {
setLoadingContacts(false)
}
}
// 搜索
const handleSearch = (e) => {
e.preventDefault()
setPage(1)
loadCustomers()
}
// 重置筛选
const handleReset = () => {
setKeyword('')
setCountry('')
setIndustry('')
setPage(1)
}
// 删除客户
const handleDelete = async (customer) => {
if (!confirm(`确定要删除 "${customer.name}" 吗?\n这将同时删除其所有联系人信息。`)) {
return
}
try {
await potentialCustomerApi.delete(customer.id)
alert('✓ 删除成功')
loadCustomers()
if (selectedCustomer?.id === customer.id) {
setSelectedCustomer(null)
}
} catch (err) {
alert('删除失败: ' + err.message)
}
}
// 深度分析(使用 customer.analysis_status,反范式设计)
const handleDeepAnalysis = async (customer) => {
const isAnalyzed = customer.analysis_status === 'completed'
const confirmMsg = isAnalyzed
? `确定要重新深度分析 "${customer.name}" 吗?\n这将生成新的分析报告。`
: `确定要对 "${customer.name}" 进行深度分析吗?`
if (!confirm(confirmMsg)) {
return
}
try {
await deepAnalysisApi.create([customer.id])
alert('✓ 已添加到分析队列')
// 刷新客户列表以获取最新状态
loadCustomers()
} catch (err) {
alert('添加分析任务失败: ' + err.message)
}
}
// 获取分析按钮文本(使用 customer.analysis_status,反范式设计)
const getAnalysisButtonText = (customer) => {
const status = customer.analysis_status || 'none'
if (status === 'pending') return '排队中...'
if (status === 'processing') return '分析中...'
if (status === 'completed') return '再次深度分析'
return '深度分析'
}
// 获取分析按钮样式(使用 customer.analysis_status,反范式设计)
const getAnalysisButtonVariant = (customer) => {
const status = customer.analysis_status || 'none'
if (status === 'pending' || status === 'processing') return 'secondary'
if (status === 'completed') return 'secondary'
return 'primary'
}
// 检查是否正在分析(用于禁用按钮)
const isAnalyzing = (customer) => {
const status = customer.analysis_status || 'none'
return status === 'pending' || status === 'processing'
}
const totalPages = Math.ceil(total / PAGE_SIZE)
return (
<div>
<div className="mb-6">
<h1 className="text-2xl font-bold">🎯 潜在客户</h1>
<p className="text-black/60 mt-1">管理从 fumamx 导入的企业数据</p>
</div>
{/* 筛选栏 */}
<Card className="mb-6">
<form onSubmit={handleSearch} className="flex flex-wrap items-end gap-4">
<div className="flex-1 min-w-[200px]">
<label className="block text-sm font-bold mb-1">关键词</label>
<Input
type="text"
placeholder="搜索公司名、域名、描述..."
value={keyword}
onChange={(e) => setKeyword(e.target.value)}
/>
</div>
<div className="w-40">
<label className="block text-sm font-bold mb-1">国家</label>
<select
value={country}
onChange={(e) => setCountry(e.target.value)}
className="w-full px-3 py-2 border-2 border-black focus:outline-none focus:ring-2 focus:ring-brutal-pink"
>
<option value="">全部国家</option>
{countries.map((c) => (
<option key={c.code} value={c.code}>
{c.cn_name || c.en_name || c.code}
</option>
))}
</select>
</div>
<div className="w-40">
<label className="block text-sm font-bold mb-1">行业</label>
<select
value={industry}
onChange={(e) => setIndustry(e.target.value)}
className="w-full px-3 py-2 border-2 border-black focus:outline-none focus:ring-2 focus:ring-brutal-pink"
>
<option value="">全部行业</option>
{industries.map((ind) => (
<option key={ind} value={ind}>{ind}</option>
))}
</select>
</div>
<Button type="submit" variant="primary">
🔍 搜索
</Button>
<Button type="button" variant="secondary" onClick={handleReset}>
重置
</Button>
</form>
</Card>
{/* 统计 */}
<div className="mb-4 text-sm text-black/60">
共 <strong className="text-black">{total}</strong> 家企业
{keyword && ` · 关键词: "${keyword}"`}
{country && ` · 国家: ${country}`}
{industry && ` · 行业: ${industry}`}
</div>
{/* 客户列表 */}
<div className="space-y-4">
{loading ? (
<div className="text-center py-12 text-black/60">
<p className="text-4xl mb-2">⏳</p>
<p>加载中...</p>
</div>
) : customers.length === 0 ? (
<div className="text-center py-12 text-black/60">
<p className="text-4xl mb-2">📭</p>
<p>暂无数据</p>
<p className="text-sm mt-1">在「发现」页面导入企业数据</p>
</div>
) : (
<>
{customers.map((customer) => (
<Card
key={customer.id}
padding="normal"
className="border-2 border-black shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] hover:translate-x-[2px] hover:translate-y-[2px] hover:shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] transition-all"
>
{/* 头部 */}
<div className="flex items-start gap-3 mb-3">
<div className="w-12 h-12 bg-gray-200 border-2 border-black flex items-center justify-center shrink-0">
<span className="text-xl">🏢</span>
</div>
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 flex-wrap">
<h3 className="font-bold text-lg truncate">{customer.name}</h3>
{customer.source_score > 0 && (
<span className="px-2 py-0.5 bg-brutal-yellow text-xs font-bold border border-black">
匹配度 {Math.round(customer.source_score)}%
</span>
)}
{customer.contact_count > 0 && (
<span className="px-2 py-0.5 bg-brutal-green text-xs font-bold border border-black">
👤 {customer.contact_count} 联系人
</span>
)}
</div>
<div className="flex items-center gap-3 text-sm text-black/70 mt-1 flex-wrap">
{customer.country_cn && (
<span className="flex items-center gap-1">
🌍 {customer.country_cn}
</span>
)}
{customer.employees && (
<span>👥 {customer.employees}</span>
)}
{customer.industry && (
<span>🏭 {customer.industry}</span>
)}
{customer.domain && (
<span className="flex items-center gap-1">
🌐 {customer.domain}
</span>
)}
</div>
</div>
</div>
{/* 描述 */}
{customer.description && (
<p className="text-sm text-black/70 mb-3 line-clamp-2">
{customer.description}
</p>
)}
{/* 贸易信息 */}
{(customer.procurement_frequency > 0 || customer.annual_purchase_amount > 0) && (
<div className="flex flex-wrap gap-2 mb-3">
{customer.procurement_frequency > 0 && (
<span className="px-2 py-1 bg-brutal-pink/20 border border-brutal-pink text-xs">
采购频次: {customer.procurement_frequency}
</span>
)}
{customer.annual_purchase_amount > 0 && (
<span className="px-2 py-1 bg-brutal-green/20 border border-brutal-green text-xs">
年采购额: ${(customer.annual_purchase_amount / 1000000).toFixed(1)}M
</span>
)}
</div>
)}
{/* HS 编码 */}
{customer.hs_codes && customer.hs_codes.length > 0 && (
<div className="flex flex-wrap gap-1 mb-3">
{customer.hs_codes.slice(0, 5).map((code, idx) => (
<span key={idx} className="px-2 py-0.5 bg-gray-100 border border-gray-300 text-xs">
{code}
</span>
))}
{customer.hs_codes.length > 5 && (
<span className="px-2 py-0.5 text-xs text-black/50">
+{customer.hs_codes.length - 5}
</span>
)}
</div>
)}
{/* 操作按钮 */}
<div className="flex items-center justify-between pt-3 border-t-2 border-black/10">
<span className="text-xs text-black/50">
导入关键词: {customer.keyword}
</span>
<div className="flex items-center gap-2">
<Button
variant="secondary"
size="sm"
onClick={() => handleViewDetail(customer)}
>
查看详情
</Button>
<Button
variant={getAnalysisButtonVariant(customer)}
size="sm"
onClick={() => handleDeepAnalysis(customer)}
disabled={isAnalyzing(customer)}
>
{getAnalysisButtonText(customer)}
</Button>
<Button
variant="danger"
size="sm"
onClick={() => handleDelete(customer)}
>
删除
</Button>
</div>
</div>
</Card>
))}
{/* 分页 */}
{totalPages > 1 && (
<div className="flex items-center justify-center gap-2 pt-4">
<Button
variant="secondary"
size="sm"
onClick={() => setPage(p => Math.max(1, p - 1))}
disabled={page === 1}
>
上一页
</Button>
<span className="px-4 py-2 border-2 border-black font-bold">
{page} / {totalPages}
</span>
<Button
variant="secondary"
size="sm"
onClick={() => setPage(p => Math.min(totalPages, p + 1))}
disabled={page === totalPages}
>
下一页
</Button>
</div>
)}
</>
)}
</div>
{/* 详情弹窗 */}
{selectedCustomer && (
<div className="fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50">
<Card className="w-full max-w-3xl max-h-[90vh] overflow-auto">
<div className="flex items-center justify-between mb-4">
<h2 className="text-xl font-bold">{selectedCustomer.name}</h2>
<button
onClick={() => setSelectedCustomer(null)}
className="w-8 h-8 flex items-center justify-center border-2 border-black hover:bg-brutal-red hover:text-white transition-colors"
>
✕
</button>
</div>
<div className="space-y-6">
{/* 基本信息 */}
<div>
<h3 className="font-bold text-brutal-pink mb-2">基本信息</h3>
<div className="grid grid-cols-2 gap-4 text-sm">
<div>
<span className="text-black/60">域名:</span>
<span className="ml-2">{selectedCustomer.domain || '-'}</span>
</div>
<div>
<span className="text-black/60">国家:</span>
<span className="ml-2">{selectedCustomer.country_cn || selectedCustomer.country || '-'}</span>
</div>
<div>
<span className="text-black/60">行业:</span>
<span className="ml-2">{selectedCustomer.industry || '-'}</span>
</div>
<div>
<span className="text-black/60">员工数:</span>
<span className="ml-2">{selectedCustomer.employees || '-'}</span>
</div>
<div>
<span className="text-black/60">成立时间:</span>
<span className="ml-2">{selectedCustomer.founded || '-'}</span>
</div>
<div>
<span className="text-black/60">电话:</span>
<span className="ml-2">{selectedCustomer.phone || '-'}</span>
</div>
</div>
{selectedCustomer.address && (
<div className="mt-2 text-sm">
<span className="text-black/60">地址:</span>
<span className="ml-2">{selectedCustomer.address}</span>
</div>
)}
{selectedCustomer.description && (
<div className="mt-2 text-sm">
<span className="text-black/60">描述:</span>
<p className="mt-1 p-2 bg-gray-50 border border-gray-200">{selectedCustomer.description}</p>
</div>
)}
</div>
{/* 在线链接 */}
{(selectedCustomer.website || selectedCustomer.linkedin_url) && (
<div>
<h3 className="font-bold text-brutal-pink mb-2">在线链接</h3>
<div className="flex flex-wrap gap-2">
{selectedCustomer.website && (
<a
href={selectedCustomer.website}
target="_blank"
rel="noopener noreferrer"
className="px-3 py-1 bg-brutal-green border-2 border-black text-sm hover:shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] transition-shadow"
>
🌐 访问网站
</a>
)}
{selectedCustomer.linkedin_url && (
<a
href={selectedCustomer.linkedin_url}
target="_blank"
rel="noopener noreferrer"
className="px-3 py-1 bg-blue-500 text-white border-2 border-black text-sm hover:shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] transition-shadow"
>
💼 LinkedIn
</a>
)}
</div>
</div>
)}
{/* 贸易数据 */}
{(selectedCustomer.procurement_frequency > 0 || selectedCustomer.annual_purchase_amount > 0 || selectedCustomer.hs_codes?.length > 0) && (
<div>
<h3 className="font-bold text-brutal-pink mb-2">贸易数据</h3>
<div className="grid grid-cols-2 gap-4 text-sm">
{selectedCustomer.procurement_frequency > 0 && (
<div>
<span className="text-black/60">采购频次:</span>
<span className="ml-2 font-bold">{selectedCustomer.procurement_frequency}</span>
</div>
)}
{selectedCustomer.annual_purchase_amount > 0 && (
<div>
<span className="text-black/60">年采购额:</span>
<span className="ml-2 font-bold">${selectedCustomer.annual_purchase_amount.toLocaleString()}</span>
</div>
)}
</div>
{selectedCustomer.hs_codes?.length > 0 && (
<div className="mt-2">
<span className="text-black/60 text-sm">HS编码:</span>
<div className="flex flex-wrap gap-1 mt-1">
{selectedCustomer.hs_codes.map((code, idx) => (
<span key={idx} className="px-2 py-1 bg-gray-100 border border-gray-300 text-xs">
{code}
</span>
))}
</div>
</div>
)}
{selectedCustomer.hs_entities?.length > 0 && (
<div className="mt-2">
<span className="text-black/60 text-sm">商品:</span>
<p className="text-sm">{selectedCustomer.hs_entities.join(', ')}</p>
</div>
)}
</div>
)}
{/* 联系人 */}
<div>
<h3 className="font-bold text-brutal-pink mb-2">
联系人 ({selectedCustomer.contact_count})
</h3>
{loadingContacts ? (
<p className="text-center py-4 text-black/60">加载中...</p>
) : contacts.length === 0 ? (
<p className="text-center py-4 text-black/60">暂无联系人信息</p>
) : (
<div className="space-y-2">
{contacts.map((contact) => (
<div
key={contact.id}
className="p-3 border-2 border-black bg-gray-50"
>
<div className="flex items-start justify-between">
<div>
<div className="flex items-center gap-2">
<span className="font-bold">{contact.name || '未知名称'}</span>
{contact.score > 0 && (
<span className="px-2 py-0.5 bg-brutal-yellow text-xs font-bold border border-black">
匹配度 {contact.score}%
</span>
)}
</div>
{contact.position && (
<p className="text-sm text-black/70">{contact.position}</p>
)}
</div>
<div className="flex items-center gap-1">
{contact.is_executive && (
<span className="px-2 py-0.5 bg-brutal-red text-white text-xs">高管</span>
)}
{contact.is_kp && (
<span className="px-2 py-0.5 bg-brutal-green text-black text-xs border border-black">KP</span>
)}
</div>
</div>
<div className="mt-2 text-sm space-y-1">
{contact.email && (
<div className="flex items-center gap-2">
<span className="text-black/60">📧</span>
<a href={`mailto:${contact.email}`} className="text-blue-600 hover:underline">
{contact.email}
</a>
</div>
)}
{contact.phone && (
<div className="flex items-center gap-2">
<span className="text-black/60">📞</span>
<span>{contact.phone}</span>
</div>
)}
{contact.linkedin && (
<div className="flex items-center gap-2">
<span className="text-black/60">💼</span>
<a
href={contact.linkedin}
target="_blank"
rel="noopener noreferrer"
className="text-blue-600 hover:underline truncate max-w-xs"
>
{contact.linkedin}
</a>
</div>
)}
</div>
</div>
))}
</div>
)}
</div>
</div>
</Card>
</div>
)}
</div>
)
}
+429
View File
@@ -0,0 +1,429 @@
import React, { useEffect, useState } from 'react'
import Card, { CardHeader, CardTitle, CardContent } from '../components/Card'
import Button from '../components/Button'
import Input from '../components/Input'
import Textarea from '../components/Textarea'
import { settingsApi, authApi, deepAnalysisApi } from '../api'
export default function Settings() {
const [status, setStatus] = useState({
user: '',
cookie_valid: false,
tokens_valid: false,
})
const [cookieContent, setCookieContent] = useState('')
const [savingCookie, setSavingCookie] = useState(false)
// Token 设置
const [accessToken, setAccessToken] = useState('')
const [individualAccessToken, setIndividualAccessToken] = useState('')
const [savingTokens, setSavingTokens] = useState(false)
// 修改密码
const [oldPassword, setOldPassword] = useState('')
const [newPassword, setNewPassword] = useState('')
const [confirmPassword, setConfirmPassword] = useState('')
const [changingPassword, setChangingPassword] = useState(false)
const [passwordError, setPasswordError] = useState('')
// LLM 模型配置
const [llmModel, setLlmModel] = useState('deepseek-chat')
const [llmApiKey, setLlmApiKey] = useState('')
const [maskedApiKey, setMaskedApiKey] = useState('')
const [savingLlmConfig, setSavingLlmConfig] = useState(false)
const [isEditingLlm, setIsEditingLlm] = useState(false)
useEffect(() => {
loadStatus()
loadTokens()
loadLlmConfig()
}, [])
const loadLlmConfig = async () => {
try {
const data = await deepAnalysisApi.getModelConfig()
setLlmModel(data.model || 'deepseek-chat')
setMaskedApiKey(data.api_key_masked || '')
// 如果有已保存的key,不显示在输入框中,需要点击修改重新输入
if (data.api_key_masked && data.api_key_masked !== '****') {
setIsEditingLlm(false)
} else {
setIsEditingLlm(true)
}
} catch (err) {
console.error('加载LLM配置失败:', err)
}
}
const loadStatus = async () => {
try {
const data = await settingsApi.getStatus()
setStatus(data)
} catch (err) {
console.error('加载状态失败:', err)
}
}
const loadTokens = async () => {
try {
const data = await settingsApi.getTokens()
if (data.access_token) {
setAccessToken(data.access_token)
}
if (data.individual_access_token) {
setIndividualAccessToken(data.individual_access_token)
}
} catch (err) {
console.error('加载Token失败:', err)
}
}
const handleSaveCookie = async (e) => {
e.preventDefault()
if (!cookieContent.trim()) {
alert('请输入 Cookie 内容')
return
}
setSavingCookie(true)
try {
const res = await settingsApi.setCookie(cookieContent)
alert(res.message)
setCookieContent('')
loadStatus()
} catch (err) {
alert('保存失败: ' + err.message)
} finally {
setSavingCookie(false)
}
}
const handleSaveTokens = async (e) => {
e.preventDefault()
if (!accessToken.trim() || !individualAccessToken.trim()) {
alert('请输入两个 Token 值')
return
}
setSavingTokens(true)
try {
const res = await settingsApi.setTokens(accessToken, individualAccessToken)
alert(res.message)
loadStatus()
} catch (err) {
alert('保存失败: ' + err.message)
} finally {
setSavingTokens(false)
}
}
const handleChangePassword = async (e) => {
e.preventDefault()
setPasswordError('')
if (newPassword.length < 6) {
setPasswordError('新密码至少需要 6 位')
return
}
if (newPassword !== confirmPassword) {
setPasswordError('两次输入的新密码不一致')
return
}
setChangingPassword(true)
try {
await authApi.changePassword(oldPassword, newPassword)
alert('✓ 密码修改成功!请使用新密码重新登录。')
// 登出让用户重新登录
localStorage.removeItem('token')
window.location.href = '/login'
} catch (err) {
setPasswordError(err.message || '修改失败')
} finally {
setChangingPassword(false)
}
}
const handleSaveLlmConfig = async (e) => {
e.preventDefault()
if (!llmModel || !llmApiKey.trim()) {
alert('请选择模型并输入 API Key')
return
}
setSavingLlmConfig(true)
try {
const res = await deepAnalysisApi.setModelConfig(llmModel, llmApiKey)
alert('✓ 模型配置保存成功')
setMaskedApiKey(res.api_key_masked)
setLlmApiKey('') // 清空输入框
setIsEditingLlm(false)
} catch (err) {
alert('保存失败: ' + err.message)
} finally {
setSavingLlmConfig(false)
}
}
return (
<div>
<div className="mb-6">
<h1 className="text-2xl font-bold">⚙️ 设置</h1>
<p className="text-black/60 mt-1">系统配置和账号管理</p>
</div>
<div className="space-y-6">
{/* 系统状态 */}
<Card padding="large">
<CardHeader>
<CardTitle>系统状态</CardTitle>
</CardHeader>
<CardContent>
<div className="grid grid-cols-3 gap-4">
<div className="p-4 bg-black/5 border-2 border-black">
<p className="text-sm text-black/60">当前用户</p>
<p className="font-bold">{status.user || '-'}</p>
</div>
<div className={`p-4 border-2 border-black ${status.cookie_valid ? 'bg-brutal-green/20' : 'bg-red-100'}`}>
<p className="text-sm text-black/60">Cookie 状态</p>
<p className={`font-bold ${status.cookie_valid ? 'text-brutal-green' : 'text-red-600'}`}>
{status.cookie_valid ? '✓ 有效' : '✗ 无效或过期'}
</p>
</div>
<div className={`p-4 border-2 border-black ${status.tokens_valid ? 'bg-brutal-green/20' : 'bg-red-100'}`}>
<p className="text-sm text-black/60">Token 状态</p>
<p className={`font-bold ${status.tokens_valid ? 'text-brutal-green' : 'text-red-600'}`}>
{status.tokens_valid ? '✓ 有效' : '✗ 无效或缺失'}
</p>
</div>
</div>
</CardContent>
</Card>
{/* Cookie 设置 */}
<Card padding="large">
<CardHeader>
<CardTitle>🔑 Cookie 设置</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handleSaveCookie} className="space-y-4">
<Textarea
label="Cookie JSON 内容"
placeholder='粘贴从浏览器复制的 Cookie JSON,格式如:[{&quot;name&quot;: &quot;token&quot;, &quot;value&quot;: &quot;xxx&quot;, ...}]'
value={cookieContent}
onChange={(e) => setCookieContent(e.target.value)}
rows={6}
required
/>
<div className="flex gap-4">
<Button
type="submit"
variant="primary"
disabled={savingCookie}
>
{savingCookie ? '保存中...' : '保存 Cookie'}
</Button>
<Button
type="button"
variant="outline"
onClick={() => setCookieContent('')}
>
清空
</Button>
</div>
</form>
<div className="mt-4 p-4 bg-yellow-50 border-2 border-brutal-yellow text-sm">
<p className="font-bold mb-2">💡 如何获取 Cookie:</p>
<ol className="list-decimal list-inside space-y-1 text-black/80">
<li>登录 https://www.fumamx.com</li>
<li>按 F12 打开开发者工具 → Application → Cookies</li>
<li>导出为 JSON 格式并粘贴到上方</li>
<li>Cookie 会保存在服务器,用于 API 调用</li>
</ol>
</div>
</CardContent>
</Card>
{/* Access Token 设置 */}
<Card padding="large">
<CardHeader>
<CardTitle>🔐 Access Token 设置</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handleSaveTokens} className="space-y-4">
<Input
label="Access Token"
placeholder='从 sessionStorage 获取的 accessToken 值'
value={accessToken}
onChange={(e) => setAccessToken(e.target.value)}
required
/>
<Input
label="Individual Access Token"
placeholder='从 sessionStorage 获取的 individualAccessToken 值'
value={individualAccessToken}
onChange={(e) => setIndividualAccessToken(e.target.value)}
required
/>
<div className="flex gap-4">
<Button
type="submit"
variant="primary"
disabled={savingTokens}
>
{savingTokens ? '保存中...' : '保存 Token'}
</Button>
</div>
</form>
<div className="mt-4 p-4 bg-blue-50 border-2 border-blue-400 text-sm">
<p className="font-bold mb-2">💡 如何获取 Token:</p>
<ol className="list-decimal list-inside space-y-1 text-black/80">
<li>登录 https://www.fumamx.com</li>
<li>按 F12 打开开发者工具 → 切换到 Console 标签</li>
<li>输入以下命令获取 Token(注意大小写):
<pre className="bg-black text-green-400 p-2 mt-1 rounded text-xs overflow-x-auto">
{`sessionStorage.getItem('accessToken')
sessionStorage.getItem('individualAccessToken')`}
</pre>
</li>
<li>返回结果是 JSON 字符串,提取其中的 <code className="bg-gray-200 px-1">value</code> 字段值</li>
<li>例如:<code className="bg-gray-200 px-1 text-xs">{"{\"value\":\"71uRBqAwJWWLxWyp\"}"}</code> → 只复制 <code className="bg-gray-200 px-1">71uRBqAwJWWLxWyp</code></li>
<li>将两个 value 值分别填入上方输入框</li>
</ol>
<p className="mt-2 text-red-600 font-bold">⚠️ 注意:Token 有过期时间,API 返回 401 时需要重新获取并更新</p>
</div>
</CardContent>
</Card>
{/* 修改密码 */}
<Card padding="large">
<CardHeader>
<CardTitle>🔒 修改密码</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handleChangePassword} className="space-y-4">
<Input
label="旧密码"
type="password"
value={oldPassword}
onChange={(e) => setOldPassword(e.target.value)}
placeholder="输入当前密码"
required
/>
<Input
label="新密码"
type="password"
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
placeholder="输入新密码(至少6位)"
required
/>
<Input
label="确认新密码"
type="password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
placeholder="再次输入新密码"
required
error={passwordError}
/>
<Button
type="submit"
variant="warning"
disabled={changingPassword}
>
{changingPassword ? '修改中...' : '修改密码'}
</Button>
</form>
</CardContent>
</Card>
{/* LLM 模型配置 */}
<Card padding="large">
<CardHeader>
<CardTitle>🤖 深度分析模型配置</CardTitle>
</CardHeader>
<CardContent>
{!isEditingLlm && maskedApiKey ? (
<div className="space-y-4">
<div className="p-4 bg-gray-50 border-2 border-black">
<div className="grid grid-cols-2 gap-4 mb-4">
<div>
<p className="text-sm text-black/60">当前模型</p>
<p className="font-bold">{llmModel === 'kimi-k2.5' ? 'Moonshot Kimi K2.5' : 'DeepSeek Chat'}</p>
</div>
<div>
<p className="text-sm text-black/60">API Key</p>
<p className="font-bold font-mono">{maskedApiKey}</p>
</div>
</div>
<Button
variant="secondary"
size="sm"
onClick={() => setIsEditingLlm(true)}
>
修改配置
</Button>
</div>
</div>
) : (
<form onSubmit={handleSaveLlmConfig} className="space-y-4">
<div>
<label className="block text-sm font-bold mb-1">选择模型</label>
<select
value={llmModel}
onChange={(e) => setLlmModel(e.target.value)}
className="w-full px-3 py-2 border-2 border-black focus:outline-none focus:ring-2 focus:ring-brutal-pink"
required
>
<option value="deepseek-chat">DeepSeek Chat</option>
<option value="kimi-k2.5">Moonshot Kimi K2.5</option>
<option value="kimi-latest">Moonshot Kimi (最新版)</option>
</select>
</div>
<Input
label="API Key"
type="password"
value={llmApiKey}
onChange={(e) => setLlmApiKey(e.target.value)}
placeholder="输入 API Key"
required
/>
<div className="flex gap-4">
<Button
type="submit"
variant="primary"
disabled={savingLlmConfig}
>
{savingLlmConfig ? '保存中...' : '保存配置'}
</Button>
{maskedApiKey && (
<Button
type="button"
variant="outline"
onClick={() => {
setIsEditingLlm(false)
setLlmApiKey('')
}}
>
取消
</Button>
)}
</div>
</form>
)}
<div className="mt-4 p-4 bg-green-50 border-2 border-green-400 text-sm">
<p className="font-bold mb-2">💡 如何获取 API Key:</p>
<ul className="list-disc list-inside space-y-1 text-black/80">
<li><strong>DeepSeek:</strong> 访问 <a href="https://platform.deepseek.com/" target="_blank" rel="noopener noreferrer" className="text-blue-600 underline">platform.deepseek.com</a> 注册并创建 API Key</li>
<li><strong>Moonshot Kimi:</strong> 访问 <a href="https://platform.moonshot.cn/" target="_blank" rel="noopener noreferrer" className="text-blue-600 underline">platform.moonshot.cn</a> 注册并创建 API Key</li>
</ul>
<p className="mt-2 text-black/60">API Key 将保存在服务器,用于深度分析功能调用大模型</p>
</div>
</CardContent>
</Card>
</div>
</div>
)
}