初始化提交
This commit is contained in:
23
NBATransfer-frontend/eslint.config.js
Normal file
23
NBATransfer-frontend/eslint.config.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs.flat.recommended,
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
},
|
||||
])
|
||||
13
NBATransfer-frontend/index.html
Normal file
13
NBATransfer-frontend/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>大语言模型API中转站</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
4992
NBATransfer-frontend/package-lock.json
generated
Normal file
4992
NBATransfer-frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
NBATransfer-frontend/package.json
Normal file
37
NBATransfer-frontend/package.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "nbatransfer",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
"react-router-dom": "^7.1.3",
|
||||
"axios": "^1.7.9",
|
||||
"zustand": "^5.0.3",
|
||||
"antd": "^5.23.2",
|
||||
"@ant-design/icons": "^5.5.4",
|
||||
"dayjs": "^1.11.13",
|
||||
"recharts": "^2.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.1",
|
||||
"@types/node": "^24.10.1",
|
||||
"@types/react": "^19.2.5",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^5.1.1",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"eslint-plugin-react-refresh": "^0.4.24",
|
||||
"globals": "^16.5.0",
|
||||
"typescript": "~5.9.3",
|
||||
"typescript-eslint": "^8.46.4",
|
||||
"vite": "^7.2.4"
|
||||
}
|
||||
}
|
||||
1
NBATransfer-frontend/public/vite.svg
Normal file
1
NBATransfer-frontend/public/vite.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="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
17
NBATransfer-frontend/src/App.css
Normal file
17
NBATransfer-frontend/src/App.css
Normal file
@@ -0,0 +1,17 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
#root {
|
||||
min-height: 100vh;
|
||||
}
|
||||
50
NBATransfer-frontend/src/App.tsx
Normal file
50
NBATransfer-frontend/src/App.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import React from 'react';
|
||||
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { ConfigProvider } from 'antd';
|
||||
import zhCN from 'antd/locale/zh_CN';
|
||||
import Login from './pages/Login';
|
||||
import DashboardLayout from './components/DashboardLayout';
|
||||
import Dashboard from './pages/Dashboard';
|
||||
import Wallet from './pages/Wallet';
|
||||
import ApiKeyManagement from './pages/ApiKeyManagement';
|
||||
import ApiDocumentation from './pages/ApiDocumentation';
|
||||
import Settings from './pages/Settings';
|
||||
import { PrivateRoute } from './components/PrivateRoute';
|
||||
import { useAuthStore } from './store/auth';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
|
||||
|
||||
return (
|
||||
<ConfigProvider locale={zhCN}>
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route
|
||||
path="/login"
|
||||
element={isAuthenticated ? <Navigate to="/dashboard" replace /> : <Login />}
|
||||
/>
|
||||
|
||||
<Route
|
||||
path="/dashboard"
|
||||
element={
|
||||
<PrivateRoute>
|
||||
<DashboardLayout />
|
||||
</PrivateRoute>
|
||||
}
|
||||
>
|
||||
<Route index element={<Dashboard />} />
|
||||
<Route path="wallet" element={<Wallet />} />
|
||||
<Route path="apikeys" element={<ApiKeyManagement />} />
|
||||
<Route path="docs" element={<ApiDocumentation />} />
|
||||
<Route path="settings" element={<Settings />} />
|
||||
</Route>
|
||||
|
||||
<Route path="/" element={<Navigate to="/dashboard" replace />} />
|
||||
<Route path="*" element={<Navigate to="/dashboard" replace />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
</ConfigProvider>
|
||||
);
|
||||
}
|
||||
export default App;
|
||||
65
NBATransfer-frontend/src/api/client.ts
Normal file
65
NBATransfer-frontend/src/api/client.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000/api';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
// 请求拦截器 - 添加 token
|
||||
api.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = localStorage.getItem('access_token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 响应拦截器 - 处理错误
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error) => {
|
||||
const originalRequest = error.config;
|
||||
|
||||
// 如果 token 过期,尝试刷新
|
||||
if (error.response?.status === 401 && !originalRequest._retry) {
|
||||
originalRequest._retry = true;
|
||||
|
||||
try {
|
||||
const refreshToken = localStorage.getItem('refresh_token');
|
||||
if (refreshToken) {
|
||||
const response = await axios.post(`${API_BASE_URL}/auth/refresh`, null, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${refreshToken}`,
|
||||
},
|
||||
});
|
||||
|
||||
const { access_token } = response.data;
|
||||
localStorage.setItem('access_token', access_token);
|
||||
|
||||
originalRequest.headers.Authorization = `Bearer ${access_token}`;
|
||||
return api(originalRequest);
|
||||
}
|
||||
} catch (refreshError) {
|
||||
// 刷新失败,清除 token 并跳转到登录页
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('refresh_token');
|
||||
window.location.href = '/login';
|
||||
return Promise.reject(refreshError);
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default api;
|
||||
10
NBATransfer-frontend/src/api/index.ts
Normal file
10
NBATransfer-frontend/src/api/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import api from './client';
|
||||
|
||||
export * from './modules/auth';
|
||||
export * from './modules/user';
|
||||
export * from './modules/order';
|
||||
export * from './modules/service';
|
||||
export * from './modules/admin';
|
||||
export * from './modules/apikey';
|
||||
|
||||
export default api;
|
||||
16
NBATransfer-frontend/src/api/modules/admin.ts
Normal file
16
NBATransfer-frontend/src/api/modules/admin.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import api from '../client';
|
||||
|
||||
export const adminAPI = {
|
||||
getUsers: (params: { page?: number; per_page?: number; search?: string }) =>
|
||||
api.get('/admin/users', { params }),
|
||||
getUserDetail: (userId: number) => api.get(`/admin/users/${userId}`),
|
||||
toggleUserStatus: (userId: number) => api.post(`/admin/users/${userId}/toggle-status`),
|
||||
adjustBalance: (userId: number, data: { amount: number; description: string }) =>
|
||||
api.post(`/admin/users/${userId}/adjust-balance`, data),
|
||||
getAllOrders: (params: { page?: number; per_page?: number; status?: string }) =>
|
||||
api.get('/admin/orders', { params }),
|
||||
getAllApiCalls: (params: { page?: number; per_page?: number; status?: string }) =>
|
||||
api.get('/admin/api-calls', { params }),
|
||||
getOverviewStats: () => api.get('/admin/stats/overview'),
|
||||
getChartData: (params: { days?: number }) => api.get('/admin/stats/chart', { params }),
|
||||
};
|
||||
10
NBATransfer-frontend/src/api/modules/apikey.ts
Normal file
10
NBATransfer-frontend/src/api/modules/apikey.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import api from '../client';
|
||||
|
||||
export const apikeyAPI = {
|
||||
getKeys: () => api.get('/apikey/keys'),
|
||||
createKey: (data: { name: string }) => api.post('/apikey/keys', data),
|
||||
deleteKey: (id: number) => api.delete(`/apikey/keys/${id}`),
|
||||
updateKey: (id: number, data: { name?: string; is_active?: boolean }) =>
|
||||
api.put(`/apikey/keys/${id}`, data),
|
||||
regenerateKey: (id: number) => api.post(`/apikey/keys/${id}/regenerate`, {}),
|
||||
};
|
||||
17
NBATransfer-frontend/src/api/modules/auth.ts
Normal file
17
NBATransfer-frontend/src/api/modules/auth.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import api from '../client';
|
||||
|
||||
export const authAPI = {
|
||||
sendVerificationCode: (data: { email: string }) =>
|
||||
api.post('/auth/send-verification-code', data),
|
||||
register: (data: { email: string; password: string; verification_code: string }) =>
|
||||
api.post('/auth/register', { ...data, code: data.verification_code }),
|
||||
login: (data: { email: string; password: string }) =>
|
||||
api.post('/auth/login', data),
|
||||
getCurrentUser: () => api.get('/auth/me'),
|
||||
changePassword: (data: { old_password: string; new_password: string }) =>
|
||||
api.post('/auth/change-password', data),
|
||||
verifyCode: (data: { email: string; code: string }) =>
|
||||
api.post('/auth/verify-code', data),
|
||||
resetPassword: (data: { email: string; verification_code: string; new_password: string }) =>
|
||||
api.post('/auth/reset-password', { ...data, code: data.verification_code }),
|
||||
};
|
||||
10
NBATransfer-frontend/src/api/modules/order.ts
Normal file
10
NBATransfer-frontend/src/api/modules/order.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import api from '../client';
|
||||
|
||||
export const orderAPI = {
|
||||
createOrder: (data: { amount: number; payment_method: string }) =>
|
||||
api.post('/order/create', data),
|
||||
getOrders: (params: { page?: number; per_page?: number; status?: string }) =>
|
||||
api.get('/order/list', { params }),
|
||||
getOrder: (orderId: number) => api.get(`/order/${orderId}`),
|
||||
notifyPayment: (orderNo: string) => api.post(`/order/notify/${orderNo}`),
|
||||
};
|
||||
9
NBATransfer-frontend/src/api/modules/service.ts
Normal file
9
NBATransfer-frontend/src/api/modules/service.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import api from '../client';
|
||||
|
||||
export const apiServiceAPI = {
|
||||
textToImage: (data: { model?: string; messages?: any[]; prompt?: string; parameters?: any }) =>
|
||||
api.post('/service/text-to-image', data),
|
||||
getModels: () => api.get('/service/models'),
|
||||
getPricing: () => api.get('/service/pricing'),
|
||||
getApiCall: (callId: number) => api.get(`/service/call/${callId}`),
|
||||
};
|
||||
12
NBATransfer-frontend/src/api/modules/user.ts
Normal file
12
NBATransfer-frontend/src/api/modules/user.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import api from '../client';
|
||||
|
||||
export const userAPI = {
|
||||
getProfile: () => api.get('/user/profile'),
|
||||
updateProfile: (data: { username?: string }) => api.put('/user/profile', data),
|
||||
getBalance: () => api.get('/user/balance'),
|
||||
getTransactions: (params: { page?: number; per_page?: number }) =>
|
||||
api.get('/user/transactions', { params }),
|
||||
getApiCalls: (params: { page?: number; per_page?: number }) =>
|
||||
api.get('/user/api-calls', { params }),
|
||||
getStats: () => api.get('/user/stats'),
|
||||
};
|
||||
1
NBATransfer-frontend/src/assets/react.svg
Normal file
1
NBATransfer-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 |
86
NBATransfer-frontend/src/components/DashboardLayout.css
Normal file
86
NBATransfer-frontend/src/components/DashboardLayout.css
Normal file
@@ -0,0 +1,86 @@
|
||||
.dashboard-layout {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.dashboard-sider {
|
||||
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.logo h2 {
|
||||
color: #fff;
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.dashboard-header {
|
||||
background: #fff;
|
||||
padding: 0 24px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.balance-info {
|
||||
font-weight: 600;
|
||||
color: #1890ff;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
cursor: pointer;
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.user-info:hover {
|
||||
background: rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.username {
|
||||
max-width: 150px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.dashboard-content {
|
||||
margin: 24px;
|
||||
padding: 24px;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
min-height: calc(100vh - 112px);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.dashboard-content {
|
||||
margin: 16px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.username {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.balance-info {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
143
NBATransfer-frontend/src/components/DashboardLayout.tsx
Normal file
143
NBATransfer-frontend/src/components/DashboardLayout.tsx
Normal file
@@ -0,0 +1,143 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Layout, Menu, Avatar, Dropdown, message } from 'antd';
|
||||
import {
|
||||
DashboardOutlined,
|
||||
WalletOutlined,
|
||||
UserOutlined,
|
||||
LogoutOutlined,
|
||||
SettingOutlined,
|
||||
KeyOutlined,
|
||||
FileTextOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { Outlet, useNavigate, useLocation } from 'react-router-dom';
|
||||
import { useAuthStore } from '../store/auth';
|
||||
import { userAPI } from '../api';
|
||||
import './DashboardLayout.css';
|
||||
|
||||
const { Header, Sider, Content } = Layout;
|
||||
|
||||
const DashboardLayout: React.FC = () => {
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { user, logout, updateUser } = useAuthStore();
|
||||
|
||||
useEffect(() => {
|
||||
// 获取最新用户信息(包括余额)
|
||||
const fetchUserProfile = async () => {
|
||||
try {
|
||||
const response = await userAPI.getProfile();
|
||||
updateUser(response.data);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch user profile:', error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchUserProfile();
|
||||
}, [updateUser]);
|
||||
|
||||
const menuItems = [
|
||||
{
|
||||
key: '/dashboard',
|
||||
icon: <DashboardOutlined />,
|
||||
label: '概览',
|
||||
},
|
||||
{
|
||||
key: '/dashboard/wallet',
|
||||
icon: <WalletOutlined />,
|
||||
label: '我的钱包',
|
||||
},
|
||||
{
|
||||
key: '/dashboard/apikeys',
|
||||
icon: <KeyOutlined />,
|
||||
label: 'API密钥',
|
||||
},
|
||||
{
|
||||
key: '/dashboard/docs',
|
||||
icon: <FileTextOutlined />,
|
||||
label: 'API文档',
|
||||
},
|
||||
{
|
||||
key: '/dashboard/settings',
|
||||
icon: <SettingOutlined />,
|
||||
label: '账户设置',
|
||||
},
|
||||
];
|
||||
|
||||
const handleLogout = () => {
|
||||
logout();
|
||||
message.success('已退出登录');
|
||||
navigate('/login');
|
||||
};
|
||||
|
||||
const userMenuItems = [
|
||||
{
|
||||
key: 'profile',
|
||||
icon: <UserOutlined />,
|
||||
label: '个人资料',
|
||||
onClick: () => navigate('/dashboard/settings'),
|
||||
},
|
||||
{
|
||||
key: 'logout',
|
||||
icon: <LogoutOutlined />,
|
||||
label: '退出登录',
|
||||
onClick: handleLogout,
|
||||
},
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
// 移动端自动收起侧边栏
|
||||
const handleResize = () => {
|
||||
if (window.innerWidth < 768) {
|
||||
setCollapsed(true);
|
||||
}
|
||||
};
|
||||
|
||||
handleResize();
|
||||
window.addEventListener('resize', handleResize);
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Layout className="dashboard-layout">
|
||||
<Sider
|
||||
collapsible
|
||||
collapsed={collapsed}
|
||||
onCollapse={setCollapsed}
|
||||
breakpoint="lg"
|
||||
className="dashboard-sider"
|
||||
>
|
||||
<div className="logo">
|
||||
<h2>{collapsed ? '🍌' : '🍌 大语言模型API'}</h2>
|
||||
</div>
|
||||
<Menu
|
||||
theme="dark"
|
||||
mode="inline"
|
||||
selectedKeys={[location.pathname]}
|
||||
items={menuItems}
|
||||
onClick={({ key }) => navigate(key)}
|
||||
/>
|
||||
</Sider>
|
||||
<Layout>
|
||||
<Header className="dashboard-header">
|
||||
<div className="header-right">
|
||||
<div className="balance-info">
|
||||
余额: ¥{user?.balance?.toFixed(2) || '0.00'}
|
||||
</div>
|
||||
<Dropdown menu={{ items: userMenuItems }} placement="bottomRight">
|
||||
<div className="user-info">
|
||||
<Avatar icon={<UserOutlined />} />
|
||||
<span className="username">{user?.username || user?.email}</span>
|
||||
</div>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</Header>
|
||||
<Content className="dashboard-content">
|
||||
<Outlet />
|
||||
</Content>
|
||||
</Layout>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default DashboardLayout;
|
||||
22
NBATransfer-frontend/src/components/PrivateRoute.tsx
Normal file
22
NBATransfer-frontend/src/components/PrivateRoute.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
import { Navigate } from 'react-router-dom';
|
||||
import { useAuthStore } from '../store/auth';
|
||||
|
||||
interface PrivateRouteProps {
|
||||
children: React.ReactNode;
|
||||
requireAdmin?: boolean;
|
||||
}
|
||||
|
||||
export const PrivateRoute: React.FC<PrivateRouteProps> = ({ children, requireAdmin = false }) => {
|
||||
const { isAuthenticated, user } = useAuthStore();
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/login" replace />;
|
||||
}
|
||||
|
||||
if (requireAdmin && !user?.is_admin) {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
14
NBATransfer-frontend/src/index.css
Normal file
14
NBATransfer-frontend/src/index.css
Normal file
@@ -0,0 +1,14 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
10
NBATransfer-frontend/src/main.tsx
Normal file
10
NBATransfer-frontend/src/main.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
134
NBATransfer-frontend/src/pages/ApiDocumentation.css
Normal file
134
NBATransfer-frontend/src/pages/ApiDocumentation.css
Normal file
@@ -0,0 +1,134 @@
|
||||
.doc-section {
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.doc-section h2 {
|
||||
margin-top: 20px;
|
||||
margin-bottom: 15px;
|
||||
color: #000;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.doc-section h3 {
|
||||
margin-top: 15px;
|
||||
margin-bottom: 10px;
|
||||
color: #333;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.doc-section p {
|
||||
margin-bottom: 12px;
|
||||
line-height: 1.6;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.doc-section ul,
|
||||
.doc-section ol {
|
||||
margin-left: 20px;
|
||||
margin-bottom: 12px;
|
||||
color: #666;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.doc-section li {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.code-block {
|
||||
background: #f5f5f5;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
margin: 15px 0;
|
||||
}
|
||||
|
||||
.code-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: #efefef;
|
||||
border-bottom: 1px solid #ddd;
|
||||
font-weight: 500;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.code-block pre {
|
||||
margin: 0;
|
||||
padding: 15px;
|
||||
overflow-x: auto;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.endpoint-doc {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin: 20px 0;
|
||||
padding: 15px;
|
||||
background: #f0f2f5;
|
||||
border-left: 4px solid #1890ff;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.method-badge {
|
||||
display: inline-block;
|
||||
padding: 5px 12px;
|
||||
background: #52c41a;
|
||||
color: white;
|
||||
border-radius: 3px;
|
||||
font-weight: bold;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.endpoint-url {
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.pricing-table,
|
||||
.param-table,
|
||||
.error-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 15px 0;
|
||||
background: white;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.pricing-table th,
|
||||
.param-table th,
|
||||
.error-table th {
|
||||
background: #fafafa;
|
||||
padding: 12px;
|
||||
border: 1px solid #ddd;
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.pricing-table td,
|
||||
.param-table td,
|
||||
.error-table td {
|
||||
padding: 12px;
|
||||
border: 1px solid #ddd;
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.pricing-table tr:hover,
|
||||
.param-table tr:hover,
|
||||
.error-table tr:hover {
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.pricing-table td:first-child,
|
||||
.param-table td:first-child,
|
||||
.error-table td:first-child {
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
163
NBATransfer-frontend/src/pages/ApiDocumentation.tsx
Normal file
163
NBATransfer-frontend/src/pages/ApiDocumentation.tsx
Normal file
@@ -0,0 +1,163 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Card, Tabs, Alert, Button, Space, message } from 'antd';
|
||||
import { CopyOutlined } from '@ant-design/icons';
|
||||
import './ApiDocumentation.css';
|
||||
|
||||
const ApiDocumentation: React.FC = () => {
|
||||
const [selectedExample, setSelectedExample] = useState('curl');
|
||||
|
||||
const copyToClipboard = (text: string) => {
|
||||
navigator.clipboard.writeText(text);
|
||||
message.success('已复制到剪贴板');
|
||||
};
|
||||
|
||||
const API_BASE_URL = 'https://api.nanobananapi.com/v1';
|
||||
|
||||
// 示例代码
|
||||
const examples = {
|
||||
curl: `curl ${API_BASE_URL}/chat/completions \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "Authorization: Bearer sk_your_api_key_here" \\
|
||||
-d '{
|
||||
"model": "deepseek-chat",
|
||||
"messages": [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": "Hello!"}
|
||||
],
|
||||
"stream": false
|
||||
}'`,
|
||||
|
||||
python: `import requests
|
||||
|
||||
url = "${API_BASE_URL}/chat/completions"
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer sk_your_api_key_here"
|
||||
}
|
||||
|
||||
data = {
|
||||
"model": "deepseek-chat",
|
||||
"messages": [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": "Hello!"}
|
||||
],
|
||||
"stream": False
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
print(response.json())`,
|
||||
|
||||
nodejs: `const axios = require('axios');
|
||||
|
||||
const url = '${API_BASE_URL}/chat/completions';
|
||||
const apiKey = 'sk_your_api_key_here';
|
||||
|
||||
const data = {
|
||||
model: 'deepseek-chat',
|
||||
messages: [
|
||||
{ role: 'system', content: 'You are a helpful assistant.' },
|
||||
{ role: 'user', content: 'Hello!' }
|
||||
],
|
||||
stream: false
|
||||
};
|
||||
|
||||
axios.post(url, data, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': \`Bearer \${apiKey}\`
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
console.log(response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});`
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ padding: '24px' }}>
|
||||
<Card>
|
||||
<h1>🍌 大语言模型API中转站文档</h1>
|
||||
|
||||
<Alert
|
||||
message="API 接口地址"
|
||||
description={API_BASE_URL}
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: '20px' }}
|
||||
/>
|
||||
|
||||
<div className="doc-section">
|
||||
<h2>认证方式</h2>
|
||||
<p>所有 API 请求都需要在 HTTP 请求头中提供 API Key:</p>
|
||||
|
||||
<div className="code-block">
|
||||
<div className="code-header">
|
||||
<span>HTTP Headers</span>
|
||||
<Button
|
||||
type="text"
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() =>
|
||||
copyToClipboard('Authorization: Bearer sk_your_api_key_here')
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<pre>{`Authorization: Bearer sk_your_api_key_here`}</pre>
|
||||
</div>
|
||||
<p style={{ marginTop: '10px', fontSize: '14px', color: '#666' }}>
|
||||
* 您可以在 "API 密钥管理" 页面创建和获取您的 API Key。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="doc-section" style={{ marginTop: '30px' }}>
|
||||
<h2>DeepSeek API 调用示例</h2>
|
||||
<p>我们完全兼容 OpenAI 格式的接口调用,只需将 Base URL 替换为我们的接口地址,并使用我们的 API Key 即可。</p>
|
||||
|
||||
<div style={{ marginBottom: '20px', marginTop: '20px' }}>
|
||||
<Space>
|
||||
{Object.keys(examples).map((lang) => (
|
||||
<Button
|
||||
key={lang}
|
||||
type={selectedExample === lang ? 'primary' : 'default'}
|
||||
onClick={() => setSelectedExample(lang)}
|
||||
>
|
||||
{lang === 'curl'
|
||||
? 'cURL'
|
||||
: lang === 'python'
|
||||
? 'Python'
|
||||
: 'Node.js'}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
<div className="code-block">
|
||||
<div className="code-header">
|
||||
<span>
|
||||
{selectedExample === 'curl'
|
||||
? 'cURL'
|
||||
: selectedExample === 'python'
|
||||
? 'Python'
|
||||
: 'Node.js'}
|
||||
</span>
|
||||
<Button
|
||||
type="text"
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() =>
|
||||
copyToClipboard(
|
||||
examples[selectedExample as keyof typeof examples]
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<pre>{examples[selectedExample as keyof typeof examples]}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ApiDocumentation;
|
||||
14
NBATransfer-frontend/src/pages/ApiKeyManagement.css
Normal file
14
NBATransfer-frontend/src/pages/ApiKeyManagement.css
Normal file
@@ -0,0 +1,14 @@
|
||||
.api-key-copy {
|
||||
cursor: pointer;
|
||||
font-family: 'Courier New', monospace;
|
||||
user-select: all;
|
||||
background: #f5f5f5;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #d9d9d9;
|
||||
}
|
||||
|
||||
.api-key-copy:hover {
|
||||
background: #e6e6e6;
|
||||
border-color: #b3b3b3;
|
||||
}
|
||||
347
NBATransfer-frontend/src/pages/ApiKeyManagement.tsx
Normal file
347
NBATransfer-frontend/src/pages/ApiKeyManagement.tsx
Normal file
@@ -0,0 +1,347 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Card,
|
||||
Button,
|
||||
Table,
|
||||
Modal,
|
||||
Form,
|
||||
Input,
|
||||
Space,
|
||||
message,
|
||||
Empty,
|
||||
Spin,
|
||||
Tag,
|
||||
Tooltip,
|
||||
Popconfirm,
|
||||
Alert,
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined,
|
||||
DeleteOutlined,
|
||||
CopyOutlined,
|
||||
ReloadOutlined,
|
||||
LockOutlined,
|
||||
UnlockOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { apikeyAPI } from '../api';
|
||||
import type { ApiKey } from '../types';
|
||||
import './ApiKeyManagement.css';
|
||||
|
||||
const ApiKeyManagement: React.FC = () => {
|
||||
const [apiKeys, setApiKeys] = useState<ApiKey[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [createModalVisible, setCreateModalVisible] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const [newKeyData, setNewKeyData] = useState<{ api_key: string } | null>(
|
||||
null
|
||||
);
|
||||
const [newKeyModalVisible, setNewKeyModalVisible] = useState(false);
|
||||
|
||||
// 获取 API 密钥列表
|
||||
const fetchApiKeys = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await apikeyAPI.getKeys();
|
||||
setApiKeys(response.data.keys || []);
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.error || '获取 API 密钥列表失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiKeys();
|
||||
}, []);
|
||||
|
||||
// 创建新密钥
|
||||
const handleCreateKey = async (values: { name: string }) => {
|
||||
try {
|
||||
const response = await apikeyAPI.createKey({ name: values.name });
|
||||
|
||||
// 展示新生成的密钥(只会显示一次)
|
||||
setNewKeyData({
|
||||
api_key: response.data.key.api_key,
|
||||
});
|
||||
setNewKeyModalVisible(true);
|
||||
setCreateModalVisible(false);
|
||||
form.resetFields();
|
||||
|
||||
// 刷新列表
|
||||
await fetchApiKeys();
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.error || '创建 API 密钥失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 删除密钥
|
||||
const handleDeleteKey = async (id: number) => {
|
||||
try {
|
||||
await apikeyAPI.deleteKey(id);
|
||||
message.success('API 密钥已删除');
|
||||
await fetchApiKeys();
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.error || '删除 API 密钥失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 切换密钥激活状态
|
||||
const handleToggleActive = async (id: number, currentStatus: boolean) => {
|
||||
try {
|
||||
await apikeyAPI.updateKey(id, { is_active: !currentStatus });
|
||||
message.success(!currentStatus ? 'API 密钥已激活' : 'API 密钥已停用');
|
||||
await fetchApiKeys();
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.error || '更新 API 密钥失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 轮换 API Key
|
||||
const handleRegenerateKey = async (id: number) => {
|
||||
try {
|
||||
const response = await apikeyAPI.regenerateKey(id);
|
||||
|
||||
// 展示新秘钥
|
||||
setNewKeyData({
|
||||
api_key: response.data.key.api_key,
|
||||
});
|
||||
setNewKeyModalVisible(true);
|
||||
|
||||
// 刷新列表
|
||||
await fetchApiKeys();
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.error || '重置 Key 失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 复制到剪贴板
|
||||
const copyToClipboard = (text: string) => {
|
||||
navigator.clipboard.writeText(text);
|
||||
message.success('已复制到剪贴板');
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: 'API Key',
|
||||
dataIndex: 'api_key',
|
||||
key: 'api_key',
|
||||
width: 200,
|
||||
render: (text: string) => (
|
||||
<Tooltip title="点击复制">
|
||||
<div
|
||||
onClick={() => copyToClipboard(text)}
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
fontFamily: 'monospace',
|
||||
wordBreak: 'break-all',
|
||||
}}
|
||||
>
|
||||
{text}
|
||||
<CopyOutlined style={{ marginLeft: '8px' }} />
|
||||
</div>
|
||||
</Tooltip>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'is_active',
|
||||
key: 'is_active',
|
||||
width: 100,
|
||||
render: (isActive: boolean) => (
|
||||
<Tag color={isActive ? 'green' : 'red'}>{isActive ? '激活' : '已停用'}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'created_at',
|
||||
key: 'created_at',
|
||||
width: 180,
|
||||
render: (text: string) => new Date(text).toLocaleString('zh-CN'),
|
||||
},
|
||||
{
|
||||
title: '最后使用',
|
||||
dataIndex: 'last_used_at',
|
||||
key: 'last_used_at',
|
||||
width: 180,
|
||||
render: (text?: string) =>
|
||||
text ? new Date(text).toLocaleString('zh-CN') : '从未使用过',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
render: (_: any, record: ApiKey) => (
|
||||
<Space size="small" wrap>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
icon={record.is_active ? <LockOutlined /> : <UnlockOutlined />}
|
||||
onClick={() => handleToggleActive(record.id, record.is_active)}
|
||||
>
|
||||
{record.is_active ? '停用' : '启用'}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => handleRegenerateKey(record.id)}
|
||||
>
|
||||
重置 Key
|
||||
</Button>
|
||||
|
||||
<Popconfirm
|
||||
title="删除 API 密钥"
|
||||
description="确定要删除该 API 密钥吗?删除后无法恢复。"
|
||||
onConfirm={() => handleDeleteKey(record.id)}
|
||||
okText="确定"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Button type="text" danger size="small" icon={<DeleteOutlined />}>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ padding: '24px' }}>
|
||||
<Card>
|
||||
<div style={{ marginBottom: '20px', display: 'flex', justifyContent: 'space-between' }}>
|
||||
<h2>API 密钥管理</h2>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => setCreateModalVisible(true)}
|
||||
>
|
||||
创建新密钥
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Alert
|
||||
message="重要提示"
|
||||
description="API Key 只在创建和重置时显示一次,请妥善保管。使用 API Key 进行 API 调用时需要进行认证。"
|
||||
type="warning"
|
||||
showIcon
|
||||
style={{ marginBottom: '20px' }}
|
||||
/>
|
||||
|
||||
<Spin spinning={loading}>
|
||||
{apiKeys.length > 0 ? (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={apiKeys}
|
||||
rowKey="id"
|
||||
pagination={false}
|
||||
scroll={{ x: 1200 }}
|
||||
/>
|
||||
) : (
|
||||
<Empty description="没有 API 密钥,点击下方按钮创建" />
|
||||
)}
|
||||
</Spin>
|
||||
</Card>
|
||||
|
||||
{/* 创建密钥对话框 */}
|
||||
<Modal
|
||||
title="创建新 API 密钥"
|
||||
open={createModalVisible}
|
||||
onCancel={() => {
|
||||
setCreateModalVisible(false);
|
||||
form.resetFields();
|
||||
}}
|
||||
footer={[
|
||||
<Button key="cancel" onClick={() => setCreateModalVisible(false)}>
|
||||
取消
|
||||
</Button>,
|
||||
<Button
|
||||
key="submit"
|
||||
type="primary"
|
||||
onClick={() => form.submit()}
|
||||
>
|
||||
创建
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={handleCreateKey}
|
||||
>
|
||||
<Form.Item
|
||||
name="name"
|
||||
label="密钥名称"
|
||||
rules={[
|
||||
{ required: true, message: '请输入密钥名称' },
|
||||
{ min: 1, max: 50, message: '名称长度在 1-50 个字符之间' },
|
||||
]}
|
||||
>
|
||||
<Input placeholder="例如:我的应用、测试环境等" />
|
||||
</Form.Item>
|
||||
<Alert
|
||||
message="创建后会生成 API Key,请妥善保管"
|
||||
type="info"
|
||||
showIcon
|
||||
/>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
{/* 显示新生成的密钥 */}
|
||||
<Modal
|
||||
title="✨ 新 API 密钥已生成"
|
||||
open={newKeyModalVisible}
|
||||
onOk={() => setNewKeyModalVisible(false)}
|
||||
onCancel={() => setNewKeyModalVisible(false)}
|
||||
footer={[
|
||||
<Button key="close" type="primary" onClick={() => setNewKeyModalVisible(false)}>
|
||||
我已保存
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<Alert
|
||||
message="⚠️ 重要:API Key 仅显示一次"
|
||||
description="请立即复制并妥善保管。关闭此对话框后,API Key 将不再显示。如果丢失,需要重新生成。"
|
||||
type="error"
|
||||
showIcon
|
||||
style={{ marginBottom: '20px' }}
|
||||
/>
|
||||
|
||||
{newKeyData && (
|
||||
<div>
|
||||
<div style={{ marginBottom: '15px' }}>
|
||||
<label style={{ display: 'block', marginBottom: '8px', fontWeight: 'bold' }}>
|
||||
API Key:
|
||||
</label>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: '8px',
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
value={newKeyData.api_key}
|
||||
readOnly
|
||||
style={{ fontFamily: 'monospace', wordBreak: 'break-all' }}
|
||||
/>
|
||||
<Button
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() => copyToClipboard(newKeyData.api_key)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ApiKeyManagement;
|
||||
51
NBATransfer-frontend/src/pages/Dashboard.css
Normal file
51
NBATransfer-frontend/src/pages/Dashboard.css
Normal file
@@ -0,0 +1,51 @@
|
||||
.dashboard-home h1 {
|
||||
margin-bottom: 24px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 400px;
|
||||
}
|
||||
|
||||
.quick-start {
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
.quick-start h3 {
|
||||
font-size: 18px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.quick-start ol {
|
||||
padding-left: 24px;
|
||||
line-height: 2;
|
||||
}
|
||||
|
||||
.quick-start ol li {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.pricing-info {
|
||||
margin-top: 24px;
|
||||
padding: 16px;
|
||||
background: #f5f5f5;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.pricing-info p {
|
||||
margin: 8px 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.dashboard-home h1 {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.quick-start h3 {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
111
NBATransfer-frontend/src/pages/Dashboard.tsx
Normal file
111
NBATransfer-frontend/src/pages/Dashboard.tsx
Normal file
@@ -0,0 +1,111 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Row, Col, Card, Statistic, Spin } from 'antd';
|
||||
import { ApiOutlined, CheckCircleOutlined, CloseCircleOutlined, WalletOutlined } from '@ant-design/icons';
|
||||
import { userAPI } from '../api';
|
||||
import type { Stats } from '../types';
|
||||
import './Dashboard.css';
|
||||
|
||||
const Dashboard: React.FC = () => {
|
||||
const [stats, setStats] = useState<Stats | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
fetchStats();
|
||||
}, []);
|
||||
|
||||
const fetchStats = async () => {
|
||||
try {
|
||||
const response = await userAPI.getStats();
|
||||
setStats(response.data);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch stats:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="loading-container">
|
||||
<Spin size="large" tip="加载中..." />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="dashboard-home">
|
||||
<h1>数据概览</h1>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="总调用次数"
|
||||
value={stats?.total_calls || 0}
|
||||
prefix={<ApiOutlined />}
|
||||
valueStyle={{ color: '#1890ff' }}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="成功调用"
|
||||
value={stats?.success_calls || 0}
|
||||
prefix={<CheckCircleOutlined />}
|
||||
valueStyle={{ color: '#52c41a' }}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="失败调用"
|
||||
value={stats?.failed_calls || 0}
|
||||
prefix={<CloseCircleOutlined />}
|
||||
valueStyle={{ color: '#ff4d4f' }}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="总消费"
|
||||
value={stats?.total_cost || 0}
|
||||
prefix={<WalletOutlined />}
|
||||
precision={2}
|
||||
valueStyle={{ color: '#fa8c16' }}
|
||||
suffix="元"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 16]} style={{ marginTop: '24px' }}>
|
||||
<Col span={24}>
|
||||
<Card title="快速开始">
|
||||
<div className="quick-start">
|
||||
<h3>🎨 如何使用大语言模型API中转站</h3>
|
||||
<ol>
|
||||
<li>
|
||||
<strong>充值账户</strong>: 前往"我的钱包"充值余额
|
||||
</li>
|
||||
<li>
|
||||
<strong>调用API</strong>: 进入"API调用"页面生成图片
|
||||
</li>
|
||||
<li>
|
||||
<strong>查看记录</strong>: 在"历史记录"查看所有调用记录
|
||||
</li>
|
||||
</ol>
|
||||
<div className="pricing-info">
|
||||
<p><strong>⚡ 速度</strong>: 平均生成时间 10-30 秒</p>
|
||||
<p><strong>🎯 质量</strong>: 专业级AI图像生成</p>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Dashboard;
|
||||
42
NBATransfer-frontend/src/pages/Login.css
Normal file
42
NBATransfer-frontend/src/pages/Login.css
Normal file
@@ -0,0 +1,42 @@
|
||||
.login-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f0f2f5;
|
||||
background-image: url("data:image/svg+xml,%3Csvg width='64' height='64' viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M8 16c4.418 0 8-3.582 8-8s-3.582-8-8-8-8 3.582-8 8 3.582 8 8 8zm0-2c3.314 0 6-2.686 6-6s-2.686-6-6-6-6 2.686-6 6 2.686 6 6 6zm33.414-6l5.95-5.95L45.95.636 40 6.586 34.05.636 32.636 2.05 38.586 8l-5.95 5.95 1.414 1.414L40 9.414l5.95 5.95 1.414-1.414L41.414 8zM40 48c4.418 0 8-3.582 8-8s-3.582-8-8-8-8 3.582-8 8 3.582 8 8 8zm0-2c3.314 0 6-2.686 6-6s-2.686-6-6-6-6 2.686-6 6 2.686 6 6 6zM9.414 40l5.95-5.95-1.414-1.414L8 38.586l-5.95-5.95L.636 34.05 6.586 40l-5.95 5.95 1.414 1.414L8 41.414l5.95 5.95 1.414-1.414L9.414 40z' fill='%239C92AC' fill-opacity='0.05' fill-rule='evenodd'/%3E%3C/svg%3E");
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
width: 100%;
|
||||
max-width: 450px;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 28px;
|
||||
margin-bottom: 10px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@media (max-width: 576px) {
|
||||
.login-card {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
253
NBATransfer-frontend/src/pages/Login.tsx
Normal file
253
NBATransfer-frontend/src/pages/Login.tsx
Normal file
@@ -0,0 +1,253 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Form, Input, Button, Card, message, Tabs, Space, Alert } from 'antd';
|
||||
import { LockOutlined, MailOutlined } from '@ant-design/icons';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { authAPI } from '../api';
|
||||
import { useAuthStore } from '../store/auth';
|
||||
import './Login.css';
|
||||
|
||||
const Login: React.FC = () => {
|
||||
const [loginLoading, setLoginLoading] = useState(false);
|
||||
const [registerLoading, setRegisterLoading] = useState(false);
|
||||
const [codeSent, setCodeSent] = useState(false);
|
||||
const [codeLoading, setCodeLoading] = useState(false);
|
||||
const [email, setEmail] = useState('');
|
||||
const [form] = Form.useForm();
|
||||
const navigate = useNavigate();
|
||||
const setAuth = useAuthStore((state) => state.setAuth);
|
||||
|
||||
const onLogin = async (values: { email: string; password: string }) => {
|
||||
setLoginLoading(true);
|
||||
try {
|
||||
const response = await authAPI.login(values);
|
||||
const data = response.data;
|
||||
|
||||
setAuth({
|
||||
user: data.user,
|
||||
access_token: data.access_token,
|
||||
refresh_token: data.refresh_token,
|
||||
});
|
||||
|
||||
message.success('登录成功!');
|
||||
navigate(data.user.is_admin ? '/admin' : '/dashboard');
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.error || '登录失败,请检查邮箱和密码');
|
||||
} finally {
|
||||
setLoginLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const sendVerificationCode = async () => {
|
||||
if (!email) {
|
||||
message.error('请先输入邮箱地址');
|
||||
return;
|
||||
}
|
||||
|
||||
// 简单的邮箱验证
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(email)) {
|
||||
message.error('请输入有效的邮箱地址');
|
||||
return;
|
||||
}
|
||||
|
||||
setCodeLoading(true);
|
||||
try {
|
||||
await authAPI.sendVerificationCode({ email });
|
||||
setCodeSent(true);
|
||||
message.success('验证码已发送到您的邮箱,请检查收件箱(5分钟内有效)');
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.error || '发送验证码失败');
|
||||
} finally {
|
||||
setCodeLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const onRegister = async (values: any) => {
|
||||
setRegisterLoading(true);
|
||||
try {
|
||||
const response = await authAPI.register({
|
||||
email: values.email,
|
||||
password: values.password,
|
||||
verification_code: values.code,
|
||||
});
|
||||
const data = response.data;
|
||||
|
||||
setAuth({
|
||||
user: data.user,
|
||||
access_token: data.access_token,
|
||||
refresh_token: data.refresh_token,
|
||||
});
|
||||
|
||||
message.success('注册成功!');
|
||||
navigate('/dashboard');
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.error || '注册失败');
|
||||
} finally {
|
||||
setRegisterLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const loginForm = (
|
||||
<Form
|
||||
name="login"
|
||||
onFinish={onLogin}
|
||||
autoComplete="off"
|
||||
size="large"
|
||||
>
|
||||
<Form.Item
|
||||
name="email"
|
||||
rules={[
|
||||
{ required: true, message: '请输入邮箱' },
|
||||
{ type: 'email', message: '请输入有效的邮箱地址' },
|
||||
]}
|
||||
>
|
||||
<Input prefix={<MailOutlined />} placeholder="邮箱" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="password"
|
||||
rules={[{ required: true, message: '请输入密码' }]}
|
||||
>
|
||||
<Input.Password prefix={<LockOutlined />} placeholder="密码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Button type="primary" htmlType="submit" loading={loginLoading} block>
|
||||
登录
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
);
|
||||
|
||||
const registerForm = (
|
||||
<Form
|
||||
form={form}
|
||||
name="register"
|
||||
onFinish={onRegister}
|
||||
autoComplete="off"
|
||||
size="large"
|
||||
>
|
||||
<Alert
|
||||
message="邮箱验证注册"
|
||||
description="注册需要邮箱验证,我们会发送6位验证码到您的邮箱"
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: '20px' }}
|
||||
/>
|
||||
|
||||
<Form.Item
|
||||
name="email"
|
||||
rules={[
|
||||
{ required: true, message: '请输入邮箱' },
|
||||
{ type: 'email', message: '请输入有效的邮箱地址' },
|
||||
]}
|
||||
>
|
||||
<Input
|
||||
prefix={<MailOutlined />}
|
||||
placeholder="邮箱(QQ邮箱推荐)"
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
disabled={codeSent}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Button
|
||||
type="dashed"
|
||||
onClick={sendVerificationCode}
|
||||
loading={codeLoading}
|
||||
block
|
||||
disabled={codeSent}
|
||||
>
|
||||
{codeSent ? '✓ 验证码已发送' : '发送验证码'}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
|
||||
{codeSent && (
|
||||
<>
|
||||
<Form.Item
|
||||
name="code"
|
||||
rules={[
|
||||
{ required: true, message: '请输入验证码' },
|
||||
{ len: 6, message: '验证码为6位数字' },
|
||||
{ pattern: /^\d{6}$/, message: '验证码只能是6位数字' },
|
||||
]}
|
||||
>
|
||||
<Input placeholder="6位验证码" maxLength={6} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="password"
|
||||
rules={[
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ min: 6, message: '密码至少6位' },
|
||||
]}
|
||||
>
|
||||
<Input.Password prefix={<LockOutlined />} placeholder="密码(至少6位)" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="confirm"
|
||||
dependencies={['password']}
|
||||
rules={[
|
||||
{ required: true, message: '请确认密码' },
|
||||
({ getFieldValue }) => ({
|
||||
validator(_, value) {
|
||||
if (!value || getFieldValue('password') === value) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.reject(new Error('两次密码不一致'));
|
||||
},
|
||||
}),
|
||||
]}
|
||||
>
|
||||
<Input.Password prefix={<LockOutlined />} placeholder="确认密码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Space style={{ width: '100%' }}>
|
||||
<Button type="primary" htmlType="submit" loading={registerLoading} block>
|
||||
注册
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setCodeSent(false);
|
||||
form.resetFields();
|
||||
}}
|
||||
>
|
||||
重新输入邮箱
|
||||
</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</>
|
||||
)}
|
||||
</Form>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="login-container">
|
||||
<Card className="login-card">
|
||||
<div className="login-header">
|
||||
<h1>🍌 大语言模型API中转站</h1>
|
||||
<p>专业的AI大模型API中转服务平台</p>
|
||||
</div>
|
||||
<Tabs
|
||||
defaultActiveKey="login"
|
||||
items={[
|
||||
{
|
||||
key: 'login',
|
||||
label: '登录',
|
||||
children: loginForm,
|
||||
},
|
||||
{
|
||||
key: 'register',
|
||||
label: '注册',
|
||||
children: registerForm,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Login;
|
||||
8
NBATransfer-frontend/src/pages/Settings.css
Normal file
8
NBATransfer-frontend/src/pages/Settings.css
Normal file
@@ -0,0 +1,8 @@
|
||||
.settings-page {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
max-width: 600px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
86
NBATransfer-frontend/src/pages/Settings.tsx
Normal file
86
NBATransfer-frontend/src/pages/Settings.tsx
Normal file
@@ -0,0 +1,86 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Card, Form, Input, Button, message, Divider } from 'antd';
|
||||
import { LockOutlined } from '@ant-design/icons';
|
||||
import { authAPI } from '../api';
|
||||
import './Settings.css';
|
||||
|
||||
const Settings: React.FC = () => {
|
||||
const [passwordLoading, setPasswordLoading] = useState(false);
|
||||
const [passwordForm] = Form.useForm();
|
||||
|
||||
const onChangePassword = async (values: any) => {
|
||||
setPasswordLoading(true);
|
||||
try {
|
||||
await authAPI.changePassword({
|
||||
old_password: values.old_password,
|
||||
new_password: values.new_password,
|
||||
});
|
||||
message.success('密码修改成功');
|
||||
passwordForm.resetFields();
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.error || '密码修改失败');
|
||||
} finally {
|
||||
setPasswordLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="settings-page">
|
||||
<h1>账户设置</h1>
|
||||
|
||||
<Card title="修改密码" className="settings-card">
|
||||
<Form
|
||||
form={passwordForm}
|
||||
layout="vertical"
|
||||
onFinish={onChangePassword}
|
||||
>
|
||||
<Form.Item
|
||||
name="old_password"
|
||||
label="当前密码"
|
||||
rules={[{ required: true, message: '请输入当前密码' }]}
|
||||
>
|
||||
<Input.Password prefix={<LockOutlined />} placeholder="当前密码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="new_password"
|
||||
label="新密码"
|
||||
rules={[
|
||||
{ required: true, message: '请输入新密码' },
|
||||
{ min: 6, message: '密码长度至少为6位' },
|
||||
]}
|
||||
>
|
||||
<Input.Password prefix={<LockOutlined />} placeholder="新密码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="confirm_password"
|
||||
label="确认新密码"
|
||||
dependencies={['new_password']}
|
||||
rules={[
|
||||
{ required: true, message: '请确认新密码' },
|
||||
({ getFieldValue }) => ({
|
||||
validator(_, value) {
|
||||
if (!value || getFieldValue('new_password') === value) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.reject(new Error('两次密码不一致'));
|
||||
},
|
||||
}),
|
||||
]}
|
||||
>
|
||||
<Input.Password prefix={<LockOutlined />} placeholder="确认新密码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Button type="primary" htmlType="submit" loading={passwordLoading}>
|
||||
修改密码
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Settings;
|
||||
215
NBATransfer-frontend/src/pages/Wallet.css
Normal file
215
NBATransfer-frontend/src/pages/Wallet.css
Normal file
@@ -0,0 +1,215 @@
|
||||
.wallet-page h1 {
|
||||
margin-bottom: 24px;
|
||||
font-size: 28px;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
/* 余额卡片 */
|
||||
.balance-card {
|
||||
background: linear-gradient(135deg, #1890ff 0%, #0050b3 100%);
|
||||
border: none;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.balance-display,
|
||||
.api-calls-display {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
color: white;
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
.balance-icon,
|
||||
.calls-icon {
|
||||
font-size: 48px;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.balance-content,
|
||||
.calls-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.balance-label,
|
||||
.calls-label {
|
||||
font-size: 14px;
|
||||
opacity: 0.9;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.balance-amount {
|
||||
font-size: 40px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.calls-count {
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 充值套餐卡片 */
|
||||
.package-card {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
border: 2px solid transparent;
|
||||
}
|
||||
|
||||
.package-card:hover {
|
||||
border-color: #1890ff;
|
||||
box-shadow: 0 4px 12px rgba(24, 144, 255, 0.15);
|
||||
}
|
||||
|
||||
.package-content {
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
.package-price {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: #ff7a45;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.package-count {
|
||||
font-size: 16px;
|
||||
color: #333;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.package-unit {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 充值提示 */
|
||||
.recharge-tips {
|
||||
margin-top: 24px;
|
||||
padding: 20px;
|
||||
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
||||
border-radius: 8px;
|
||||
border-left: 4px solid #1890ff;
|
||||
}
|
||||
|
||||
.recharge-tips h4 {
|
||||
margin-bottom: 12px;
|
||||
font-size: 16px;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.recharge-tips ul {
|
||||
margin: 0;
|
||||
padding-left: 24px;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.recharge-tips li {
|
||||
color: #555;
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
/* 支付模态框 */
|
||||
.payment-modal {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.payment-info {
|
||||
margin-bottom: 24px;
|
||||
padding: 16px;
|
||||
background: #fafafa;
|
||||
border-radius: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.payment-info p {
|
||||
margin: 8px 0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.qrcode-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 24px 0;
|
||||
}
|
||||
|
||||
.qrcode-container p {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* 响应式 */
|
||||
@media (max-width: 768px) {
|
||||
.wallet-page h1 {
|
||||
font-size: 24px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.balance-icon,
|
||||
.calls-icon {
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
.balance-amount {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.calls-count {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.package-card {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.package-price {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.package-count {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.recharge-tips {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.recharge-tips h4 {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.recharge-tips ul {
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.wallet-page h1 {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.balance-display,
|
||||
.api-calls-display {
|
||||
gap: 12px;
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
.balance-icon,
|
||||
.calls-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.balance-amount {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.calls-count {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.balance-label,
|
||||
.calls-label {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
257
NBATransfer-frontend/src/pages/Wallet.tsx
Normal file
257
NBATransfer-frontend/src/pages/Wallet.tsx
Normal file
@@ -0,0 +1,257 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Card, Button, Form, InputNumber, Radio, message, Modal, QRCode, Statistic,
|
||||
Row, Col, Divider, Spin
|
||||
} from 'antd';
|
||||
import { WalletOutlined, AlipayOutlined, WechatOutlined } from '@ant-design/icons';
|
||||
import { orderAPI, userAPI } from '../api';
|
||||
import { useAuthStore } from '../store/auth';
|
||||
import './Wallet.css';
|
||||
|
||||
const Wallet: React.FC = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [paymentMethod, setPaymentMethod] = useState('alipay');
|
||||
const [orderInfo, setOrderInfo] = useState<any>(null);
|
||||
const user = useAuthStore((state) => state.user);
|
||||
const updateUser = useAuthStore((state) => state.updateUser);
|
||||
const [form] = Form.useForm();
|
||||
|
||||
const onRecharge = async (values: { amount: number }) => {
|
||||
if (!user) return;
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await orderAPI.createOrder({
|
||||
amount: values.amount,
|
||||
payment_method: paymentMethod,
|
||||
});
|
||||
|
||||
setOrderInfo(response.data);
|
||||
setModalVisible(true);
|
||||
message.success('订单创建成功,请扫码支付');
|
||||
} catch (error: any) {
|
||||
message.error(error.response?.data?.error || '订单创建失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handlePaymentComplete = async () => {
|
||||
if (!orderInfo || !user) return;
|
||||
|
||||
try {
|
||||
// 模拟支付通知(实际生产环境由支付平台回调)
|
||||
await orderAPI.notifyPayment(orderInfo.order.order_no);
|
||||
|
||||
// 刷新用户余额
|
||||
const balanceResponse = await userAPI.getBalance();
|
||||
|
||||
updateUser({
|
||||
...user,
|
||||
balance: balanceResponse.data.balance
|
||||
});
|
||||
|
||||
message.success('充值成功!');
|
||||
setModalVisible(false);
|
||||
setOrderInfo(null);
|
||||
form.resetFields();
|
||||
} catch (error: any) {
|
||||
message.error('支付确认失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 充值套餐选项
|
||||
const rechargePackages = [
|
||||
{ amount: 10 },
|
||||
{ amount: 50 },
|
||||
{ amount: 100 },
|
||||
{ amount: 500 },
|
||||
];
|
||||
|
||||
const getPaymentMethodName = (method: string) => {
|
||||
return method === 'alipay' ? '支付宝' : '微信支付';
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="wallet-page">
|
||||
<h1>💰 我的钱包</h1>
|
||||
|
||||
{/* 余额显示卡片 */}
|
||||
<Card className="balance-card">
|
||||
<Row gutter={[24, 24]}>
|
||||
<Col xs={24} sm={12}>
|
||||
<div className="balance-display">
|
||||
<WalletOutlined className="balance-icon" />
|
||||
<div className="balance-content">
|
||||
<div className="balance-label">账户余额</div>
|
||||
<div className="balance-amount">¥{user?.balance?.toFixed(2) || '0.00'}</div>
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
|
||||
<Divider />
|
||||
|
||||
{/* 快速充值套餐 */}
|
||||
<Card title="💡 快速充值套餐" style={{ marginBottom: 24 }}>
|
||||
<Row gutter={[16, 16]}>
|
||||
{rechargePackages.map((pkg) => (
|
||||
<Col xs={24} sm={12} md={6} key={pkg.amount}>
|
||||
<Card
|
||||
hoverable
|
||||
className="package-card"
|
||||
onClick={() => {
|
||||
form.setFieldsValue({ amount: pkg.amount });
|
||||
}}
|
||||
>
|
||||
<div className="package-content">
|
||||
<div className="package-price">¥{pkg.amount}</div>
|
||||
</div>
|
||||
</Card>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
</Card>
|
||||
|
||||
{/* 自定义充值 */}
|
||||
<Card title="自定义充值金额" style={{ marginBottom: 24 }}>
|
||||
<Form
|
||||
form={form}
|
||||
onFinish={onRecharge}
|
||||
layout="vertical"
|
||||
>
|
||||
<Form.Item
|
||||
label="充值金额"
|
||||
name="amount"
|
||||
rules={[
|
||||
{ required: true, message: '请输入充值金额' },
|
||||
{ type: 'number', min: 1, max: 100000, message: '充值金额需在 ¥1 - ¥100000 之间' },
|
||||
]}
|
||||
>
|
||||
<InputNumber
|
||||
style={{ width: '100%' }}
|
||||
min={1}
|
||||
max={100000}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
placeholder="请输入充值金额"
|
||||
size="large"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="支付方式">
|
||||
<Radio.Group
|
||||
value={paymentMethod}
|
||||
onChange={(e) => setPaymentMethod(e.target.value)}
|
||||
size="large"
|
||||
>
|
||||
<Radio.Button value="alipay">
|
||||
<AlipayOutlined /> 支付宝
|
||||
</Radio.Button>
|
||||
<Radio.Button value="wechat">
|
||||
<WechatOutlined /> 微信支付
|
||||
</Radio.Button>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Button
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
size="large"
|
||||
block
|
||||
loading={loading}
|
||||
disabled={!user || (user.balance >= 100000)}
|
||||
>
|
||||
{loading ? '创建订单中...' : '立即充值'}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
<Divider />
|
||||
|
||||
<div className="recharge-tips">
|
||||
<h4>充值说明</h4>
|
||||
<ul>
|
||||
<li>✓ 充值后立即到账,无需等待</li>
|
||||
<li>✓ 余额可用于所有 API 调用</li>
|
||||
<li>✓ 最低充值金额: ¥1.00</li>
|
||||
<li>✓ 最高余额限制: ¥100,000</li>
|
||||
<li>✓ 余额永不过期</li>
|
||||
<li>✓ 如有问题请联系在线客服</li>
|
||||
</ul>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* 支付模态框 */}
|
||||
<Modal
|
||||
title="扫码支付"
|
||||
open={modalVisible}
|
||||
onCancel={() => setModalVisible(false)}
|
||||
width={450}
|
||||
footer={[
|
||||
<Button key="cancel" onClick={() => setModalVisible(false)}>
|
||||
取消
|
||||
</Button>,
|
||||
<Button key="confirm" type="primary" onClick={handlePaymentComplete}>
|
||||
我已完成支付
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
{orderInfo ? (
|
||||
<div className="payment-modal">
|
||||
<div className="payment-info">
|
||||
<Row gutter={16} style={{ marginBottom: 24 }}>
|
||||
<Col span={24}>
|
||||
<Statistic
|
||||
title="订单号"
|
||||
value={orderInfo.order.order_no}
|
||||
valueStyle={{ fontSize: '14px', fontFamily: 'monospace' }}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16} style={{ marginBottom: 24 }}>
|
||||
<Col xs={12}>
|
||||
<Statistic
|
||||
title="充值金额"
|
||||
value={orderInfo.order.amount}
|
||||
prefix="¥"
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={12}>
|
||||
<Statistic
|
||||
title="支付方式"
|
||||
value={getPaymentMethodName(orderInfo.order.payment_method)}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
<Divider />
|
||||
<div className="qrcode-container">
|
||||
<p style={{ textAlign: 'center', marginBottom: 16, color: '#666' }}>
|
||||
请使用 {getPaymentMethodName(orderInfo.order.payment_method)} 扫描下方二维码支付
|
||||
</p>
|
||||
<div style={{ textAlign: 'center' }}>
|
||||
<QRCode
|
||||
value={orderInfo.payment?.payment_url || `payment:${orderInfo.order.order_no}`}
|
||||
size={240}
|
||||
level="H"
|
||||
includeMargin={true}
|
||||
/>
|
||||
</div>
|
||||
<p style={{ marginTop: 16, textAlign: 'center', fontSize: '12px', color: '#999' }}>
|
||||
支付完成后,点击"我已完成支付"按钮
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<Spin />
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Wallet;
|
||||
60
NBATransfer-frontend/src/store/auth.ts
Normal file
60
NBATransfer-frontend/src/store/auth.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
email: string;
|
||||
username: string;
|
||||
balance: number;
|
||||
is_active: boolean;
|
||||
is_admin: boolean;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
interface AuthState {
|
||||
user: User | null;
|
||||
accessToken: string | null;
|
||||
refreshToken: string | null;
|
||||
isAuthenticated: boolean;
|
||||
setAuth: (data: { user: User; access_token: string; refresh_token: string }) => void;
|
||||
updateUser: (user: User) => void;
|
||||
logout: () => void;
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
user: null,
|
||||
accessToken: null,
|
||||
refreshToken: null,
|
||||
isAuthenticated: false,
|
||||
setAuth: (data) => {
|
||||
localStorage.setItem('access_token', data.access_token);
|
||||
localStorage.setItem('refresh_token', data.refresh_token);
|
||||
set({
|
||||
user: data.user,
|
||||
accessToken: data.access_token,
|
||||
refreshToken: data.refresh_token,
|
||||
isAuthenticated: true,
|
||||
});
|
||||
},
|
||||
updateUser: (user) => {
|
||||
set({ user });
|
||||
},
|
||||
logout: () => {
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('refresh_token');
|
||||
set({
|
||||
user: null,
|
||||
accessToken: null,
|
||||
refreshToken: null,
|
||||
isAuthenticated: false,
|
||||
});
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: 'auth-storage',
|
||||
}
|
||||
)
|
||||
);
|
||||
54
NBATransfer-frontend/src/types/index.ts
Normal file
54
NBATransfer-frontend/src/types/index.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
export interface User {
|
||||
id: number;
|
||||
email: string;
|
||||
username: string;
|
||||
balance: number;
|
||||
is_active: boolean;
|
||||
is_admin: boolean;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface ApiKey {
|
||||
id: number;
|
||||
user_id: number;
|
||||
api_key: string;
|
||||
name: string;
|
||||
is_active: boolean;
|
||||
last_used_at?: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Order {
|
||||
id: number;
|
||||
order_no: string;
|
||||
amount: number;
|
||||
status: 'pending' | 'paid' | 'cancelled';
|
||||
payment_method: 'alipay' | 'wechat';
|
||||
created_at: string;
|
||||
paid_at?: string;
|
||||
}
|
||||
|
||||
export interface ApiCall {
|
||||
id: number;
|
||||
user_id: number;
|
||||
model: string;
|
||||
cost: number;
|
||||
status: 'success' | 'failed' | 'processing';
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Stats {
|
||||
total_calls: number;
|
||||
success_calls: number;
|
||||
failed_calls: number;
|
||||
total_cost: number;
|
||||
total_recharge: number;
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T> {
|
||||
data: T[];
|
||||
total: number;
|
||||
page: number;
|
||||
per_page: number;
|
||||
pages: number;
|
||||
}
|
||||
28
NBATransfer-frontend/tsconfig.app.json
Normal file
28
NBATransfer-frontend/tsconfig.app.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"types": ["vite/client"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
7
NBATransfer-frontend/tsconfig.json
Normal file
7
NBATransfer-frontend/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
26
NBATransfer-frontend/tsconfig.node.json
Normal file
26
NBATransfer-frontend/tsconfig.node.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
7
NBATransfer-frontend/vite.config.ts
Normal file
7
NBATransfer-frontend/vite.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
||||
17
NBATransfer-frontend/前端文档.md
Normal file
17
NBATransfer-frontend/前端文档.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Nano Banana API Frontend
|
||||
|
||||
## Project Setup
|
||||
|
||||
1. Install dependencies:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
2. Start development server:
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Check `.env` for API URL configuration.
|
||||
20
NBATransfer-frontend/启动前端.bat
Normal file
20
NBATransfer-frontend/启动前端.bat
Normal file
@@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
title Nano Banana API - 启动前端服务
|
||||
|
||||
cd /d "%~dp0NBATransfer-frontend"
|
||||
|
||||
echo.
|
||||
echo ============================================
|
||||
echo 🍌 Nano Banana API - 前端服务
|
||||
echo ============================================
|
||||
echo.
|
||||
echo 启动前端开发服务器...
|
||||
echo.
|
||||
echo 📍 访问地址:http://localhost:5173
|
||||
echo.
|
||||
echo 按 Ctrl+C 停止服务
|
||||
echo.
|
||||
|
||||
call npm run dev
|
||||
pause
|
||||
Reference in New Issue
Block a user