You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

3.3 KiB

前台路由同步逻辑更新

📋 更新内容

1. 删除 frontend_backend_routes 表中的 created_at 字段

修改的文件:

  • backend/internal/auth/model/frontend_backend_route.go
    • FrontendBackendRoute 结构体中移除了 CreatedAt 字段
    • 保留了 UpdatedAt 字段用于记录更新时间

数据库迁移:

  • backend/internal/auth/migration/remove_delete_at_fields.go
    • 添加了 removeCreatedAtFromFrontendBackendRoutes() 函数
    • RemoveDeleteAtFields() 函数中调用该函数
    • 包含完整的表存在检查和字段存在检查
    • 添加了详细的调试日志

迁移逻辑:

// 检查表是否存在
tableExists := db.Migrator().HasTable("frontend_backend_routes")

// 检查 created_at 字段是否存在
columnExists := db.Migrator().HasColumn("frontend_backend_routes", "created_at")

// 删除 created_at 字段
ddlQuery := "ALTER TABLE frontend_backend_routes DROP COLUMN created_at"

2. 为 backend_route 字段补充 apiBaseUrl 前缀

修改的文件:

  • app/src/renderer/modules/route-sync/RouteMapper.js
    • 导入了 getFinalConfig 函数从 app.config.js
    • 修改了 _createApiMappingFromDirectCall() 方法
    • 修改了 _getSubRouteMapping() 方法

实现逻辑:

// 获取完整的API基础URL
const config = getFinalConfig()
const fullBackendRoute = `${config.apiBaseUrl}${apiCall.path}`

配置获取方式:

  • 使用 getFinalConfig() 函数获取最终配置
  • 优先使用用户自定义配置(localStorage中的设置)
  • 回退到环境配置(development/production/test)
  • 确保获取到完整的API基础URL(包含 /api 前缀)

🔧 技术细节

API基础URL获取流程:

  1. 用户配置优先: 从 localStorage.getItem('gofaster-settings') 获取用户自定义的API URL
  2. 环境配置回退: 如果用户没有配置,使用当前环境的默认配置
  3. URL构建: 自动添加 /api 后缀,确保完整的API路径

数据库字段变更:

  • 移除字段: created_at (time.Time)
  • 保留字段: updated_at (time.Time) - 用于记录最后更新时间
  • 影响范围: 仅影响 frontend_backend_routes

📊 预期效果

1. 数据库优化:

  • 减少不必要的 created_at 字段存储
  • 简化表结构,提高查询效率
  • 保持 updated_at 字段用于审计追踪

2. API路径完整性:

  • 所有保存到 frontend_backend_routes 表的 backend_route 字段现在包含完整的API URL
  • 格式示例:http://localhost:8080/api/auth/permissions
  • 支持不同环境的配置(开发、生产、测试)

3. 配置灵活性:

  • 支持用户自定义API服务器地址
  • 自动适配不同环境的配置
  • 确保前后端API路径的一致性

🚀 部署说明

  1. 数据库迁移: 应用启动时会自动执行字段删除操作
  2. 前端同步: 下次执行前台路由同步时,会使用新的完整URL格式
  3. 向后兼容: 现有的路由映射数据不会受到影响,新同步的数据会使用新格式

🔍 验证方法

  1. 检查数据库: 确认 frontend_backend_routes 表的 created_at 字段已被删除
  2. 检查API路径: 确认新同步的路由映射包含完整的API基础URL
  3. 检查配置: 确认不同环境下的API URL配置正确