Browse Source

整理环境

master
hejl 1 week ago
parent
commit
cca538032b
  1. 212
      gofaster/FULL_STACK_ENHANCED.md
  2. 118
      gofaster/HOT_RELOAD.md
  3. 139
      gofaster/NPM_FIX_SUMMARY.md
  4. 138
      gofaster/QUICK_START.md
  5. 2
      gofaster/app/dist/renderer/js/index.js
  6. BIN
      gofaster/backend/tmp/main.exe
  7. 149
      gofaster/check-environment.ps1
  8. 76
      gofaster/start-dev.bat
  9. 105
      gofaster/start-dev.ps1
  10. 49
      gofaster/start-enhanced.bat
  11. 192
      gofaster/start-enhanced.ps1
  12. 47
      gofaster/start-simple.bat
  13. 15
      gofaster/test-api-fixed.bat
  14. 143
      gofaster/test-api-fixed.ps1
  15. 15
      gofaster/test-api.bat
  16. 115
      gofaster/test-api.ps1
  17. 126
      gofaster/test-captcha-display.html
  18. 15
      gofaster/test-jwt-fix.bat
  19. 154
      gofaster/test-jwt-fix.ps1
  20. 122
      gofaster/test-login-complete.md
  21. 94
      gofaster/test-login-fix-verification.md
  22. 96
      gofaster/test-login-fixes.md

212
gofaster/FULL_STACK_ENHANCED.md

@ -1,212 +0,0 @@ @@ -1,212 +0,0 @@
# 🚀 GoFaster 增强版全栈开发环境
## 📋 功能特性
本增强版全栈开发环境集成了所有优化功能:
### **1. 编码优化**
- ✅ UTF-8 编码支持
- ✅ 中文显示无乱码
- ✅ PowerShell 编码配置
### **2. 日志增强**
- ✅ 详细构建日志
- ✅ 进度条显示
- ✅ 错误详情展示
- ✅ 实时状态监控
### **3. 智能依赖管理**
- ✅ 自动检查前端依赖
- ✅ 自动安装 cross-env
- ✅ 自动检查后端依赖
- ✅ 自动安装 air 工具
### **4. 灵活启动模式**
- ✅ 全栈启动(前后端)
- ✅ 仅启动后端
- ✅ 仅启动前端
- ✅ 调试模式
- ✅ 监听模式
## 🛠 使用方法
### **方法 1: 从根目录启动(推荐)**
```powershell
# 全栈启动(标准模式)
.\dev-full.ps1
# 全栈启动(调试模式)
.\dev-full.ps1 -Debug
# 全栈启动(监听模式)
.\dev-full.ps1 -Watch
# 仅启动后端
.\dev-full.ps1 -BackendOnly
# 仅启动前端
.\dev-full.ps1 -FrontendOnly
```
### **方法 2: 从前端目录启动**
```bash
cd app
# 全栈启动(标准模式)
npm run dev:full
# 全栈启动(调试模式)
npm run dev:full-debug
# 全栈启动(监听模式)
npm run dev:full-watch
# 仅启动后端
npm run dev:backend-only
# 仅启动前端
npm run dev:frontend-only
```
### **方法 3: 单独启动服务**
```bash
# 前端增强版
npm run dev:enhanced
# 前端调试版
npm run dev:debug
# 后端热重载
cd backend
air
```
## 🔧 新增功能详解
### **1. 智能依赖检查**
- 自动检查 `node_modules` 是否存在
- 自动安装缺失的依赖
- 自动安装 `cross-env` 工具
- 自动检查并安装 `air` 工具
### **2. 进程管理**
- 显示每个服务的进程 ID (PID)
- 提供进程管理命令
- 智能启动顺序(先后端,后前端)
- 启动状态检查
### **3. 环境配置**
- 自动设置 UTF-8 编码
- 配置 Vue CLI 环境变量
- 设置 Node.js 内存选项
- 配置日志级别
### **4. 错误处理**
- 友好的错误提示
- 详细的故障排除建议
- 状态码检查
- 启动失败处理
## 📁 文件结构
```
gofaster/
├── dev-full.ps1 # 增强版全栈启动脚本
├── app/
│ ├── dev-enhanced.ps1 # 前端增强启动脚本
│ ├── dev-enhanced.bat # 前端批处理脚本
│ ├── .npmrc # npm 配置文件
│ ├── vue.config.js # Vue CLI 增强配置
│ └── package.json # 包含新脚本的包配置
└── backend/
├── .air.toml # Air 热重载配置
└── main.go # 后端主程序
```
## 🚀 启动流程
### **全栈启动流程**
1. **环境检查**:设置编码、环境变量
2. **依赖检查**:检查前端和后端依赖
3. **后端启动**:启动 Go 服务 + Air 热重载
4. **状态检查**:验证后端启动状态
5. **前端启动**:启动 Electron + Vue 热重载
6. **完成提示**:显示服务信息和进程管理命令
### **启动参数说明**
| 参数 | 说明 | 示例 |
|------|------|------|
| `-Debug` | 启用调试模式,显示详细日志 | `.\dev-full.ps1 -Debug` |
| `-Watch` | 启用监听模式,自动重载 | `.\dev-full.ps1 -Watch` |
| `-BackendOnly` | 仅启动后端服务 | `.\dev-full.ps1 -BackendOnly` |
| `-FrontendOnly` | 仅启动前端服务 | `.\dev-full.ps1 -FrontendOnly` |
## 🔍 监控和管理
### **进程信息**
启动完成后会显示:
- 后端进程 ID (PID)
- 前端进程 ID (PID)
- 进程管理命令
### **进程管理命令**
```powershell
# 停止后端
Stop-Process -Id <后端PID>
# 停止前端
Stop-Process -Id <前端PID>
# 停止所有服务
Get-Process | Where-Object {$_.ProcessName -eq 'powershell'} | Stop-Process
```
### **服务状态检查**
- 后端健康检查:`http://localhost:8080/health`
- Swagger 文档:`http://localhost:8080/swagger/index.html`
- 前端应用:Electron 窗口自动打开
## 🚨 故障排除
### **常见问题**
#### **1. 编码问题**
- 确保使用 PowerShell 或 CMD
- 检查系统区域设置
- 使用 `-Debug` 参数查看详细日志
#### **2. 依赖问题**
- 脚本会自动检查和安装依赖
- 如果失败,手动运行 `npm install`
- 检查 Node.js 版本 (推荐 v16+)
#### **3. 端口冲突**
- 检查 8080 端口是否被占用
- 检查 3000 端口是否被占用
- 使用 `netstat -ano | findstr :8080` 查看
#### **4. 启动失败**
- 查看详细错误日志
- 检查 Go 和 Node.js 环境
- 确保在正确的目录下运行
### **调试技巧**
1. **使用调试模式**:`.\dev-full.ps1 -Debug`
2. **查看进程状态**:`Get-Process | Where-Object {$_.ProcessName -eq 'powershell'}`
3. **检查端口占用**:`netstat -ano | findstr :8080`
4. **查看日志文件**:检查各服务的日志输出
## 💡 最佳实践
1. **推荐使用全栈启动**:`.\dev-full.ps1`
2. **开发时使用监听模式**:`.\dev-full.ps1 -Watch`
3. **调试时使用调试模式**:`.\dev-full.ps1 -Debug`
4. **定期清理进程**:避免端口冲突
5. **保持依赖更新**:定期运行 `npm update`
## 🔄 更新日志
- **v2.0.0**: 集成所有增强功能
- **v2.1.0**: 添加智能依赖管理
- **v2.2.0**: 增强进程管理和监控
- **v2.3.0**: 优化启动流程和错误处理

118
gofaster/HOT_RELOAD.md

