后端管理模块部署

This commit is contained in:
2025-10-30 16:55:22 +08:00
parent 093d07ab76
commit 8f2133f3af
16 changed files with 649 additions and 52 deletions
+49 -8
View File
@@ -47,6 +47,7 @@
#### 前端技术栈 #### 前端技术栈
- **Web端**: Vue 3.4.21 + TypeScript 5.4.2 + Vite 5.1.6 - **Web端**: Vue 3.4.21 + TypeScript 5.4.2 + Vite 5.1.6
- **管理后台**: Vue 3.4.0 + TypeScript 5.3.3 + Element Plus 2.4.4
- **移动端**: SwiftUI (iOS原生) - **移动端**: SwiftUI (iOS原生)
- **UI框架**: Element Plus 2.6.1 + Tailwind CSS 3.4.1 - **UI框架**: Element Plus 2.6.1 + Tailwind CSS 3.4.1
- **状态管理**: Pinia 2.1.7 - **状态管理**: Pinia 2.1.7
@@ -108,10 +109,10 @@ cd backend
- Node.js 18+ - Node.js 18+
- npm 9+ - npm 9+
#### 安装与启动 #### 用户前端 (web)
```bash ```bash
# 进入新版本Web目录 # 进入前端目录
cd web-new cd web
# 安装依赖 # 安装依赖
npm install npm install
@@ -121,6 +122,38 @@ npm run dev
# 构建生产版本 # 构建生产版本
npm run build npm run build
# 部署到服务器
bash deploy.sh
```
#### 管理后台 (web-admin)
```bash
# 进入管理后台目录
cd web-admin
# 安装依赖
npm install
# 启动开发服务器
npm run dev
# 构建生产版本
npm run build
# 部署到服务器
bash deploy.sh
```
### 一键部署
```bash
# 部署所有服务(后端 + 前端 + 管理后台)
bash deploy-all.sh
# 部署指定服务
bash deploy-all.sh backend # 仅部署后端
bash deploy-all.sh frontend # 仅部署前端
bash deploy-all.sh admin # 仅部署管理后台
``` ```
## 📊 核心功能模块 ## 📊 核心功能模块
@@ -167,11 +200,19 @@ npm run build
4. 集成Tailwind CSS样式框架 4. 集成Tailwind CSS样式框架
5. 使用Pinia进行状态管理 5. 使用Pinia进行状态管理
### API文档 ### 访问地址
- 网关地址: http://localhost:8080
- 用户服务: http://localhost:8081 #### 生产环境 (101.200.208.45)
- AI服务: http://localhost:8082 - **用户前端**: http://101.200.208.45/emotion-museum/
- 各服务健康检查: http://localhost:{port}/actuator/health - **管理后台**: http://101.200.208.45/emotion-museum-admin/
- **后端API**: http://101.200.208.45:19089/api
- **WebSocket**: ws://101.200.208.45:19089/ws
#### 开发环境 (本地)
- **用户前端**: http://localhost:5173
- **管理后台**: http://localhost:5174
- **后端API**: http://localhost:19089/api
- **WebSocket**: ws://localhost:19089/ws
## 🧪 测试策略 ## 🧪 测试策略
+117
View File
@@ -0,0 +1,117 @@
# Emotion Museum 前端应用 Nginx 配置
# 配置路径: /www/server/panel/vhost/nginx/emotion-museum.conf
server {
listen 80;
server_name 101.200.208.45 localhost 127.0.0.1;
# 前端应用路径
location /emotion-museum/ {
alias /data/www/emotion-museum/;
# 启用目录索引(可选)
autoindex off;
# 处理 Vue Router 的 history 模式
# 所有非文件请求都重定向到 index.html
try_files $uri $uri/ /emotion-museum/index.html;
# 设置缓存策略
# HTML 文件不缓存
location ~ \.html?$ {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# 静态资源缓存 1 年
location ~ \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
expires 1y;
}
}
# 处理不带末尾斜杠的 /emotion-museum 请求
location = /emotion-museum {
rewrite ^(.*)$ $1/ permanent;
}
# 管理后台应用路径
location /emotion-museum-admin/ {
alias /data/www/emotion-museum-admin/;
# 启用目录索引(可选)
autoindex off;
# 处理 Vue Router 的 history 模式
# 所有非文件请求都重定向到 index.html
try_files $uri $uri/ /emotion-museum-admin/index.html;
# 设置缓存策略
# HTML 文件不缓存
location ~ \.html?$ {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# 静态资源缓存 1 年
location ~ \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
expires 1y;
}
}
# 处理不带末尾斜杠的 /emotion-museum-admin 请求
location = /emotion-museum-admin {
rewrite ^(.*)$ $1/ permanent;
}
# 后端 API 代理
location /api {
proxy_pass http://127.0.0.1:19089;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# WebSocket 代理
location /ws {
proxy_pass http://127.0.0.1:19089;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket 超时设置
proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}
# 健康检查端点
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
# 禁止访问敏感文件
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
access_log /www/wwwlogs/access.log;
}
+76 -14
View File
@@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
# 情绪博物馆 - 一键式部署脚本 # 情绪博物馆 - 一键式部署脚本
# 同时部署后端前端到远程服务器 101.200.208.45 # 同时部署后端前端和管理后台到远程服务器 101.200.208.45
# 使用方法: bash deploy-all.sh [backend|frontend|all] # 使用方法: bash deploy-all.sh [backend|frontend|admin|all]
# 默认部署所有服务 # 默认部署所有服务
set -e set -e
@@ -43,9 +43,9 @@ cd "$SCRIPT_DIR"
DEPLOY_TYPE="${1:-all}" DEPLOY_TYPE="${1:-all}"
# 验证部署类型 # 验证部署类型
if [[ ! "$DEPLOY_TYPE" =~ ^(backend|frontend|all)$ ]]; then if [[ ! "$DEPLOY_TYPE" =~ ^(backend|frontend|admin|all)$ ]]; then
log_error "无效的部署类型: $DEPLOY_TYPE" log_error "无效的部署类型: $DEPLOY_TYPE"
echo "使用方法: bash deploy-all.sh [backend|frontend|all]" echo "使用方法: bash deploy-all.sh [backend|frontend|admin|all]"
exit 1 exit 1
fi fi
@@ -102,6 +102,31 @@ deploy_frontend() {
fi fi
} }
# ============================================================================
# 部署管理后台
# ============================================================================
deploy_admin() {
log_section "开始部署管理后台"
if [ ! -f "web-admin/deploy.sh" ]; then
log_error "管理后台部署脚本不存在: web-admin/deploy.sh"
return 1
fi
log_info "执行管理后台部署脚本..."
cd web-admin
if bash deploy.sh; then
log_info "✅ 管理后台部署成功"
cd ..
return 0
else
log_error "❌ 管理后台部署失败"
cd ..
return 1
fi
}
# ============================================================================ # ============================================================================
# 主程序 # 主程序
# ============================================================================ # ============================================================================
@@ -112,6 +137,7 @@ log_info "部署时间: $(date '+%Y-%m-%d %H:%M:%S')"
BACKEND_SUCCESS=true BACKEND_SUCCESS=true
FRONTEND_SUCCESS=true FRONTEND_SUCCESS=true
ADMIN_SUCCESS=true
# 执行部署 # 执行部署
case "$DEPLOY_TYPE" in case "$DEPLOY_TYPE" in
@@ -125,6 +151,11 @@ case "$DEPLOY_TYPE" in
FRONTEND_SUCCESS=false FRONTEND_SUCCESS=false
fi fi
;; ;;
admin)
if ! deploy_admin; then
ADMIN_SUCCESS=false
fi
;;
all) all)
if ! deploy_backend; then if ! deploy_backend; then
BACKEND_SUCCESS=false BACKEND_SUCCESS=false
@@ -133,6 +164,10 @@ case "$DEPLOY_TYPE" in
if ! deploy_frontend; then if ! deploy_frontend; then
FRONTEND_SUCCESS=false FRONTEND_SUCCESS=false
fi fi
if ! deploy_admin; then
ADMIN_SUCCESS=false
fi
;; ;;
esac esac
@@ -161,26 +196,53 @@ if [ "$DEPLOY_TYPE" = "frontend" ] || [ "$DEPLOY_TYPE" = "all" ]; then
fi fi
fi fi
if [ "$DEPLOY_TYPE" = "admin" ] || [ "$DEPLOY_TYPE" = "all" ]; then
if [ "$ADMIN_SUCCESS" = true ]; then
log_info "✅ 管理后台部署: 成功"
else
log_error "❌ 管理后台部署: 失败"
fi
fi
log_info "部署耗时: ${DURATION}" log_info "部署耗时: ${DURATION}"
# ============================================================================ # ============================================================================
# 访问信息 # 访问信息
# ============================================================================ # ============================================================================
if [ "$BACKEND_SUCCESS" = true ] && [ "$FRONTEND_SUCCESS" = true ]; then # 检查部署结果
ALL_SUCCESS=true
if [ "$DEPLOY_TYPE" = "all" ]; then
if [ "$BACKEND_SUCCESS" = false ] || [ "$FRONTEND_SUCCESS" = false ] || [ "$ADMIN_SUCCESS" = false ]; then
ALL_SUCCESS=false
fi
elif [ "$DEPLOY_TYPE" = "backend" ] && [ "$BACKEND_SUCCESS" = false ]; then
ALL_SUCCESS=false
elif [ "$DEPLOY_TYPE" = "frontend" ] && [ "$FRONTEND_SUCCESS" = false ]; then
ALL_SUCCESS=false
elif [ "$DEPLOY_TYPE" = "admin" ] && [ "$ADMIN_SUCCESS" = false ]; then
ALL_SUCCESS=false
fi
if [ "$ALL_SUCCESS" = true ]; then
echo "" echo ""
log_section "部署成功!" log_section "部署成功!"
log_info "📱 前端访问地址: http://101.200.208.45/emotion-museum/"
log_info "🔌 后端API地址: http://101.200.208.45:19089/api" if [ "$DEPLOY_TYPE" = "backend" ] || [ "$DEPLOY_TYPE" = "all" ]; then
log_info "📊 WebSocket地址: ws://101.200.208.45:19089/ws" log_info "🔌 后端API地址: http://101.200.208.45:19089/api"
log_info "📊 WebSocket地址: ws://101.200.208.45:19089/ws"
fi
if [ "$DEPLOY_TYPE" = "frontend" ] || [ "$DEPLOY_TYPE" = "all" ]; then
log_info "📱 前端访问地址: http://101.200.208.45/emotion-museum/"
fi
if [ "$DEPLOY_TYPE" = "admin" ] || [ "$DEPLOY_TYPE" = "all" ]; then
log_info "🔧 管理后台地址: http://101.200.208.45/emotion-museum-admin/"
fi
echo "" echo ""
exit 0 exit 0
elif [ "$BACKEND_SUCCESS" = true ]; then
log_warn "⚠️ 后端部署成功,前端部署失败"
exit 1
elif [ "$FRONTEND_SUCCESS" = true ]; then
log_warn "⚠️ 前端部署成功,后端部署失败"
exit 1
else else
log_error "❌ 部署失败" log_error "❌ 部署失败"
exit 1 exit 1
+63
View File
@@ -0,0 +1,63 @@
#!/bin/bash
# 部署脚本 - 将构建好的管理后台文件上传到服务器
# 使用方法: ./deploy.sh
SERVER_IP="101.200.208.45"
USERNAME="root"
REMOTE_PATH="/data/www/emotion-museum-admin"
echo "开始部署管理后台应用到服务器..."
# 检查是否安装了npm
if ! command -v npm &> /dev/null; then
echo "❌ 错误: 未找到npm命令,请先安装Node.js"
exit 1
fi
# 执行构建(无论dist目录是否存在,都必须构建)
echo "📦 开始构建管理后台项目..."
if npm run build; then
echo "✅ 管理后台项目构建成功"
else
echo "❌ 管理后台项目构建失败,请检查代码"
exit 1
fi
# 验证dist目录是否存在
if [ ! -d "dist" ]; then
echo "❌ 错误: 构建后dist目录仍不存在,请检查构建配置"
exit 1
fi
# 检查是否安装了scp命令
if ! command -v scp &> /dev/null; then
echo "❌ 错误: 未找到scp命令,请安装OpenSSH客户端"
exit 1
fi
echo "正在上传文件到服务器 $SERVER_IP..."
# 创建远程目录(如果不存在)
echo "📁 创建远程目录..."
ssh "${USERNAME}@${SERVER_IP}" "mkdir -p ${REMOTE_PATH}"
# 上传所有文件到服务器
echo "📤 上传文件到服务器..."
if scp dist/index.html "${USERNAME}@${SERVER_IP}:${REMOTE_PATH}/" && \
scp -r dist/assets "${USERNAME}@${SERVER_IP}:${REMOTE_PATH}/"; then
# 设置文件权限
echo "🔐 设置文件权限..."
ssh "${USERNAME}@${SERVER_IP}" "chmod -R 755 ${REMOTE_PATH}"
echo "✅ 管理后台部署完成!"
echo "📱 访问地址: http://$SERVER_IP/emotion-museum-admin/"
echo "🔧 管理后台功能: AI配置管理、用户管理、数据统计等"
else
echo "❌ 部署失败,请检查:"
echo "1. 服务器IP地址是否正确"
echo "2. SSH密钥是否配置正确"
echo "3. 服务器目录权限是否正确"
exit 1
fi
+2 -2
View File
@@ -77,13 +77,13 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, onMounted } from 'vue' import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute } from 'vue-router'
import { useAdminStore } from '@/stores/admin' import { useAdminStore } from '@/stores/admin'
import { Fold, Expand } from '@element-plus/icons-vue' import { Fold, Expand } from '@element-plus/icons-vue'
import { menuConfig } from '@/config/menu' import { menuConfig } from '@/config/menu'
const route = useRoute() const route = useRoute()
const router = useRouter() // const router = useRouter()
const adminStore = useAdminStore() const adminStore = useAdminStore()
const isCollapse = ref(false) const isCollapse = ref(false)
+2 -2
View File
@@ -72,12 +72,12 @@ const routes: RouteRecordRaw[] = [
] ]
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: createWebHistory('/emotion-museum-admin/'),
routes routes
}) })
// 路由守卫 // 路由守卫
router.beforeEach((to, from, next) => { router.beforeEach((to, _from, next) => {
const token = localStorage.getItem('adminToken') const token = localStorage.getItem('adminToken')
if (to.path === '/login') { if (to.path === '/login') {
+6 -5
View File
@@ -13,12 +13,13 @@ export const useAdminStore = defineStore('admin', () => {
const login = async (loginForm: AdminLoginRequest) => { const login = async (loginForm: AdminLoginRequest) => {
try { try {
const res = await loginApi(loginForm) const res = await loginApi(loginForm)
token.value = res.data.accessToken const authData = res.data as any
adminInfo.value = res.data.adminInfo token.value = authData.accessToken
adminInfo.value = authData.adminInfo
localStorage.setItem('adminToken', res.data.accessToken) localStorage.setItem('adminToken', authData.accessToken)
localStorage.setItem('adminRefreshToken', res.data.refreshToken) localStorage.setItem('adminRefreshToken', authData.refreshToken)
localStorage.setItem('adminInfo', JSON.stringify(res.data.adminInfo)) localStorage.setItem('adminInfo', JSON.stringify(authData.adminInfo))
ElMessage.success('登录成功') ElMessage.success('登录成功')
router.push('/') router.push('/')
+1 -1
View File
@@ -1,4 +1,4 @@
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios' import axios, { AxiosInstance, AxiosResponse } from 'axios'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import router from '@/router' import router from '@/router'
+4 -4
View File
@@ -1,6 +1,6 @@
// 表单验证规则 // 表单验证规则
export const validateAccount = (rule: any, value: string, callback: any) => { export const validateAccount = (_rule: any, value: string, callback: any) => {
if (!value) { if (!value) {
callback(new Error('请输入账号')) callback(new Error('请输入账号'))
} else if (value.length < 3 || value.length > 50) { } else if (value.length < 3 || value.length > 50) {
@@ -10,7 +10,7 @@ export const validateAccount = (rule: any, value: string, callback: any) => {
} }
} }
export const validatePassword = (rule: any, value: string, callback: any) => { export const validatePassword = (_rule: any, value: string, callback: any) => {
if (!value) { if (!value) {
callback(new Error('请输入密码')) callback(new Error('请输入密码'))
} else if (value.length < 6 || value.length > 20) { } else if (value.length < 6 || value.length > 20) {
@@ -20,7 +20,7 @@ export const validatePassword = (rule: any, value: string, callback: any) => {
} }
} }
export const validateEmail = (rule: any, value: string, callback: any) => { export const validateEmail = (_rule: any, value: string, callback: any) => {
if (!value) { if (!value) {
callback() callback()
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) { } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
@@ -30,7 +30,7 @@ export const validateEmail = (rule: any, value: string, callback: any) => {
} }
} }
export const validatePhone = (rule: any, value: string, callback: any) => { export const validatePhone = (_rule: any, value: string, callback: any) => {
if (!value) { if (!value) {
callback() callback()
} else if (!/^1[3-9]\d{9}$/.test(value)) { } else if (!/^1[3-9]\d{9}$/.test(value)) {
-4
View File
@@ -45,10 +45,6 @@
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div class="login-footer">
<p>默认账号: admin / admin123</p>
</div>
</div> </div>
</div> </div>
</template> </template>
+3 -2
View File
@@ -190,8 +190,9 @@ const fetchData = async () => {
size: pagination.size size: pagination.size
} }
const res = await getAdminPage(params) const res = await getAdminPage(params)
tableData.value = res.data.records const pageData = res.data as any
pagination.total = res.data.total tableData.value = pageData.records
pagination.total = pageData.total
} catch (error) { } catch (error) {
console.error('获取管理员列表失败:', error) console.error('获取管理员列表失败:', error)
} finally { } finally {
@@ -1181,7 +1181,7 @@ const handleTestRequest = async () => {
} }
// 检查是否为流式请求 // 检查是否为流式请求
const isStreamRequest = body.stream === true const isStreamRequest = (body as any).stream === true
if (isStreamRequest) { if (isStreamRequest) {
// 处理流式请求 // 处理流式请求
+3 -2
View File
@@ -131,8 +131,9 @@ const fetchData = async () => {
size: pagination.size size: pagination.size
} }
const res = await getUserPage(params) const res = await getUserPage(params)
tableData.value = res.data.records const pageData = res.data as any
pagination.total = res.data.total tableData.value = pageData.records
pagination.total = pageData.total
} catch (error) { } catch (error) {
console.error('获取用户列表失败:', error) console.error('获取用户列表失败:', error)
} finally { } finally {
+2 -1
View File
@@ -24,5 +24,6 @@ export default defineConfig({
assetsDir: 'assets', assetsDir: 'assets',
sourcemap: false, sourcemap: false,
chunkSizeWarningLimit: 1500 chunkSizeWarningLimit: 1500
} },
base: '/emotion-museum-admin/'
}) })
+276
View File
@@ -0,0 +1,276 @@
# 情绪博物馆管理后台部署说明
## 📋 概述
本文档说明如何部署情绪博物馆管理后台到服务器 `101.200.208.45`
管理后台将部署到 `/data/www/emotion-museum-admin/` 目录,通过 `http://101.200.208.45/emotion-museum-admin/` 访问。
## 🚀 快速部署
### 1. 执行部署脚本
```bash
# 进入管理后台目录
cd web-admin
# 执行部署脚本
bash deploy.sh
```
### 2. 访问管理后台
部署完成后,可以通过以下地址访问:
- **管理后台**: http://101.200.208.45/emotion-museum-admin/
- **登录页面**: http://101.200.208.45/emotion-museum-admin/login
## 📊 部署流程详解
### 自动化部署流程
1. **环境检查**: 检查 Node.js 和 npm 是否安装
2. **项目构建**: 执行 `npm run build` 构建项目
3. **文件验证**: 验证 `dist` 目录是否生成
4. **文件上传**: 使用 SCP 上传文件到服务器
5. **权限设置**: 设置文件权限为 755
6. **部署验证**: 确认文件上传成功
### 构建配置
- **构建命令**: `npm run build`
- **输出目录**: `dist/`
- **基础路径**: `/emotion-museum-admin/`
- **路由模式**: HTML5 History 模式
## 🔧 配置说明
### Nginx 配置
管理后台的 Nginx 配置已添加到 `conf/emotion-museum.conf` 文件中:
```nginx
# 管理后台应用路径
location /emotion-museum-admin/ {
alias /data/www/emotion-museum-admin/;
autoindex off;
# 处理 Vue Router 的 history 模式
try_files $uri $uri/ /emotion-museum-admin/index.html;
# HTML 文件不缓存
location ~ \.html?$ {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# 静态资源缓存 1 年
location ~ \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
expires 1y;
}
}
# 处理不带末尾斜杠的请求
location = /emotion-museum-admin {
rewrite ^(.*)$ $1/ permanent;
}
```
### 路由配置
管理后台使用 Vue Router 的 History 模式,配置了基础路径:
```typescript
const router = createRouter({
history: createWebHistory('/emotion-museum-admin/'),
routes
})
```
### Vite 配置
构建配置中设置了正确的基础路径:
```typescript
export default defineConfig({
// ...其他配置
base: '/emotion-museum-admin/',
build: {
outDir: 'dist',
assetsDir: 'assets',
sourcemap: false,
chunkSizeWarningLimit: 1500
}
})
```
## ✅ 验证部署
### 1. 检查文件是否上传成功
```bash
# SSH 连接到服务器
ssh root@101.200.208.45
# 检查文件是否存在
ls -lh /data/www/emotion-museum-admin/
```
### 2. 检查 Nginx 配置
```bash
# 测试 Nginx 配置
nginx -t
# 重新加载 Nginx
nginx -s reload
```
### 3. 访问测试
在浏览器中访问以下地址:
- http://101.200.208.45/emotion-museum-admin/
- http://101.200.208.45/emotion-museum-admin/login
## 🔄 更新部署
### 代码更新后重新部署
```bash
# 1. 进入管理后台目录
cd web-admin
# 2. 拉取最新代码(如果使用 Git)
git pull
# 3. 安装依赖(如果有新依赖)
npm install
# 4. 执行部署
bash deploy.sh
```
### 仅更新前端资源
如果只是修改了前端代码,无需重启后端服务:
```bash
# 执行部署脚本即可
bash deploy.sh
```
## 🛠️ 故障排查
### 问题 1: 构建失败
**现象**: 执行 `npm run build` 失败
**解决方案**:
```bash
# 1. 清理依赖
rm -rf node_modules package-lock.json
# 2. 重新安装依赖
npm install
# 3. 重新构建
npm run build
```
### 问题 2: 上传失败
**现象**: SCP 上传文件失败
**解决方案**:
```bash
# 1. 检查 SSH 连接
ssh root@101.200.208.45 "echo 'SSH 连接成功'"
# 2. 检查目标目录权限
ssh root@101.200.208.45 "ls -ld /data/www/"
# 3. 手动创建目录
ssh root@101.200.208.45 "mkdir -p /data/www/emotion-museum-admin"
```
### 问题 3: 访问 404
**现象**: 访问管理后台返回 404
**解决方案**:
```bash
# 1. 检查文件是否存在
ssh root@101.200.208.45 "ls -lh /data/www/emotion-museum-admin/"
# 2. 检查 Nginx 配置
ssh root@101.200.208.45 "nginx -t"
# 3. 重新加载 Nginx
ssh root@101.200.208.45 "nginx -s reload"
```
### 问题 4: 路由不工作
**现象**: 直接访问子路由返回 404
**解决方案**:
1. 确认 Nginx 配置中的 `try_files` 指令正确
2. 确认路由配置中的 `base` 路径正确
3. 清除浏览器缓存
## 📱 功能说明
管理后台包含以下功能模块:
### 1. 仪表盘
- 系统概览
- 数据统计
- 快速操作
### 2. 管理员管理
- 管理员列表
- 添加/编辑管理员
- 权限管理
### 3. 用户管理
- 用户列表
- 用户详情
- 用户统计
### 4. AI配置管理
- AI配置列表
- 配置创建/编辑
- 接口测试
- 流式响应测试
## 🔐 安全说明
### 访问控制
- 管理后台需要登录才能访问
- 使用 JWT Token 进行身份验证
- 自动跳转到登录页面
### 文件权限
- 部署文件权限设置为 755
- 静态资源可公开访问
- 敏感配置文件受保护
## 📞 支持
如有问题,请检查:
1. **部署脚本**: `web-admin/deploy.sh`
2. **Nginx 配置**: `conf/emotion-museum.conf`
3. **路由配置**: `web-admin/src/router/index.ts`
4. **构建配置**: `web-admin/vite.config.ts`
---
**最后更新**: 2025-10-30
**版本**: 1.0
**状态**: ✅ 已完成
+44 -6
View File
@@ -17,13 +17,14 @@
### 基本用法 ### 基本用法
```bash ```bash
# 部署所有服务(后端 + 前端) # 部署所有服务(后端 + 前端 + 管理后台
bash deploy-all.sh bash deploy-all.sh
# 或指定部署类型 # 或指定部署类型
bash deploy-all.sh all # 部署所有服务 bash deploy-all.sh all # 部署所有服务
bash deploy-all.sh backend # 仅部署后端 bash deploy-all.sh backend # 仅部署后端
bash deploy-all.sh frontend # 仅部署前端 bash deploy-all.sh frontend # 仅部署前端
bash deploy-all.sh admin # 仅部署管理后台
``` ```
### 完整部署流程 ### 完整部署流程
@@ -39,6 +40,7 @@ bash deploy-all.sh
# 4. 访问应用 # 4. 访问应用
# 前端: http://101.200.208.45/emotion-museum/ # 前端: http://101.200.208.45/emotion-museum/
# 管理后台: http://101.200.208.45/emotion-museum-admin/
# 后端: http://101.200.208.45:19089/api # 后端: http://101.200.208.45:19089/api
``` ```
@@ -64,6 +66,12 @@ bash deploy-all.sh frontend
``` ```
仅更新前端应用,适用于前端代码更新。 仅更新前端应用,适用于前端代码更新。
### 仅部署管理后台
```bash
bash deploy-all.sh admin
```
仅更新管理后台,适用于管理后台代码更新。
## 📊 部署流程详解 ## 📊 部署流程详解
### 后端部署流程 ### 后端部署流程
@@ -78,11 +86,21 @@ bash deploy-all.sh frontend
### 前端部署流程 ### 前端部署流程
1. 检查 `web/deploy.sh` 是否存在 1. 检查 `web/deploy.sh` 是否存在
2. 执行前端部署脚本 2. 执行前端部署脚本
- 检查 `dist` 目录是否存在 - 构建前端项目 (`npm run build`)
- 上传 `index.html` 到服务器 - 上传 `index.html` 到服务器
- 上传 `assets` 目录到服务器 - 上传 `assets` 目录到服务器
- 验证文件是否上传成功 - 验证文件是否上传成功
### 管理后台部署流程
1. 检查 `web-admin/deploy.sh` 是否存在
2. 执行管理后台部署脚本
- 构建管理后台项目 (`npm run build`)
- 创建远程目录
- 上传 `index.html` 到服务器
- 上传 `assets` 目录到服务器
- 设置文件权限
- 验证文件是否上传成功
## ✅ 验证部署 ## ✅ 验证部署
### 部署完成后的验证 ### 部署完成后的验证
@@ -94,8 +112,12 @@ curl http://101.200.208.45:19089/api/health
# 2. 检查前端是否可访问 # 2. 检查前端是否可访问
curl http://101.200.208.45/emotion-museum/ curl http://101.200.208.45/emotion-museum/
# 3. 在浏览器中访问 # 3. 检查管理后台是否可访问
curl http://101.200.208.45/emotion-museum-admin/
# 4. 在浏览器中访问
# 前端: http://101.200.208.45/emotion-museum/ # 前端: http://101.200.208.45/emotion-museum/
# 管理后台: http://101.200.208.45/emotion-museum-admin/
# 登录页面应该正常显示 # 登录页面应该正常显示
``` ```
@@ -110,6 +132,9 @@ tail -f /data/logs/emotion-museum/emotion-single.log
# 查看前端文件是否存在 # 查看前端文件是否存在
ls -lh /data/www/emotion-museum/ ls -lh /data/www/emotion-museum/
# 查看管理后台文件是否存在
ls -lh /data/www/emotion-museum-admin/
``` ```
## 🔧 故障排查 ## 🔧 故障排查
@@ -174,7 +199,7 @@ bash deploy-all.sh frontend
**解决方案**: **解决方案**:
```bash ```bash
# 1. 检查 Nginx 配置 # 1. 检查 Nginx 配置 (www/server/panel/vhost/nginx/emotion-museum.conf )
ssh root@101.200.208.45 "nginx -t" ssh root@101.200.208.45 "nginx -t"
# 2. 重新加载 Nginx # 2. 重新加载 Nginx
@@ -248,10 +273,21 @@ bash deploy-all.sh frontend
# http://101.200.208.45/emotion-museum/ # http://101.200.208.45/emotion-museum/
``` ```
### 场景 3: 同时更新前后端 ### 场景 3: 仅更新管理后台代码
```bash ```bash
# 1. 修改前后端代码 # 1. 修改管理后台代码
# 2. 执行部署
bash deploy-all.sh admin
# 3. 在浏览器中刷新页面
# http://101.200.208.45/emotion-museum-admin/
```
### 场景 4: 同时更新所有服务
```bash
# 1. 修改前后端和管理后台代码
# 2. 执行部署 # 2. 执行部署
bash deploy-all.sh all bash deploy-all.sh all
@@ -264,8 +300,10 @@ bash deploy-all.sh all
如有问题,请参考以下文件: 如有问题,请参考以下文件:
- `backend-single/部署说明.md` - 后端部署详情 - `backend-single/部署说明.md` - 后端部署详情
- `web/部署说明.md` - 前端部署详情 - `web/部署说明.md` - 前端部署详情
- `web-admin/部署说明.md` - 管理后台部署详情
- `backend-single/deploy.sh` - 后端部署脚本 - `backend-single/deploy.sh` - 后端部署脚本
- `web/deploy.sh` - 前端部署脚本 - `web/deploy.sh` - 前端部署脚本
- `web-admin/deploy.sh` - 管理后台部署脚本
--- ---