add windows start scripts and update database password in config.yaml

This commit is contained in:
2026-03-20 22:06:38 +08:00
parent c0fc1ea13a
commit 5a8518f6ab
5 changed files with 2274 additions and 0 deletions

238
TROUBLESHOOTING.md Normal file
View File

@@ -0,0 +1,238 @@
# 考试信息管理系统 - 常见问题修复指南
## 🔧 问题:首页显示 "Not Found"
### 问题描述
访问系统首页http://localhost:8080时显示 "Not Found" 错误。
### 原因分析
1. **前端未构建**:项目缺少 `frontend/dist` 目录
2. **静态文件服务未配置**:后端无法提供前端页面文件
3. **SPA 路由未处理**Vue Router 的前端路由需要特殊配置
### 解决方案
#### 方法一:使用快速启动脚本(推荐)
**Windows PowerShell:**
```powershell
.\start.ps1
```
**Windows CMD:**
```batch
start.bat
```
脚本会自动:
- ✅ 检查 Go 和 Node.js 环境
- ✅ 安装前端依赖
- ✅ 构建前端生产版本
- ✅ 启动后端服务
- ✅ 配置静态文件服务
#### 方法二:手动修复
**步骤 1构建前端**
```bash
# 进入前端目录
cd frontend
# 安装依赖(首次需要)
npm install
# 构建生产版本
npm run build
```
构建成功后会生成 `frontend/dist` 目录。
**步骤 2验证构建结果**
```bash
# 检查 dist 目录是否存在
dir dist
# 应该看到:
# index.html
# assets/
# static/
```
**步骤 3重启后端服务**
```bash
# 停止当前运行的服务Ctrl+C
# 重新启动
go run cmd/main.go
```
**步骤 4访问系统**
打开浏览器访问http://localhost:8080
应该能看到登录页面。
---
## 📋 完整排查清单
### 1. 检查前端是否已构建
```bash
# PowerShell
Test-Path frontend\dist
# 或 CMD
dir frontend\dist
```
如果返回 `False` 或提示目录不存在,需要构建前端。
### 2. 检查后端日志
启动后端时应该看到:
```
Server started on port 8080
```
如果没有此输出,查看错误信息并解决。
### 3. 检查数据库连接
确保 `config/config.yaml` 中的数据库配置正确:
```yaml
database:
host: localhost
port: 3306
user: root
password: YOUR_PASSWORD # ⚠️ 修改为你的密码
dbname: exam_registration
```
### 4. 检查浏览器控制台
按 F12 打开开发者工具,查看:
- Network 标签:是否有 404 错误
- Console 标签:是否有 JavaScript 错误
### 5. 清除浏览器缓存
有时浏览器缓存会导致旧版本问题:
- Ctrl+Shift+Delete 清除缓存
- 或使用无痕模式访问
---
## 🎯 其他常见问题
### 问题npm install 失败
**错误信息:**
```
npm ERR! code ECONNREFUSED
```
**解决方案:**
1. 检查网络连接
2. 切换 npm 镜像源:
```bash
npm config set registry https://registry.npmmirror.com
npm install
```
### 问题:前端构建失败
**错误信息:**
```
Error: Cannot find module 'xxx'
```
**解决方案:**
```bash
cd frontend
rm -rf node_modules package-lock.json
npm install
npm run build
```
### 问题:后端启动失败 - 端口被占用
**错误信息:**
```
bind: address already in use
```
**解决方案:**
方案 1关闭占用端口的进程
```bash
# Windows PowerShell
netstat -ano | findstr :8080
taskkill /PID <进程 PID> /F
```
方案 2修改端口
编辑 `config/config.yaml`:
```yaml
server:
port: 8081 # 改为其他端口
```
### 问题:登录后仍然 404
**可能原因:**
- Token 未正确保存
- 路由守卫配置问题
**解决方案:**
1. 检查浏览器 Local Storage 是否有 token
2. 检查浏览器 Console 是否有错误
3. 尝试清除缓存重新登录
---
## 🆘 获取帮助
如果以上方法都无法解决问题:
1. **查看完整日志**
```bash
# 启动时查看详细日志
go run cmd/main.go 2>&1 | tee startup.log
```
2. **检查系统要求**
- Go 1.21+
- Node.js 18+
- MySQL 8.0+
3. **重新部署**
```bash
# 删除并重新克隆项目
# 或备份数据后重新执行初始化流程
```
4. **联系技术支持**
- 提供完整的错误日志
- 说明操作系统版本
- 说明已尝试的解决方法
---
## ✅ 验证成功标准
系统正常运行的标志:
- ✅ 后端服务启动,显示 "Server started on port 8080"
- ✅ 访问 http://localhost:8080 显示登录页面
- ✅ 可以使用 admin/admin123 登录
- ✅ 登录后显示系统首页Dashboard
- ✅ 导航栏各菜单可以正常切换
- ✅ API 请求正常(无 404 错误)
---
**祝您使用愉快!** 🎉