@ -1,118 +0,0 @@ @@ -1,118 +0,0 @@
# 🔥 GoFaster 热加载开发指南
## 概述
GoFaster 项目支持前后端热加载,修改代码后无需手动重启服务,大大提高开发效率。
## 🚀 快速启动
### 方式1:一键启动(推荐)
```bash
# 在项目根目录执行
./dev-full.ps1
```
这将同时启动前后端热加载服务。
### 方式2:分别启动
```bash
# 启动后端热加载
cd backend
./dev.ps1
# 启动前端热加载(新终端)
cd app
./dev-hot.ps1
```
## 🔧 热加载配置
### 后端 Go 热加载
- **工具**: `air` (Go 热加载工具)
- **配置文件**: `backend/.air.toml`
- **监听文件**: `.go`, `.tpl`, `.tmpl`, `.html`
- **排除目录**: `tmp`, `vendor`, `docs`, `testdata`
### 前端 Electron 热加载
- **工具**: `vue-cli-service` + `electron`
- **配置文件**: `app/vue.config.js`
- **监听文件**: `.vue`, `.js`, `.css`, `.html`
- **自动重载**: 代码修改后自动重新编译并重启 Electron
## 📁 文件结构
```
gofaster/
├── dev-full.ps1 # 一键启动脚本
├── backend/
│ ├── .air.toml # 后端热加载配置
│ ├── dev.bat # Windows 后端启动脚本
│ └── dev.ps1 # PowerShell 后端启动脚本
└── app/
├── dev-hot.bat # Windows 前端启动脚本
└── dev-hot.ps1 # PowerShell 前端启动脚本
```
## 🎯 使用场景
### 后端开发
1. 修改 Go 代码
2. 保存文件
3. `air` 自动检测变化
4. 自动重新编译并重启服务
5. 无需手动重启
### 前端开发
1. 修改 Vue 组件、样式或逻辑
2. 保存文件
3. `vue-cli-service` 自动重新编译
4. Electron 自动重载
5. 界面立即更新
## ⚡ 性能优化
### 后端优化
- 排除测试文件和文档目录
- 设置合理的重载延迟(1秒)
- 只监听必要的文件类型
### 前端优化
- 启用增量编译
- 排除不必要的文件监听
- 使用内存中的热重载
## 🐛 故障排除
### 后端热加载不工作
1. 检查 `air` 是否安装:`go version -m $(which air)`
2. 确认 `.air.toml` 配置正确
3. 检查文件权限和路径
### 前端热加载不工作
1. 确认 `npm run dev` 正常运行
2. 检查 `vue.config.js` 配置
3. 查看控制台错误信息
### 端口冲突
- 后端默认端口:8080
- 前端开发端口:3000
- 如遇冲突,修改相应配置文件
## 💡 开发技巧
1. **保持两个终端窗口**:一个运行后端,一个运行前端
2. **使用 VS Code 集成终端**:方便同时查看前后端日志
3. **合理使用日志**:热重载时日志会保留,便于调试
4. **测试验证码接口**:修改后端代码后,验证码接口会立即生效
## 🔄 热加载流程
```
修改代码 → 保存文件 → 自动检测 → 重新编译 → 重启服务 → 立即生效
```
## 📚 相关文档
- [Air 官方文档](https://github.com/air-verse/air)
- [Vue CLI 热重载](https://cli.vuejs.org/guide/cli-service.html#vue-cli-service-serve)
- [Electron 开发指南](https://www.electronjs.org/docs/tutorial/development)
---
**享受高效的开发体验!** 🎉

139
gofaster/NPM_FIX_SUMMARY.md

@ -1,139 +0,0 @@ @@ -1,139 +0,0 @@
# npm 路径问题修复总结
## 问题描述
您遇到的错误:
```
Uncaught exception: Error: spawn npm ENOENT
```
这个错误表明 Electron 应用在尝试启动构建过程时找不到 `npm` 命令。
## 根本原因
1. **Windows 环境下的 npm 路径问题**:在 Windows 环境下,npm 命令实际上是 `npm.cmd`
2. **构建文件路径错误**:代码中的路径拼接导致重复的 `app` 目录
3. **缺少 shell 参数**:spawn 命令缺少 `shell: true` 参数
## 修复内容
### 1. 修复 npm 命令调用 (`app/src/main/index.js`)
**修复前:**
```javascript
const buildProcess = spawn('npm', ['run', 'build:vue'], {
cwd: appRoot,
stdio: 'pipe'
});
```
**修复后:**
```javascript
// 在 Windows 环境下使用 npm.cmd
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
const buildProcess = spawn(npmCommand, ['run', 'build:vue'], {
cwd: appRoot,
stdio: 'pipe',
shell: true
});
```
### 2. 修复构建文件路径 (`app/src/main/index.js`)
**修复前:**
```javascript
const loadPath = path.join(appRoot, 'app/dist/renderer/index.html')
```
**修复后:**
```javascript
const loadPath = path.join(appRoot, 'dist/renderer/index.html')
```
## 新增文件
### 1. 修复启动脚本 (`app/fix-npm-start.ps1`)
- PowerShell 版本的修复脚本
- 包含环境检查、依赖安装、预构建和启动功能
- 支持调试和监听模式
### 2. 批处理版本 (`app/fix-npm-start.bat`)
- 批处理文件版本的修复脚本
- 功能与 PowerShell 版本相同
### 3. 测试脚本 (`app/test-fix.bat`)
- 简单的测试脚本,用于验证修复是否有效
## 使用方法
### 方法 1:使用修复脚本
```bash
# PowerShell
cd app
powershell -ExecutionPolicy Bypass -File fix-npm-start.ps1
# 批处理
cd app
fix-npm-start.bat
```
### 方法 2:手动修复
1. 确保在 `app` 目录下
2. 运行 `npm install` 安装依赖
3. 运行 `npm run build:vue` 构建前端
4. 运行 `electron .` 启动应用
### 方法 3:测试修复
```bash
cd app
test-fix.bat
```
## 验证修复
运行测试脚本后,应该看到:
- ✅ 构建文件存在: dist\renderer\index.html
- ✅ npm 命令正常
- ✅ 构建命令成功
## 注意事项
1. **确保 Node.js 已正确安装**:访问 https://nodejs.org 下载并安装
2. **确保在正确的目录**:所有命令都应在 `app` 目录下运行
3. **检查环境变量**:确保 npm 在系统 PATH 中
4. **权限问题**:如果遇到权限问题,请以管理员身份运行
## 故障排除
如果仍然遇到问题:
1. **检查 Node.js 安装**
```bash
node --version
npm --version
```
2. **重新安装依赖**
```bash
cd app
rm -rf node_modules
npm install
```
3. **清理构建缓存**
```bash
cd app
rm -rf dist
npm run build:vue
```
4. **检查防火墙和杀毒软件**:某些安全软件可能阻止 npm 命令执行
## 总结
通过以上修复,解决了:
- Windows 环境下 npm 命令找不到的问题
- 构建文件路径错误的问题
- 自动构建失败的问题
现在应用应该能够正常启动和运行了。

138
gofaster/QUICK_START.md

@ -1,138 +0,0 @@ @@ -1,138 +0,0 @@
# 🚀 GoFaster 快速启动指南
## 📋 启动方式总览
### **🎯 多种启动方式**
#### **方式 1: PowerShell 脚本(推荐)**
```powershell
# 右键选择"使用 PowerShell 运行"
.\start.ps1
# 或者在 PowerShell 中运行
.\start.ps1
```
#### **方式 2: 批处理文件**
```bash
# 双击运行(如果仍有编码问题,使用方式1)
start-dev.bat
# 或者使用英文版本
start-simple.bat
```
#### **方式 3: 直接启动**
```powershell
# 全栈启动(标准模式)
.\dev-full.ps1
# 全栈启动(调试模式)
.\dev-full.ps1 -Debug
# 全栈启动(监听模式)
.\dev-full.ps1 -Watch
```
### **⚡ 直接启动**
```powershell
# 全栈启动(标准模式)
.\dev-full.ps1
# 全栈启动(调试模式)
.\dev-full.ps1 -Debug
# 全栈启动(监听模式)
.\dev-full.ps1 -Watch
```
### **🔧 灵活启动**
```powershell
# 仅启动后端
.\dev-full.ps1 -BackendOnly
# 仅启动前端
.\dev-full.ps1 -FrontendOnly
```
## 🚀 推荐启动流程
### **1. 首次使用**
```bash
# 双击运行
start-dev.bat
# 选择选项 1: 全栈启动
```
### **2. 日常开发**
```bash
# 选择选项 3: 监听模式(自动重载)
start-dev.bat
```
### **3. 调试问题**
```bash
# 选择选项 2: 调试模式(详细日志)
start-dev.bat
```
## 📁 文件说明
| 文件 | 说明 | 用途 |
|------|------|------|
| `start-dev.bat` | 快速启动菜单 | 一键选择启动模式 |
| `dev-full.ps1` | 增强版全栈脚本 | 智能启动前后端 |
| `app/dev-enhanced.ps1` | 前端增强脚本 | 仅启动前端 |
| `backend/dev.ps1` | 后端启动脚本 | 仅启动后端 |
## 🔧 功能特性
### **✅ 已解决的问题**
- 🎯 中文乱码问题
- 📊 日志信息少的问题
- 🔄 热重载不工作的问题
- 📦 依赖管理问题
### **🚀 新增功能**
- 🧠 智能依赖检查
- 📱 进程管理和监控
- 🎨 友好的用户界面
- ⚡ 多种启动模式
## 💡 使用技巧
### **开发阶段**
1. **开始开发**:使用监听模式,自动重载
2. **调试问题**:使用调试模式,查看详细日志
3. **测试功能**:使用标准模式,稳定运行
### **维护阶段**
1. **仅修改前端**:使用 `-FrontendOnly` 模式
2. **仅修改后端**:使用 `-BackendOnly` 模式
3. **全栈开发**:使用标准模式
## 🚨 常见问题
### **Q: 启动失败怎么办?**
A: 使用调试模式 `.\dev-full.ps1 -Debug` 查看详细错误信息
### **Q: 中文显示乱码?**
A: 脚本已自动设置 UTF-8 编码,确保使用 PowerShell 或 CMD
### **Q: 端口被占用?**
A: 脚本会自动检查端口状态,如有冲突会提示解决方案
### **Q: 依赖安装失败?**
A: 脚本会自动检查和安装依赖,如失败会提供手动安装指导
## 🎯 下一步
1. **立即体验**:双击 `start-dev.bat`
2. **查看文档**:阅读 `FULL_STACK_ENHANCED.md`
3. **自定义配置**:修改 `app/vue.config.js`
4. **反馈问题**:记录遇到的问题和解决方案
---
**🎉 现在你可以享受无乱码、详细日志、智能管理的开发环境了!**

2
gofaster/app/dist/renderer/js/index.js vendored

@ -12014,7 +12014,7 @@ __webpack_require__.r(__webpack_exports__); @@ -12014,7 +12014,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("d15b4267db1069bb")
/******/ __webpack_require__.h = () => ("65321810fe15e8a1")
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */

BIN
gofaster/backend/tmp/main.exe

Binary file not shown.

149
gofaster/check-environment.ps1

@ -1,149 +0,0 @@ @@ -1,149 +0,0 @@
# GoFaster 环境兼容性检查脚本
# 检查当前环境是否满足运行要求
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " GoFaster 环境兼容性检查" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 检查 Node.js 版本
Write-Host "检查 Node.js 版本..." -ForegroundColor Yellow
try {
$nodeVersion = node --version
Write-Host "Node.js 版本: $nodeVersion" -ForegroundColor Green
# 检查版本兼容性
if ($nodeVersion -match "v(\d+)") {
$majorVersion = [int]$matches[1]
if ($majorVersion -lt 16) {
Write-Host " 警告: Node.js 版本过低,推荐使用 v16 或更高版本" -ForegroundColor Yellow
} elseif ($majorVersion -gt 20) {
Write-Host " 警告: Node.js 版本过高,可能存在兼容性问题" -ForegroundColor Yellow
} else {
Write-Host "✅ Node.js 版本兼容" -ForegroundColor Green
}
}
} catch {
Write-Host "❌ Node.js 未安装或不可用" -ForegroundColor Red
}
Write-Host ""
# 检查 npm 版本
Write-Host "检查 npm 版本..." -ForegroundColor Yellow
try {
$npmVersion = npm --version
Write-Host "npm 版本: $npmVersion" -ForegroundColor Green
# 检查版本兼容性
if ($npmVersion -match "(\d+)") {
$majorVersion = [int]$matches[1]
if ($majorVersion -lt 8) {
Write-Host " 警告: npm 版本过低,推荐使用 v8 或更高版本" -ForegroundColor Yellow
} elseif ($majorVersion -gt 10) {
Write-Host " 警告: npm 版本过高,可能存在兼容性问题" -ForegroundColor Yellow
} else {
Write-Host "✅ npm 版本兼容" -ForegroundColor Green
}
}
} catch {
Write-Host "❌ npm 未安装或不可用" -ForegroundColor Red
}
Write-Host ""
# 检查 Go 版本
Write-Host "检查 Go 版本..." -ForegroundColor Yellow
try {
$goVersion = go version
Write-Host "Go 版本: $goVersion" -ForegroundColor Green
# 检查版本兼容性
if ($goVersion -match "go(\d+\.\d+)") {
$version = [version]$matches[1]
if ($version -lt [version]"1.20") {
Write-Host " 警告: Go 版本过低,推荐使用 v1.20 或更高版本" -ForegroundColor Yellow
} elseif ($version -gt [version]"1.25") {
Write-Host " 警告: Go 版本过高,可能存在兼容性问题" -ForegroundColor Yellow
} else {
Write-Host "✅ Go 版本兼容" -ForegroundColor Green
}
}
} catch {
Write-Host "❌ Go 未安装或不可用" -ForegroundColor Red
}
Write-Host ""
# 检查项目结构
Write-Host "检查项目结构..." -ForegroundColor Yellow
$requiredDirs = @("app", "backend")
$missingDirs = @()
foreach ($dir in $requiredDirs) {
if (Test-Path $dir) {
Write-Host "✅ 目录存在: $dir" -ForegroundColor Green
} else {
Write-Host "❌ 目录缺失: $dir" -ForegroundColor Red
$missingDirs += $dir
}
}
Write-Host ""
# 检查前端依赖
Write-Host "检查前端依赖..." -ForegroundColor Yellow
if (Test-Path "app/package.json") {
Write-Host "✅ 前端 package.json 存在" -ForegroundColor Green
if (Test-Path "app/node_modules") {
Write-Host "✅ 前端依赖已安装" -ForegroundColor Green
} else {
Write-Host " 前端依赖未安装,需要运行: cd app && npm install" -ForegroundColor Yellow
}
} else {
Write-Host "❌ 前端 package.json 不存在" -ForegroundColor Red
}
Write-Host ""
# 检查后端依赖
Write-Host "检查后端依赖..." -ForegroundColor Yellow
if (Test-Path "backend/go.mod") {
Write-Host "✅ 后端 go.mod 存在" -ForegroundColor Green
} else {
Write-Host "❌ 后端 go.mod 不存在" -ForegroundColor Red
}
Write-Host ""
# 检查端口占用
Write-Host "检查端口占用..." -ForegroundColor Yellow
$ports = @(8080, 3000)
foreach ($port in $ports) {
$processes = netstat -ano 2>$null | Select-String ":$port\s"
if ($processes) {
Write-Host " 端口 $port 被占用" -ForegroundColor Yellow
} else {
Write-Host "✅ 端口 $port 可用" -ForegroundColor Green
}
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "检查完成!" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
# 提供修复建议
if ($missingDirs.Count -gt 0) {
Write-Host ""
Write-Host "🔧 修复建议:" -ForegroundColor Yellow
Write-Host " 1. 确保项目结构完整" -ForegroundColor White
Write-Host " 2. 重新克隆或下载项目" -ForegroundColor White
}
Write-Host ""
Write-Host "💡 启动建议:" -ForegroundColor Cyan
Write-Host " 1. 使用 .\start-enhanced.ps1 启动完整环境" -ForegroundColor White
Write-Host " 2. 使用 .\start-enhanced.ps1 -BackendOnly 仅启动后端" -ForegroundColor White
Write-Host " 3. 使用 .\start-enhanced.ps1 -FrontendOnly 仅启动前端" -ForegroundColor White
Write-Host " 4. 使用 .\start-enhanced.ps1 -ForceClean 强制清理后启动" -ForegroundColor White

76
gofaster/start-dev.bat

@ -1,76 +0,0 @@ @@ -1,76 +0,0 @@
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
echo ========================================
echo GoFaster 开发环境快速启动
echo ========================================
echo.
REM 检查 PowerShell 执行策略
powershell -Command "Get-ExecutionPolicy" >nul 2>&1
if errorlevel 1 (
echo [INFO] 正在设置 PowerShell 执行策略...
powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force"
)
echo.
echo 启动选项:
echo 1. 全栈启动 (前后端)
echo 2. 全栈启动 (调试模式)
echo 3. 全栈启动 (监听模式)
echo 4. 仅启动后端
echo 5. 仅启动前端
echo 6. 退出
echo.
set /p choice="请选择 (1-6): "
if "%choice%"=="1" (
echo [INFO] 启动全栈开发环境...
powershell -ExecutionPolicy Bypass -File dev-full.ps1
if errorlevel 1 (
echo [ERROR] 启动失败,请检查错误信息
pause
)
) else if "%choice%"=="2" (
echo [INFO] 启动全栈开发环境 (调试模式)...
powershell -ExecutionPolicy Bypass -File dev-full.ps1 -Debug
if errorlevel 1 (
echo [ERROR] 启动失败,请检查错误信息
pause
)
) else if "%choice%"=="3" (
echo [INFO] 启动全栈开发环境 (监听模式)...
powershell -ExecutionPolicy Bypass -File dev-full.ps1 -Watch
if errorlevel 1 (
echo [ERROR] 启动失败,请检查错误信息
pause
)
) else if "%choice%"=="4" (
echo [INFO] 仅启动后端...
powershell -ExecutionPolicy Bypass -File dev-full.ps1 -BackendOnly
if errorlevel 1 (
echo [ERROR] 启动失败,请检查错误信息
pause
)
) else if "%choice%"=="5" (
echo [INFO] 仅启动前端...
powershell -ExecutionPolicy Bypass -File dev-full.ps1 -FrontendOnly
if errorlevel 1 (
echo [ERROR] 启动失败,请检查错误信息
pause
)
) else if "%choice%"=="6" (
echo [INFO] 再见!
pause
exit /b 0
) else (
echo [ERROR] 无效选择,请重新运行脚本
pause
exit /b 1
)
echo.
echo 按任意键退出...
pause >nul

105
gofaster/start-dev.ps1

@ -1,105 +0,0 @@ @@ -1,105 +0,0 @@
# GoFaster 开发环境启动脚本
param(
[switch]$Help
)
# 设置控制台编码
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
# 显示帮助信息
if ($Help) {
Write-Host "使用方法:" -ForegroundColor Cyan
Write-Host " .\start-dev.ps1 # 显示菜单" -ForegroundColor White
Write-Host " .\start-dev.ps1 -Help # 显示此帮助" -ForegroundColor White
Write-Host " .\dev-full.ps1 # 直接启动全栈" -ForegroundColor White
Write-Host " .\dev-full.ps1 -Debug # 调试模式启动" -ForegroundColor White
Write-Host " .\dev-full.ps1 -Watch # 监听模式启动" -ForegroundColor White
exit 0
}
# 显示启动菜单
function Show-Menu {
Clear-Host
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " GoFaster 开发环境启动菜单" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "启动选项:" -ForegroundColor Yellow
Write-Host " 1. 全栈启动 (前后端)" -ForegroundColor White
Write-Host " 2. 全栈启动 (调试模式)" -ForegroundColor White
Write-Host " 3. 全栈启动 (监听模式)" -ForegroundColor White
Write-Host " 4. 仅启动后端" -ForegroundColor White
Write-Host " 5. 仅启动前端" -ForegroundColor White
Write-Host " 6. 退出" -ForegroundColor White
Write-Host ""
}
# 主菜单循环
do {
Show-Menu
$choice = Read-Host "请选择 (1-6)"
switch ($choice) {
"1" {
Write-Host "[INFO] 启动全栈开发环境..." -ForegroundColor Green
try {
& ".\dev-full.ps1"
} catch {
Write-Host "[ERROR] 启动失败: $($_.Exception.Message)" -ForegroundColor Red
Read-Host "按回车键继续..."
}
}
"2" {
Write-Host "[INFO] 启动全栈开发环境 (调试模式)..." -ForegroundColor Green
try {
& ".\dev-full.ps1" -Debug
} catch {
Write-Host "[ERROR] 启动失败: $($_.Exception.Message)" -ForegroundColor Red
Read-Host "按回车键继续..."
}
}
"3" {
Write-Host "[INFO] 启动全栈开发环境 (监听模式)..." -ForegroundColor Green
try {
& ".\dev-full.ps1" -Watch
} catch {
Write-Host "[ERROR] 启动失败: $($_.Exception.Message)" -ForegroundColor Red
Read-Host "按回车键继续..."
}
}
"4" {
Write-Host "[INFO] 仅启动后端..." -ForegroundColor Green
try {
& ".\dev-full.ps1" -BackendOnly
} catch {
Write-Host "[ERROR] 启动失败: $($_.Exception.Message)" -ForegroundColor Red
Read-Host "按回车键继续..."
}
}
"5" {
Write-Host "[INFO] 仅启动前端..." -ForegroundColor Green
try {
& ".\dev-full.ps1" -FrontendOnly
} catch {
Write-Host "[ERROR] 启动失败: $($_.Exception.Message)" -ForegroundColor Red
Read-Host "按回车键继续..."
}
}
"6" {
Write-Host "[INFO] 再见!" -ForegroundColor Green
exit 0
}
default {
Write-Host "[ERROR] 无效选择,请重新选择" -ForegroundColor Red
Start-Sleep -Seconds 2
}
}
if ($choice -match "^[1-5]$") {
$continue = Read-Host "是否返回主菜单? (y/n)"
if ($continue -eq "n" -or $continue -eq "N") {
break
}
}
} while ($true)

49
gofaster/start-enhanced.bat

@ -1,49 +0,0 @@ @@ -1,49 +0,0 @@
@echo off
chcp 65001 >nul
title GoFaster 增强版启动脚本
echo ========================================
echo GoFaster 增强版启动脚本
echo ========================================
echo.
echo 选择启动模式:
echo 1. 全栈启动 (前后端)
echo 2. 全栈启动 (调试模式)
echo 3. 全栈启动 (监听模式)
echo 4. 仅启动后端
echo 5. 仅启动前端
echo 6. 增强版启动 (推荐)
echo 7. 强制清理启动
echo.
set /p choice=请输入选择 (1-7):
if "%choice%"=="1" (
echo 启动全栈开发环境...
powershell -ExecutionPolicy Bypass -File "dev-full.ps1"
) else if "%choice%"=="2" (
echo 启动全栈开发环境 (调试模式)...
powershell -ExecutionPolicy Bypass -File "dev-full.ps1" -Debug
) else if "%choice%"=="3" (
echo 启动全栈开发环境 (监听模式)...
powershell -ExecutionPolicy Bypass -File "dev-full.ps1" -Watch
) else if "%choice%"=="4" (
echo 仅启动后端...
powershell -ExecutionPolicy Bypass -File "dev-full.ps1" -BackendOnly
) else if "%choice%"=="5" (
echo 仅启动前端...
powershell -ExecutionPolicy Bypass -File "dev-full.ps1" -FrontendOnly
) else if "%choice%"=="6" (
echo 增强版启动 (推荐)...
powershell -ExecutionPolicy Bypass -File "start-enhanced.ps1"
) else if "%choice%"=="7" (
echo 强制清理启动...
powershell -ExecutionPolicy Bypass -File "start-enhanced.ps1" -ForceClean
) else (
echo 无效选择!
)
echo.
echo 按任意键退出...
pause >nul

192
gofaster/start-enhanced.ps1

@ -1,192 +0,0 @@ @@ -1,192 +0,0 @@
# GoFaster 增强版启动脚本
# 解决 Electron 窗口启动不稳定的问题
param(
[switch]$Debug,
[switch]$Watch,
[switch]$BackendOnly,
[switch]$FrontendOnly,
[switch]$ForceClean
)
# 设置控制台编码为 UTF-8,解决中文显示乱码问题
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
# 设置环境变量
$env:LANG = "zh_CN.UTF-8"
$env:LC_ALL = "zh_CN.UTF-8"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " GoFaster 增强版启动脚本" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 检查并清理可能的问题
if ($ForceClean) {
Write-Host "执行强制清理..." -ForegroundColor Yellow
# 清理可能的锁文件
$lockFiles = @(
"app/node_modules/.cache",
"app/dist",
"backend/tmp"
)
foreach ($lockFile in $lockFiles) {
if (Test-Path $lockFile) {
try {
Remove-Item -Path $lockFile -Recurse -Force -ErrorAction Stop
Write-Host "已清理: $lockFile" -ForegroundColor Green
} catch {
Write-Host "清理失败: $lockFile - $($_.Exception.Message)" -ForegroundColor Red
}
}
}
# 清理可能的进程
try {
$electronProcesses = Get-Process | Where-Object { $_.ProcessName -like "*electron*" -or $_.ProcessName -like "*node*" }
if ($electronProcesses) {
Write-Host "发现正在运行的 Electron 进程,正在停止..." -ForegroundColor Yellow
$electronProcesses | Stop-Process -Force
Start-Sleep -Seconds 2
}
} catch {
Write-Host "进程清理失败: $($_.Exception.Message)" -ForegroundColor Red
}
}
# 检查依赖
Write-Host "检查依赖..." -ForegroundColor Yellow
# 检查前端依赖
if (-not (Test-Path "app/node_modules")) {
Write-Host "前端依赖未安装,正在安装..." -ForegroundColor Yellow
Set-Location "app"
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host "前端依赖安装失败" -ForegroundColor Red
exit 1
}
Set-Location ".."
}
# 检查后端依赖
if (-not (Test-Path "backend/go.mod")) {
Write-Host "后端 Go 模块未找到" -ForegroundColor Red
exit 1
}
# 检查 air 是否安装
try {
$airVersion = air -v 2>$null
if (-not $airVersion) {
Write-Host "Air 未安装,正在安装..." -ForegroundColor Yellow
go install github.com/air-verse/air@latest
}
} catch {
Write-Host "Air 未安装,正在安装..." -ForegroundColor Yellow
go install github.com/air-verse/air@latest
}
Write-Host "依赖检查完成" -ForegroundColor Green
Write-Host ""
# 选择启动模式
$frontendScript = if ($Debug) { "npm run dev:debug" } elseif ($Watch) { "npm run dev:watch" } else { "npm run dev:watch" }
$backendScript = "air"
# 启动服务
if (-not $FrontendOnly) {
Write-Host "启动后端热重载..." -ForegroundColor Green
$backendProcess = Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd backend; $backendScript" -WindowStyle Normal -PassThru
Write-Host "后端已启动 (PID: $($backendProcess.Id))" -ForegroundColor Green
# 等待后端启动
Write-Host "等待后端启动..." -ForegroundColor Yellow
Start-Sleep -Seconds 5
# 检查后端是否成功启动
$retryCount = 0
$maxRetries = 3
$backendStarted = $false
while ($retryCount -lt $maxRetries -and -not $backendStarted) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:8080/health" -Method GET -TimeoutSec 10 -ErrorAction Stop
if ($response.StatusCode -eq 200) {
Write-Host "后端启动成功" -ForegroundColor Green
$backendStarted = $true
}
} catch {
$retryCount++
if ($retryCount -lt $maxRetries) {
Write-Host "后端可能还在启动中,等待重试... (尝试 $retryCount/$maxRetries)" -ForegroundColor Yellow
Start-Sleep -Seconds 5
} else {
Write-Host "后端启动检查失败,但继续启动前端..." -ForegroundColor Yellow
}
}
}
}
if (-not $BackendOnly) {
Write-Host "启动前端热重载..." -ForegroundColor Green
Write-Host "使用脚本: $frontendScript" -ForegroundColor Cyan
# 确保前端构建目录存在
if (-not (Test-Path "app/dist")) {
Write-Host "前端构建目录不存在,正在预构建..." -ForegroundColor Yellow
Set-Location "app"
npm run build:vue
if ($LASTEXITCODE -ne 0) {
Write-Host "前端预构建失败,尝试继续启动..." -ForegroundColor Yellow
}
Set-Location ".."
}
$frontendProcess = Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd app; $frontendScript" -WindowStyle Normal -PassThru
Write-Host "前端已启动 (PID: $($frontendProcess.Id))" -ForegroundColor Green
}
Write-Host ""
Write-Host "服务启动完成!" -ForegroundColor Green
if (-not $BackendOnly) {
Write-Host "后端: http://localhost:8080" -ForegroundColor Cyan
Write-Host "Swagger: http://localhost:8080/swagger/index.html" -ForegroundColor Cyan
}
if (-not $FrontendOnly) {
Write-Host "前端: Electron 应用 (自动重载已启用)" -ForegroundColor Cyan
Write-Host "注意: 前端现在默认使用 watch 模式以获得更好的热重载体验" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "使用说明:" -ForegroundColor Yellow
Write-Host " - 使用 -Debug 参数启用详细调试信息" -ForegroundColor White
Write-Host " - 使用 -Watch 参数显式启用文件监听" -ForegroundColor White
Write-Host " - 使用 -BackendOnly 仅启动后端" -ForegroundColor White
Write-Host " - 使用 -FrontendOnly 仅启动前端" -ForegroundColor White
Write-Host " - 使用 -ForceClean 强制清理并重新启动" -ForegroundColor White
Write-Host " - 按 Ctrl+C 停止服务" -ForegroundColor White
Write-Host ""
# 显示进程信息
if (-not $BackendOnly -and -not $FrontendOnly) {
Write-Host "进程信息:" -ForegroundColor Yellow
Write-Host " 后端 PID: $($backendProcess.Id)" -ForegroundColor White
Write-Host " 前端 PID: $($frontendProcess.Id)" -ForegroundColor White
Write-Host ""
Write-Host "管理命令:" -ForegroundColor Yellow
Write-Host " 停止后端: Stop-Process -Id $($backendProcess.Id)" -ForegroundColor White
Write-Host " 停止前端: Stop-Process -Id $($frontendProcess.Id)" -ForegroundColor White
Write-Host " 停止所有: Get-Process | Where-Object {$_.ProcessName -eq 'powershell'} | Stop-Process" -ForegroundColor White
}
Write-Host "代码更改将自动触发重新构建和重载!" -ForegroundColor Yellow
Write-Host "前端现在默认使用 watch 模式以获得更好的热重载体验" -ForegroundColor Green
Write-Host "按任意键退出..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

47
gofaster/start-simple.bat

@ -1,47 +0,0 @@ @@ -1,47 +0,0 @@
@echo off
title GoFaster Development Environment
echo ========================================
echo GoFaster Development Environment
echo ========================================
echo.
echo Starting options:
echo 1. Full Stack (Frontend + Backend)
echo 2. Full Stack (Debug Mode)
echo 3. Full Stack (Watch Mode)
echo 4. Backend Only
echo 5. Frontend Only
echo 6. Exit
echo.
set /p choice="Please select (1-6): "
if "%choice%"=="1" (
echo [INFO] Starting full stack development environment...
powershell -ExecutionPolicy Bypass -File dev-full.ps1
) else if "%choice%"=="2" (
echo [INFO] Starting full stack development environment (Debug Mode)...
powershell -ExecutionPolicy Bypass -File dev-full.ps1 -Debug
) else if "%choice%"=="3" (
echo [INFO] Starting full stack development environment (Watch Mode)...
powershell -ExecutionPolicy Bypass -File dev-full.ps1 -Watch
) else if "%choice%"=="4" (
echo [INFO] Starting backend only...
powershell -ExecutionPolicy Bypass -File dev-full.ps1 -BackendOnly
) else if "%choice%"=="5" (
echo [INFO] Starting frontend only...
powershell -ExecutionPolicy Bypass -File dev-full.ps1 -FrontendOnly
) else if "%choice%"=="6" (
echo [INFO] Goodbye!
pause
exit /b 0
) else (
echo [ERROR] Invalid choice, please run the script again
pause
exit /b 1
)
echo.
echo Press any key to exit...
pause >nul

15
gofaster/test-api-fixed.bat

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
@echo off
chcp 65001 >nul
title GoFaster API 修复版测试脚本
echo ========================================
echo GoFaster API 修复版测试脚本
echo ========================================
echo.
echo 正在启动 PowerShell 测试脚本...
powershell -ExecutionPolicy Bypass -File "test-api-fixed.ps1"
echo.
echo 按任意键退出...
pause >nul

143
gofaster/test-api-fixed.ps1

@ -1,143 +0,0 @@ @@ -1,143 +0,0 @@
# GoFaster API 修复版测试脚本
# 用于测试修复后的用户管理API接口
param(
[string]$BaseUrl = "http://localhost:8080",
[string]$Username = "admin",
[string]$Password = "password"
)
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " GoFaster API 修复版测试脚本" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 1. 测试健康检查端点
Write-Host "1. 测试健康检查端点..." -ForegroundColor Yellow
try {
$healthResponse = Invoke-RestMethod -Uri "$BaseUrl/health" -Method GET -TimeoutSec 10
Write-Host "✅ 健康检查通过: $($healthResponse.status)" -ForegroundColor Green
} catch {
Write-Host "❌ 健康检查失败: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Write-Host ""
# 2. 测试登录接口
Write-Host "2. 测试登录接口..." -ForegroundColor Yellow
try {
$loginData = @{
username = $Username
password = $Password
} | ConvertTo-Json
$loginResponse = Invoke-RestMethod -Uri "$BaseUrl/api/auth/login" -Method POST -Body $loginData -ContentType "application/json" -TimeoutSec 10
if ($loginResponse.data.token) {
Write-Host "✅ 登录成功,获取到token" -ForegroundColor Green
$token = $loginResponse.data.token
} else {
Write-Host "❌ 登录失败,未获取到token" -ForegroundColor Red
Write-Host "响应内容: $($loginResponse | ConvertTo-Json)" -ForegroundColor Red
exit 1
}
} catch {
Write-Host "❌ 登录失败: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Write-Host ""
# 3. 测试原始管理员路由(需要完整权限)
Write-Host "3. 测试原始管理员路由..." -ForegroundColor Yellow
try {
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
$usersResponse = Invoke-RestMethod -Uri "$BaseUrl/api/auth/admin/users?page=1&pageSize=10" -Method GET -Headers $headers -TimeoutSec 10
if ($usersResponse.data) {
Write-Host "✅ 原始管理员路由 - 用户列表获取成功" -ForegroundColor Green
Write-Host " 用户数量: $($usersResponse.data.Count)" -ForegroundColor White
Write-Host " 总数量: $($usersResponse.total)" -ForegroundColor White
} else {
Write-Host "❌ 原始管理员路由 - 用户列表获取失败" -ForegroundColor Red
Write-Host "响应内容: $($usersResponse | ConvertTo-Json)" -ForegroundColor Red
}
} catch {
Write-Host "❌ 原始管理员路由 - 用户列表获取失败: $($_.Exception.Message)" -ForegroundColor Red
if ($_.Exception.Response) {
$statusCode = $_.Exception.Response.StatusCode
Write-Host "HTTP状态码: $statusCode" -ForegroundColor Red
}
}
Write-Host ""
# 4. 测试简化权限路由(只检查JWT)
Write-Host "4. 测试简化权限路由..." -ForegroundColor Yellow
try {
$testUsersResponse = Invoke-RestMethod -Uri "$BaseUrl/api/auth/test-admin/users?page=1&pageSize=10" -Method GET -Headers $headers -TimeoutSec 10
if ($testUsersResponse.data) {
Write-Host "✅ 简化权限路由 - 用户列表获取成功" -ForegroundColor Green
Write-Host " 用户数量: $($testUsersResponse.data.Count)" -ForegroundColor White
Write-Host " 总数量: $($testUsersResponse.total)" -ForegroundColor White
} else {
Write-Host "❌ 简化权限路由 - 用户列表获取失败" -ForegroundColor Red
Write-Host "响应内容: $($testUsersResponse | ConvertTo-Json)" -ForegroundColor Red
}
} catch {
Write-Host "❌ 简化权限路由 - 用户列表获取失败: $($_.Exception.Message)" -ForegroundColor Red
if ($_.Exception.Response) {
$statusCode = $_.Exception.Response.StatusCode
Write-Host "HTTP状态码: $statusCode" -ForegroundColor Red
}
}
Write-Host ""
# 5. 测试角色列表接口
Write-Host "5. 测试角色列表接口..." -ForegroundColor Yellow
try {
$rolesResponse = Invoke-RestMethod -Uri "$BaseUrl/api/auth/test-admin/roles" -Method GET -Headers $headers -TimeoutSec 10
if ($rolesResponse.data) {
Write-Host "✅ 角色列表获取成功" -ForegroundColor Green
Write-Host " 角色数量: $($rolesResponse.data.Count)" -ForegroundColor White
foreach ($role in $rolesResponse.data) {
Write-Host " - $($role.name) ($($role.code))" -ForegroundColor White
}
} else {
Write-Host "❌ 角色列表获取失败,响应格式异常" -ForegroundColor Red
Write-Host "响应内容: $($rolesResponse | ConvertTo-Json)" -ForegroundColor Red
}
} catch {
Write-Host "❌ 角色列表获取失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " API 测试完成" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 显示使用说明
Write-Host "使用说明:" -ForegroundColor Yellow
Write-Host " - 默认用户名: admin" -ForegroundColor White
Write-Host " - 默认密码: password" -ForegroundColor White
Write-Host " - 原始管理员路由: /api/auth/admin/*" -ForegroundColor White
Write-Host " - 简化权限路由: /api/auth/test-admin/*" -ForegroundColor White
Write-Host ""
Write-Host "修复说明:" -ForegroundColor Yellow
Write-Host " - UserController 现在使用统一的响应格式" -ForegroundColor White
Write-Host " - 添加了简化权限的测试路由" -ForegroundColor White
Write-Host " - 权限中间件暂时放宽了检查" -ForegroundColor White
Write-Host ""
Write-Host "按任意键退出..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

15
gofaster/test-api.bat

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
@echo off
chcp 65001 >nul
title GoFaster API 测试脚本
echo ========================================
echo GoFaster API 测试脚本
echo ========================================
echo.
echo 正在启动 PowerShell 测试脚本...
powershell -ExecutionPolicy Bypass -File "test-api.ps1"
echo.
echo 按任意键退出...
pause >nul

115
gofaster/test-api.ps1

@ -1,115 +0,0 @@ @@ -1,115 +0,0 @@
# GoFaster API 测试脚本
# 用于测试用户管理API接口
param(
[string]$BaseUrl = "http://localhost:8080",
[string]$Username = "admin",
[string]$Password = "password"
)
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " GoFaster API 测试脚本" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 1. 测试健康检查端点
Write-Host "1. 测试健康检查端点..." -ForegroundColor Yellow
try {
$healthResponse = Invoke-RestMethod -Uri "$BaseUrl/health" -Method GET -TimeoutSec 10
Write-Host "✅ 健康检查通过: $($healthResponse.status)" -ForegroundColor Green
} catch {
Write-Host "❌ 健康检查失败: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Write-Host ""
# 2. 测试登录接口
Write-Host "2. 测试登录接口..." -ForegroundColor Yellow
try {
$loginData = @{
username = $Username
password = $Password
} | ConvertTo-Json
$loginResponse = Invoke-RestMethod -Uri "$BaseUrl/api/auth/login" -Method POST -Body $loginData -ContentType "application/json" -TimeoutSec 10
if ($loginResponse.token) {
Write-Host "✅ 登录成功,获取到token" -ForegroundColor Green
$token = $loginResponse.token
} else {
Write-Host "❌ 登录失败,未获取到token" -ForegroundColor Red
Write-Host "响应内容: $($loginResponse | ConvertTo-Json)" -ForegroundColor Red
exit 1
}
} catch {
Write-Host "❌ 登录失败: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Write-Host ""
# 3. 测试用户列表接口(需要管理员权限)
Write-Host "3. 测试用户列表接口..." -ForegroundColor Yellow
try {
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
$usersResponse = Invoke-RestMethod -Uri "$BaseUrl/api/auth/admin/users?page=1&pageSize=10" -Method GET -Headers $headers -TimeoutSec 10
if ($usersResponse.data) {
Write-Host "✅ 用户列表获取成功" -ForegroundColor Green
Write-Host " 用户数量: $($usersResponse.data.Count)" -ForegroundColor White
Write-Host " 总数量: $($usersResponse.total)" -ForegroundColor White
Write-Host " 当前页: $($usersResponse.page)" -ForegroundColor White
Write-Host " 每页大小: $($usersResponse.size)" -ForegroundColor White
} else {
Write-Host "❌ 用户列表获取失败,响应格式异常" -ForegroundColor Red
Write-Host "响应内容: $($usersResponse | ConvertTo-Json)" -ForegroundColor Red
}
} catch {
Write-Host "❌ 用户列表获取失败: $($_.Exception.Message)" -ForegroundColor Red
if ($_.Exception.Response) {
$statusCode = $_.Exception.Response.StatusCode
Write-Host "HTTP状态码: $statusCode" -ForegroundColor Red
}
}
Write-Host ""
# 4. 测试角色列表接口
Write-Host "4. 测试角色列表接口..." -ForegroundColor Yellow
try {
$rolesResponse = Invoke-RestMethod -Uri "$BaseUrl/api/auth/admin/roles" -Method GET -Headers $headers -TimeoutSec 10
if ($rolesResponse.data) {
Write-Host "✅ 角色列表获取成功" -ForegroundColor Green
Write-Host " 角色数量: $($rolesResponse.data.Count)" -ForegroundColor White
foreach ($role in $rolesResponse.data) {
Write-Host " - $($role.name) ($($role.code))" -ForegroundColor White
}
} else {
Write-Host "❌ 角色列表获取失败,响应格式异常" -ForegroundColor Red
Write-Host "响应内容: $($rolesResponse | ConvertTo-Json)" -ForegroundColor Red
}
} catch {
Write-Host "❌ 角色列表获取失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " API 测试完成" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 显示使用说明
Write-Host "使用说明:" -ForegroundColor Yellow
Write-Host " - 默认用户名: admin" -ForegroundColor White
Write-Host " - 默认密码: password" -ForegroundColor White
Write-Host " - 可以通过参数修改: .\test-api.ps1 -Username 'your_username' -Password 'your_password'" -ForegroundColor White
Write-Host ""
Write-Host "按任意键退出..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

126
gofaster/test-captcha-display.html

@ -1,126 +0,0 @@ @@ -1,126 +0,0 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>验证码测试</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 600px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.captcha-container {
margin: 20px 0;
padding: 20px;
border: 1px solid #ddd;
border-radius: 4px;
}
.captcha-image {
border: 1px solid #ccc;
border-radius: 4px;
cursor: pointer;
}
button {
background: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin: 10px 5px;
}
button:hover {
background: #0056b3;
}
.error {
color: red;
margin: 10px 0;
}
.success {
color: green;
margin: 10px 0;
}
</style>
</head>
<body>
<div class="container">
<h1>验证码显示测试</h1>
<div class="captcha-container">
<h3>验证码图片:</h3>
<img id="captchaImage" class="captcha-image" alt="验证码" style="display: none;" />
<div id="captchaPlaceholder">点击按钮获取验证码</div>
<br>
<button onclick="getCaptcha()">获取验证码</button>
<button onclick="refreshCaptcha()">刷新验证码</button>
</div>
<div id="status"></div>
<div id="response"></div>
</div>
<script>
let currentCaptchaId = '';
async function getCaptcha() {
try {
document.getElementById('status').innerHTML = '<div class="success">正在获取验证码...</div>';
const response = await fetch('http://localhost:8080/api/auth/captcha', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log('验证码响应:', data);
if (data.code === 200 && data.data) {
const captchaImage = document.getElementById('captchaImage');
const placeholder = document.getElementById('captchaPlaceholder');
captchaImage.src = data.data.captcha_image;
captchaImage.style.display = 'block';
placeholder.style.display = 'none';
currentCaptchaId = data.data.captcha_id;
document.getElementById('status').innerHTML = '<div class="success">验证码获取成功!</div>';
document.getElementById('response').innerHTML = `
<h4>响应数据:</h4>
<pre>${JSON.stringify(data, null, 2)}</pre>
`;
} else {
throw new Error(data.message || '获取验证码失败');
}
} catch (error) {
console.error('获取验证码失败:', error);
document.getElementById('status').innerHTML = `<div class="error">获取验证码失败: ${error.message}</div>`;
}
}
function refreshCaptcha() {
getCaptcha();
}
// 页面加载时自动获取验证码
window.onload = function() {
getCaptcha();
};
</script>
</body>
</html>

15
gofaster/test-jwt-fix.bat

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
@echo off
chcp 65001 >nul
title GoFaster JWT 修复测试脚本
echo ========================================
echo GoFaster JWT 修复测试脚本
echo ========================================
echo.
echo 正在启动 PowerShell 测试脚本...
powershell -ExecutionPolicy Bypass -File "test-jwt-fix.ps1"
echo.
echo 按任意键退出...
pause >nul

154
gofaster/test-jwt-fix.ps1

@ -1,154 +0,0 @@ @@ -1,154 +0,0 @@
# GoFaster JWT 修复测试脚本
# 用于测试修复后的JWT认证功能
param(
[string]$BaseUrl = "http://localhost:8080",
[string]$Username = "admin",
[string]$Password = "password"
)
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " GoFaster JWT 修复测试脚本" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 1. 测试健康检查端点
Write-Host "1. 测试健康检查端点..." -ForegroundColor Yellow
try {
$healthResponse = Invoke-RestMethod -Uri "$BaseUrl/health" -Method GET -TimeoutSec 10
Write-Host "✅ 健康检查通过: $($healthResponse.status)" -ForegroundColor Green
} catch {
Write-Host "❌ 健康检查失败: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Write-Host ""
# 2. 测试登录接口
Write-Host "2. 测试登录接口..." -ForegroundColor Yellow
try {
$loginData = @{
username = $Username
password = $Password
} | ConvertTo-Json
$loginResponse = Invoke-RestMethod -Uri "$BaseUrl/api/auth/login" -Method POST -Body $loginData -ContentType "application/json" -TimeoutSec 10
if ($loginResponse.data.token) {
Write-Host "✅ 登录成功,获取到token" -ForegroundColor Green
$token = $loginResponse.data.token
Write-Host " Token: $($token.Substring(0, [Math]::Min(50, $token.Length)))..." -ForegroundColor White
# 检查token是否是真正的JWT格式
if ($token -match "^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$") {
Write-Host " ✅ Token格式正确 (JWT格式)" -ForegroundColor Green
} else {
Write-Host " Token格式可能不正确" -ForegroundColor Yellow
}
} else {
Write-Host "❌ 登录失败,未获取到token" -ForegroundColor Red
Write-Host "响应内容: $($loginResponse | ConvertTo-Json)" -ForegroundColor Red
exit 1
}
} catch {
Write-Host "❌ 登录失败: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Write-Host ""
# 3. 测试用户信息接口
Write-Host "3. 测试用户信息接口..." -ForegroundColor Yellow
try {
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
$userInfoResponse = Invoke-RestMethod -Uri "$BaseUrl/api/auth/userinfo" -Method GET -Headers $headers -TimeoutSec 10
if ($userInfoResponse.data) {
Write-Host "✅ 用户信息获取成功" -ForegroundColor Green
Write-Host " 用户ID: $($userInfoResponse.data.id)" -ForegroundColor White
Write-Host " 用户名: $($userInfoResponse.data.username)" -ForegroundColor White
Write-Host " 邮箱: $($userInfoResponse.data.email)" -ForegroundColor White
} else {
Write-Host "❌ 用户信息获取失败" -ForegroundColor Red
Write-Host "响应内容: $($userInfoResponse | ConvertTo-Json)" -ForegroundColor Red
}
} catch {
Write-Host "❌ 用户信息获取失败: $($_.Exception.Message)" -ForegroundColor Red
if ($_.Exception.Response) {
$statusCode = $_.Exception.Response.StatusCode
Write-Host "HTTP状态码: $statusCode" -ForegroundColor Red
}
}
Write-Host ""
# 4. 测试用户列表接口(使用原始管理员路由)
Write-Host "4. 测试用户列表接口(原始管理员路由)..." -ForegroundColor Yellow
try {
$usersUrl = "$BaseUrl/api/auth/admin/users?page=1&pageSize=10"
$usersResponse = Invoke-RestMethod -Uri $usersUrl -Method GET -Headers $headers -TimeoutSec 10
if ($usersResponse.data) {
Write-Host "✅ 用户列表获取成功" -ForegroundColor Green
Write-Host " 用户数量: $($usersResponse.data.Count)" -ForegroundColor White
Write-Host " 总数量: $($usersResponse.total)" -ForegroundColor White
Write-Host " 当前页: $($usersResponse.page)" -ForegroundColor White
Write-Host " 每页大小: $($usersResponse.size)" -ForegroundColor White
} else {
Write-Host "❌ 用户列表获取失败" -ForegroundColor Red
Write-Host "响应内容: $($usersResponse | ConvertTo-Json)" -ForegroundColor Red
}
} catch {
Write-Host "❌ 用户列表获取失败: $($_.Exception.Message)" -ForegroundColor Red
if ($_.Exception.Response) {
$statusCode = $_.Exception.Response.StatusCode
Write-Host "HTTP状态码: $statusCode" -ForegroundColor Red
}
}
Write-Host ""
# 5. 测试角色列表接口
Write-Host "5. 测试角色列表接口..." -ForegroundColor Yellow
try {
$rolesResponse = Invoke-RestMethod -Uri "$BaseUrl/api/auth/admin/roles" -Method GET -Headers $headers -TimeoutSec 10
if ($rolesResponse.data) {
Write-Host "✅ 角色列表获取成功" -ForegroundColor Green
Write-Host " 角色数量: $($rolesResponse.data.Count)" -ForegroundColor White
foreach ($role in $rolesResponse.data) {
Write-Host " - $($role.name) ($($role.code))" -ForegroundColor White
}
} else {
Write-Host "❌ 角色列表获取失败" -ForegroundColor Red
Write-Host "响应内容: $($rolesResponse | ConvertTo-Json)" -ForegroundColor Red
}
} catch {
Write-Host "❌ 角色列表获取失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " JWT 修复测试完成" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 显示修复说明
Write-Host "修复内容:" -ForegroundColor Yellow
Write-Host " - 修复了JWT token生成,现在生成真正的JWT格式" -ForegroundColor White
Write-Host " - 修复了GetUserID函数,使其更安全" -ForegroundColor White
Write-Host " - 添加了详细的调试日志" -ForegroundColor White
Write-Host ""
Write-Host "预期结果:" -ForegroundColor Yellow
Write-Host " - 登录后应该获得真正的JWT token" -ForegroundColor White
Write-Host " - 用户信息接口应该能正常访问" -ForegroundColor White
Write-Host " - 用户列表和角色列表应该能正常获取" -ForegroundColor White
Write-Host ""
Write-Host "按任意键退出..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

122
gofaster/test-login-complete.md

@ -1,122 +0,0 @@ @@ -1,122 +0,0 @@
# 登录功能完整测试脚本
## 🚨 重要提醒
**在测试之前,请确保:**
1. 后端已经重新编译并启动
2. 前端已经重新编译并启动
3. 所有修改都已保存
## 🔧 问题诊断
### 检查 1: 后端验证码是否增强
1. 访问 `http://localhost:8080/api/auth/captcha`
2. **预期结果**: 返回的 `captcha_image` 应该包含复杂的 SVG 内容
3. **如果还是简单文本**: 说明后端没有重新编译
### 检查 2: 前端模态窗是否修复
1. 打开前端应用
2. 点击"登录"按钮
3. 尝试点击登录弹窗外部区域
4. **预期结果**: 弹窗不应该关闭
### 检查 3: 登录状态切换是否正常
1. 完成登录流程
2. 检查欢迎页面是否显示用户信息
3. **预期结果**: 应该显示"欢迎回来,sysadmin!"
## 🧪 完整测试流程
### 步骤 1: 重启服务
```bash
# 停止当前服务
# 重新启动后端
cd backend
air
# 重新启动前端
cd app
npm run dev
```
### 步骤 2: 测试验证码增强
1. 打开浏览器开发者工具
2. 访问 `http://localhost:8080/api/auth/captcha`
3. 检查响应中的 `captcha_image` 字段
4. **应该看到**: 复杂的 SVG 内容,包含干扰元素
### 步骤 3: 测试前端模态窗
1. 打开前端应用
2. 点击右上角"登录"按钮
3. 尝试点击弹窗外部区域
4. **预期**: 弹窗保持打开状态
5. 点击弹窗右上角 × 按钮
6. **预期**: 弹窗正常关闭
### 步骤 4: 测试登录流程
1. 在登录弹窗中输入:
- 用户名: `sysadmin`
- 密码: `sysadmin@123`
- 验证码: 从图片中识别
2. 点击"登录"按钮
3. **预期**: 登录成功,弹窗关闭
### 步骤 5: 测试状态切换
1. 登录成功后,检查欢迎页面
2. **预期看到**:
- "欢迎回来,sysadmin!"
- 功能卡片(速度测试、历史记录等)
- 待办事项列表
- 最近活动
3. **不应该看到**: "登录"按钮
### 步骤 6: 测试登出功能
1. 点击右上角用户头像
2. 选择"退出登录"
3. **预期**: 页面回到未登录状态
## 🐛 常见问题排查
### 问题 1: 验证码还是简单文本
**原因**: 后端没有重新编译
**解决**:
```bash
cd backend
go build -o main.exe .
./main.exe
```
### 问题 2: 模态窗还是可以点击外部关闭
**原因**: 前端没有重新编译
**解决**:
```bash
cd app
npm run dev
```
### 问题 3: 登录后状态没有切换
**原因**: Vue 响应式问题
**解决**: 检查浏览器控制台是否有错误
## 📊 测试结果记录
| 测试项目 | 预期结果 | 实际结果 | 状态 |
|---------|---------|---------|------|
| 验证码增强 | 复杂SVG | | |
| 模态窗修复 | 外部点击不关闭 | | |
| 登录状态切换 | 显示用户信息 | | |
| 登出功能 | 回到未登录状态 | | |
## 🎯 下一步行动
如果测试失败,请:
1. 检查控制台错误信息
2. 确认服务是否重新启动
3. 检查网络请求是否正常
4. 提供具体的错误信息
## 📞 技术支持
如果问题仍然存在,请提供:
1. 浏览器控制台错误信息
2. 网络请求的响应内容
3. 具体的操作步骤和结果

94
gofaster/test-login-fix-verification.md

@ -1,94 +0,0 @@ @@ -1,94 +0,0 @@
# 登录状态切换修复验证
## 🔧 已修复的问题
### 1. MainLayout.vue 架构问题 ✅
- **问题**: provide 在 export default 中引用了 setup 中的响应式数据
- **修复**: 将 provide 移到 setup 函数中,使用正确的 Vue 3 Composition API 语法
- **效果**: 子组件现在可以正确接收到响应式的登录状态
### 2. 响应式数据传递 ✅
- **问题**: isLoggedIn 和 currentUser 没有正确传递给子组件
- **修复**: 使用 provide() 函数在 setup 中提供响应式数据
- **效果**: 子组件可以实时响应登录状态变化
## 🧪 测试步骤
### 步骤 1: 重启前端服务
```bash
# 停止当前前端服务 (Ctrl+C)
cd app
npm run dev
```
### 步骤 2: 测试登录流程
1. 打开前端应用
2. 点击右上角"登录"按钮
3. 输入凭据:
- 用户名: `sysadmin`
- 密码: `sysadmin@123`
- 验证码: 从图片中识别
4. 点击"登录"按钮
### 步骤 3: 验证状态切换
**预期结果**:
- 登录成功后弹窗关闭
- 欢迎页面显示"欢迎回来,sysadmin!"
- 不显示"登录"按钮
- 显示功能卡片(速度测试、历史记录等)
- 显示待办事项列表
- 显示最近活动
### 步骤 4: 验证用户信息
**预期结果**:
- 用户信息应该显示为 `admin` 而不是 `用户`
- 邮箱应该显示为 `admin@gofaster.com` 而不是 `user@example.com`
## 🐛 如果仍有问题
### 检查控制台日志
应该看到以下日志:
```
Home.vue - 登录状态变化: true
Home.vue - 当前用户信息: {name: "admin", email: "admin@gofaster.com", ...}
Home.vue - 更新后的用户信息: {name: "admin", email: "admin@gofaster.com", ...}
```
### 检查网络请求
1. 验证码获取是否成功
2. 登录请求是否成功
3. 响应数据格式是否正确
### 检查本地存储
```javascript
// 在浏览器控制台中执行
localStorage.getItem('isLoggedIn') // 应该是 "true"
localStorage.getItem('user') // 应该包含用户信息
localStorage.getItem('token') // 应该包含 JWT token
```
## 📝 技术细节
### 修复的核心问题
1. **Vue 3 Composition API 架构**: 将 provide 移到 setup 函数中
2. **响应式数据传递**: 使用 provide() 函数提供响应式引用
3. **数据绑定**: 确保子组件能正确接收和响应数据变化
### 数据流
```
MainLayout (setup) → provide() → Home.vue (inject) → 模板渲染
响应式数据变化 → 自动更新 → UI 状态切换
```
## 🎯 下一步
如果测试成功:
1. 验证登出功能是否正常工作
2. 检查其他页面的登录状态是否正确
3. 测试页面刷新后的状态保持
如果测试失败:
1. 提供具体的错误信息
2. 检查控制台日志
3. 确认前端服务是否重新启动

96
gofaster/test-login-fixes.md

@ -1,96 +0,0 @@ @@ -1,96 +0,0 @@
# 登录功能修复测试指南
## 🔧 已修复的问题
### 1. 登录弹窗模态窗问题 ✅
- **问题**:点击登录窗外部区域,登录窗会消失
- **修复**:将 `@click="handleOverlayClick"` 改为 `@click.self="closeModal"`
- **效果**:现在只有点击遮罩层(非弹窗区域)才会关闭弹窗
### 2. 验证码安全性增强 ✅
- **问题**:验证码只是简单字符,安全性不足
- **修复**:添加了干扰线、干扰点、干扰圆、字符旋转、随机颜色等
- **效果**:验证码现在包含多种干扰元素,提高安全性
### 3. 登录后欢迎页面状态切换 ✅
- **问题**:登录后欢迎页面没有切换到登录状态
- **修复**:修复了 `$watch` 语法,确保正确监听登录状态变化
- **效果**:登录后应该正确显示用户信息和功能卡片
## 🧪 测试步骤
### 测试 1: 模态窗功能
1. 点击右上角"登录"按钮
2. 尝试点击登录弹窗外部区域
3. **预期结果**:弹窗不会关闭
4. 点击弹窗右上角的 × 按钮
5. **预期结果**:弹窗正常关闭
### 测试 2: 验证码安全性
1. 打开登录弹窗
2. 点击"点击获取验证码"
3. **预期结果**:显示包含干扰元素的验证码图片
4. 刷新验证码几次
5. **预期结果**:每次生成的验证码都有不同的干扰元素
### 测试 3: 登录状态切换
1. 使用正确凭据登录(sysadmin / sysadmin@123)
2. **预期结果**:登录成功后弹窗关闭
3. 检查欢迎页面
4. **预期结果**
- 显示"欢迎回来,sysadmin!"
- 不显示"登录"按钮
- 显示功能卡片(速度测试、历史记录等)
- 显示待办事项列表
- 显示最近活动
### 测试 4: 登出功能
1. 点击右上角用户头像
2. 选择"退出登录"
3. **预期结果**
- 欢迎页面切换回未登录状态
- 显示"欢迎光临,请登录!"
- 显示"登录"按钮
- 隐藏功能卡片和待办事项
## 🐛 如果仍有问题
### 检查控制台日志
- 查看是否有 JavaScript 错误
- 检查登录状态变化日志
- 检查用户信息更新日志
### 检查网络请求
- 验证码获取是否成功
- 登录请求是否成功
- 响应数据格式是否正确
### 检查本地存储
- `localStorage.getItem('isLoggedIn')`
- `localStorage.getItem('user')`
- `localStorage.getItem('token')`
## 📝 技术细节
### 验证码增强特性
- 随机干扰线(3条)
- 随机干扰点(20个)
- 随机干扰圆(5个)
- 字符随机旋转(±10度)
- 字符随机颜色
- 字符随机字体大小
- 噪声滤镜效果
### 状态管理
- 使用 Vue 3 Composition API
- 响应式数据绑定
- 全局事件通信
- 本地存储持久化
## 🎯 下一步优化建议
1. **添加验证码刷新按钮**:在验证码图片旁边添加刷新图标
2. **增强错误处理**:显示更友好的错误提示
3. **添加记住密码功能**:可选的密码记忆功能
4. **添加自动登录**:检查本地存储的登录状态
5. **优化移动端体验**:响应式设计优化
Loading…
Cancel
Save