fix: 登录后自动加载对话历史;新增生产部署指南 DEPLOY.md
- 修复 useChat useEffect 只在挂载时执行导致的登录后无历史问题 - 暴露 reloadConversations 函数,App.tsx 登录成功后主动调用 - 添加 DEPLOY.md 生产部署文档(Nginx + PHP-FPM) 2026-05-15
This commit is contained in:
@@ -1,73 +1,82 @@
|
||||
# React + TypeScript + Vite
|
||||
# Chat App
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
一个自托管的 LLM 聊天应用,支持多会话管理、流式响应和模型配置。
|
||||
|
||||
Currently, two official plugins are available:
|
||||
## 技术栈
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
**前端**
|
||||
- React 19 + TypeScript + Vite
|
||||
- Tailwind CSS 3.4 + shadcn/ui
|
||||
- SSE 流式接收 AI 回复
|
||||
|
||||
## React Compiler
|
||||
**后端**
|
||||
- PHP 8.3 + Slim 4
|
||||
- SQLite 单文件数据库
|
||||
- JWT 认证
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
## 功能特性
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
- 🖥️ 终端风格登录页
|
||||
- 💬 多会话聊天管理
|
||||
- ⚡ SSE 流式响应
|
||||
- 🔧 模型配置面板(DeepSeek / Kimi / 自定义)
|
||||
- 🔐 固定密码登录(通过 `CHAT_PASSWORD` 环境变量)
|
||||
- 📱 响应式布局
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
## 快速开始
|
||||
|
||||
```js
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
### 安装依赖
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
```bash
|
||||
# 前端依赖
|
||||
npm install
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
# 后端依赖(PHP + Composer)
|
||||
cd server && composer install
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
### 开发运行
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
```bash
|
||||
# 同时启动前端和后端
|
||||
npm run dev
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
# 前端 http://localhost:3000
|
||||
# 后端 http://localhost:8000
|
||||
```
|
||||
|
||||
### 生产构建
|
||||
|
||||
```bash
|
||||
# 构建前端
|
||||
npm run build
|
||||
|
||||
# 后端无需构建,直接部署 server/ 目录即可
|
||||
```
|
||||
|
||||
## 环境变量
|
||||
|
||||
| 变量 | 说明 | 默认值 |
|
||||
|------|------|--------|
|
||||
| `CHAT_PASSWORD` | 登录密码 | `admin` |
|
||||
| `JWT_SECRET` | JWT 签名密钥 | 内置默认值 |
|
||||
|
||||
## 部署
|
||||
|
||||
将以下目录上传至服务器:
|
||||
- `dist/` — 前端构建产物
|
||||
- `server/` — PHP 后端源码
|
||||
|
||||
配置 Web 服务器将 `server/public/` 设为根目录,并设置 `dist/` 的别名。
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
chat-app/
|
||||
├── src/ # 前端源码
|
||||
├── server/ # PHP 后端
|
||||
│ ├── public/ # Web 入口
|
||||
│ └── src/ # 业务代码
|
||||
├── dist/ # 前端构建产物(Git 忽略)
|
||||
└── package.json
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user