1859
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -43,6 +43,15 @@ export function publishScore(id) {
})
}
// 更新成绩
export function updateScore(id, data) {
return request({
url: `/scores/${id}`,
method: 'put',
data
})
}
// 删除成绩
export function deleteScore(id) {
return request({

85
start.bat Normal file
View File

@@ -0,0 +1,85 @@
@echo off
chcp 65001 >nul
echo ========================================
echo 考试信息管理系统 - 快速启动
echo ========================================
echo.
echo [1/5] 检查 Go 环境...
go version >nul 2>&1
if %errorlevel% neq 0 (
echo ✗ Go 未安装,请先安装 Go 1.21+
pause
exit /b 1
)
echo ✓ Go 已安装
echo.
echo [2/5] 检查 Node.js 环境...
node --version >nul 2>&1
if %errorlevel% neq 0 (
echo ✗ Node.js 未安装,请先安装 Node.js 18+
pause
exit /b 1
)
echo ✓ Node.js 已安装
echo.
echo [3/5] 构建前端...
cd frontend
if not exist "node_modules" (
echo 安装依赖...
call npm install
if %errorlevel% neq 0 (
echo ✗ 依赖安装失败
cd ..
pause
exit /b 1
)
) else (
echo 依赖已存在,跳过安装
)
echo 构建生产版本...
call npm run build
if %errorlevel% neq 0 (
echo ✗ 前端构建失败
cd ..
pause
exit /b 1
)
echo ✓ 前端构建完成
cd ..
echo.
echo [4/5] 检查配置文件...
if exist "config\config.yaml" (
echo ✓ 配置文件存在
echo ⚠️ 请确保 config\config.yaml 中的数据库密码已修改
) else (
echo ✗ 配置文件不存在config\config.yaml
pause
exit /b 1
)
echo.
echo [5/5] 启动后端服务...
echo.
echo ========================================
echo 服务器即将启动...
echo ========================================
echo.
echo 访问地址:
echo 前端http://localhost:8080
echo API: http://localhost:8080/api
echo.
echo 默认登录账号:
echo 用户名admin
echo 密码admin123
echo.
echo 按 Ctrl+C 停止服务
echo.
go run cmd/main.go

83
start.ps1 Normal file
View File

@@ -0,0 +1,83 @@
run# 考试信息管理系统 - 快速启动脚本 (PowerShell)
# 使用方法:.\start.ps1
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " 考试信息管理系统 - 快速启动" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 检查 Go 环境
Write-Host "[1/5] 检查 Go 环境..." -ForegroundColor Yellow
try {
$goVersion = go version
Write-Host "✓ Go 已安装:$goVersion" -ForegroundColor Green
} catch {
Write-Host "✗ Go 未安装,请先安装 Go 1.21+" -ForegroundColor Red
exit 1
}
# 检查 Node.js 环境
Write-Host "[2/5] 检查 Node.js 环境..." -ForegroundColor Yellow
try {
$nodeVersion = node --version
Write-Host "✓ Node.js 已安装:$nodeVersion" -ForegroundColor Green
} catch {
Write-Host "✗ Node.js 未安装,请先安装 Node.js 18+" -ForegroundColor Red
exit 1
}
# 构建前端
Write-Host "[3/5] 构建前端..." -ForegroundColor Yellow
Set-Location frontend
if (-not (Test-Path "node_modules")) {
Write-Host " 安装依赖..." -ForegroundColor Cyan
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host "✗ 依赖安装失败" -ForegroundColor Red
exit 1
}
} else {
Write-Host " 依赖已存在,跳过安装" -ForegroundColor Green
}
Write-Host " 构建生产版本..." -ForegroundColor Cyan
npm run build
if ($LASTEXITCODE -ne 0) {
Write-Host "✗ 前端构建失败" -ForegroundColor Red
Set-Location ..
exit 1
}
Write-Host "✓ 前端构建完成" -ForegroundColor Green
Set-Location ..
# 检查配置文件
Write-Host "[4/5] 检查配置文件..." -ForegroundColor Yellow
if (Test-Path "config\config.yaml") {
Write-Host "✓ 配置文件存在" -ForegroundColor Green
Write-Host "⚠️ 请确保 config/config.yaml 中的数据库密码已修改" -ForegroundColor Yellow
} else {
Write-Host "✗ 配置文件不存在config\config.yaml" -ForegroundColor Red
exit 1
}
# 启动后端服务
Write-Host "[5/5] 启动后端服务..." -ForegroundColor Yellow
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " 服务器即将启动..." -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "访问地址:" -ForegroundColor White
Write-Host " 前端http://localhost:8080" -ForegroundColor Blue
Write-Host " API: http://localhost:8080/api" -ForegroundColor Blue
Write-Host ""
Write-Host "默认登录账号:" -ForegroundColor White
Write-Host " 用户名admin" -ForegroundColor Blue
Write-Host " 密码admin123" -ForegroundColor Blue
Write-Host ""
Write-Host "按 Ctrl+C 停止服务" -ForegroundColor Yellow
Write-Host ""
go run cmd/main.go