Browse Source

前台路由调整根目录

master
hejl 2 days ago
parent
commit
21cc639003
  1. 16
      gofaster/app/dist/renderer/js/index.js
  2. 13
      gofaster/app/src/renderer/modules/route-sync/RouteMapper.js
  3. 91
      gofaster/backend/FRONTEND_ROUTE_SYNC_UPDATES.md
  4. 1
      gofaster/backend/internal/auth/model/frontend_backend_route.go

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

@ -14090,10 +14090,12 @@ __webpack_require__.r(__webpack_exports__); @@ -14090,10 +14090,12 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ });
/* harmony import */ var _RouteConfig_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./RouteConfig.js */ "./src/renderer/modules/route-sync/RouteConfig.js");
/* harmony import */ var _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./direct-route-mappings.js */ "./src/renderer/modules/route-sync/direct-route-mappings.js");
/* harmony import */ var _config_app_config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @/../config/app.config */ "./src/config/app.config.js");
// 路由映射器 - 将前端路由映射到后端API
class RouteMapper {
constructor() {
// 不再依赖硬编码的默认配置
@ -14142,9 +14144,13 @@ class RouteMapper { @@ -14142,9 +14144,13 @@ class RouteMapper {
// 如果是直接的API调用(type: 'api'),直接使用
if (apiCall.type === 'api' && apiCall.method && apiCall.path) {
// 获取完整的API基础URL
const config = (0,_config_app_config__WEBPACK_IMPORTED_MODULE_2__.getFinalConfig)()
const fullBackendRoute = `${config.apiBaseUrl}${apiCall.path}`
return {
frontend_route: route.path,
backend_route: apiCall.path,
backend_route: fullBackendRoute,
http_method: apiCall.method,
module: module,
operation: `${apiCall.method} ${apiCall.path}`,
@ -14181,9 +14187,13 @@ class RouteMapper { @@ -14181,9 +14187,13 @@ class RouteMapper {
return null
}
// 获取完整的API基础URL
const config = (0,_config_app_config__WEBPACK_IMPORTED_MODULE_2__.getFinalConfig)()
const fullBackendRoute = `${config.apiBaseUrl}${apiConfig.basePath}${operationConfig.path}`
return {
frontend_route: route.path,
backend_route: `${apiConfig.basePath}${operationConfig.path}`,
backend_route: fullBackendRoute,
http_method: operationConfig.method,
module: module,
operation: operation
@ -16362,7 +16372,7 @@ __webpack_require__.r(__webpack_exports__); @@ -16362,7 +16372,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("8b2021d89ca88b3d")
/******/ __webpack_require__.h = () => ("d2b659f3ff26a48f")
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */

13
gofaster/app/src/renderer/modules/route-sync/RouteMapper.js

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
// 路由映射器 - 将前端路由映射到后端API
import { RouteUtils, RouteConfig } from './RouteConfig.js'
import { directRouteMappings } from './direct-route-mappings.js'
import { getFinalConfig } from '@/../config/app.config'
export class RouteMapper {
constructor() {
@ -50,9 +51,13 @@ export class RouteMapper { @@ -50,9 +51,13 @@ export class RouteMapper {
// 如果是直接的API调用(type: 'api'),直接使用
if (apiCall.type === 'api' && apiCall.method && apiCall.path) {
// 获取完整的API基础URL
const config = getFinalConfig()
const fullBackendRoute = `${config.apiBaseUrl}${apiCall.path}`
return {
frontend_route: route.path,
backend_route: apiCall.path,
backend_route: fullBackendRoute,
http_method: apiCall.method,
module: module,
operation: `${apiCall.method} ${apiCall.path}`,
@ -89,9 +94,13 @@ export class RouteMapper { @@ -89,9 +94,13 @@ export class RouteMapper {
return null
}
// 获取完整的API基础URL
const config = getFinalConfig()
const fullBackendRoute = `${config.apiBaseUrl}${apiConfig.basePath}${operationConfig.path}`
return {
frontend_route: route.path,
backend_route: `${apiConfig.basePath}${operationConfig.path}`,
backend_route: fullBackendRoute,
http_method: operationConfig.method,
module: module,
operation: operation

91
gofaster/backend/FRONTEND_ROUTE_SYNC_UPDATES.md

@ -0,0 +1,91 @@ @@ -0,0 +1,91 @@
# 前台路由同步逻辑更新
## 📋 更新内容
### 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()` 函数中调用该函数
- 包含完整的表存在检查和字段存在检查
- 添加了详细的调试日志
#### 迁移逻辑:
```go
// 检查表是否存在
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()` 方法
#### 实现逻辑:
```javascript
// 获取完整的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配置正确

1
gofaster/backend/internal/auth/model/frontend_backend_route.go

@ -7,7 +7,6 @@ import ( @@ -7,7 +7,6 @@ import (
// FrontendBackendRoute 前后台路由关系模型
type FrontendBackendRoute struct {
ID uint `gorm:"primarykey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
FrontendRouteID uint `gorm:"uniqueIndex:idx_frontend_backend_routes_unique" json:"frontend_route_id"` // 前台路由ID
BackendRoute string `gorm:"uniqueIndex:idx_frontend_backend_routes_unique" json:"backend_route"` // 后台API路径

Loading…
Cancel
Save