diff --git a/gofaster/app/dist/renderer/js/index.js b/gofaster/app/dist/renderer/js/index.js index 206be66..ca787b5 100644 --- a/gofaster/app/dist/renderer/js/index.js +++ b/gofaster/app/dist/renderer/js/index.js @@ -13819,10 +13819,12 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ RouteCollector: () => (/* binding */ RouteCollector) /* harmony export */ }); -/* harmony import */ var _generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./generated-route-mapping.js */ "./src/renderer/modules/route-sync/generated-route-mapping.js"); +Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()); +/* harmony import */ var _RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./RouteConfig.js */ "./src/renderer/modules/route-sync/RouteConfig.js"); // 路由收集器 - 收集前端路由信息 + // 路由收集器 class RouteCollector { constructor() { @@ -13833,16 +13835,16 @@ class RouteCollector { collectRoutes() { try { // 从生成的路由映射文件收集 - if (!_generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_0__.mainRoutes || !Array.isArray(_generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_0__.mainRoutes)) { + if (!Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()) || !Array.isArray(Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()))) { console.warn('⚠️ 生成的路由映射文件格式不正确') return [] } // 转换为主入口路由格式 - const frontendRoutes = _generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_0__.mainRoutes.map(route => { + const frontendRoutes = Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()).map(route => { // 确保模块信息正确 if (!route.module) { - route.module = this._extractModuleFromPath(route.path) + route.module = _RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__.RouteUtils.extractModuleFromPath(route.path) } return { @@ -13862,28 +13864,6 @@ class RouteCollector { } } - // 从路径提取模块名 - _extractModuleFromPath(path) { - if (path === '/' || path === '') return 'home' - - const segments = path.split('/').filter(Boolean) - if (segments.length === 0) return 'home' - - // 获取第一个段作为模块名 - const module = segments[0] - - // 映射模块名 - const moduleMap = { - 'user-management': 'user-management', - 'role-management': 'role-management', - 'settings': 'system-settings', - 'user-profile': 'user-management', - 'route-sync': 'route-sync' - } - - return moduleMap[module] || module - } - // 获取菜单路由 getMenuRoutes() { return this.routes.filter(route => route.name && route.name !== '') @@ -13911,6 +13891,139 @@ class RouteCollector { } +/***/ }), + +/***/ "./src/renderer/modules/route-sync/RouteConfig.js": +/*!********************************************************!*\ + !*** ./src/renderer/modules/route-sync/RouteConfig.js ***! + \********************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ RouteConfig: () => (/* binding */ RouteConfig), +/* harmony export */ RouteUtils: () => (/* binding */ RouteUtils) +/* harmony export */ }); +// 路由配置和映射 - 统一管理所有路由相关的配置 +const RouteConfig = { + // 路由描述映射 + descriptions: { + 'home': '首页', + 'user-management': '用户管理', + 'role-management': '角色管理', + 'system-settings': '系统设置', + 'route-sync': '路由同步测试' + }, + + // 路由类型映射 + typeMap: { + 'user-management': 'list', + 'role-management': 'list', + 'system-settings': 'form', + 'route-sync': 'test' + }, + + // 排序值映射 + sortMap: { + 'home': 1, + 'user-management': 10, + 'role-management': 20, + 'system-settings': 30, + 'route-sync': 100 + } +} + +// 路由工具类 +class RouteUtils { + // 从路径提取模块名 + static extractModuleFromPath(path) { + if (path === '/' || path === '') { + return 'core' + } + + const segments = path.split('/').filter(Boolean) + if (segments.length === 0) { + return 'core' + } + + const firstPart = segments[0] + return firstPart + } + + // 生成路由描述 + static generateDescription(name, module) { + return RouteConfig.descriptions[module] || `${name}页面` + } + + // 确定路由类型 + static determineRouteType(path, module) { + if (path === '/' || path === '') return 'home' + return RouteConfig.typeMap[module] || 'list' + } + + // 生成排序值 + static generateSort(module) { + return RouteConfig.sortMap[module] || 50 + } + + // 提取路由名称 + static extractRouteName(path) { + if (path === '/' || path === '') return 'Home' + + const segments = path.split('/').filter(Boolean) + if (segments.length === 0) return 'Home' + + const lastSegment = segments[segments.length - 1] + return lastSegment.charAt(0).toUpperCase() + lastSegment.slice(1) + } + + // 生成组件名称 + static generateComponent(path, module) { + if (path === '/' || path === '') return 'Home' + + const segments = path.split('/').filter(Boolean) + if (segments.length === 0) return 'Home' + + const lastSegment = segments[segments.length - 1] + const componentName = lastSegment.charAt(0).toUpperCase() + lastSegment.slice(1) + + // 特殊处理某些路径 + if (path === '/route-sync') { + return 'RouteSync' + } + + return componentName + } + + // 验证映射 + static validateMapping(mapping, index) { + const errors = [] + + if (!mapping.frontend_route) { + errors.push(`映射 ${index}: 缺少前端路由`) + } + + if (!mapping.backend_route) { + errors.push(`映射 ${index}: 缺少后端路由`) + } + + if (!mapping.http_method) { + errors.push(`映射 ${index}: 缺少HTTP方法`) + } + + if (!mapping.module) { + errors.push(`映射 ${index}: 缺少模块信息`) + } + + return { + isValid: errors.length === 0, + errors: errors + } + } +} + + /***/ }), /***/ "./src/renderer/modules/route-sync/RouteMapper.js": @@ -13924,52 +14037,15 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ RouteMapper: () => (/* binding */ RouteMapper) /* harmony export */ }); -/* harmony import */ var _RouteUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./RouteUtils.js */ "./src/renderer/modules/route-sync/RouteUtils.js"); -/* harmony import */ var _generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./generated-route-mapping.js */ "./src/renderer/modules/route-sync/generated-route-mapping.js"); +/* harmony import */ var _RouteConfig_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./RouteConfig.js */ "./src/renderer/modules/route-sync/RouteConfig.js"); +Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()); // 路由映射器 - 将前端路由映射到后端API class RouteMapper { constructor() { - this.defaultApiMappings = { - 'user-management': { - basePath: '/auth/admin/users', - operations: { - list: { path: '', method: 'GET' }, - create: { path: '', method: 'POST' }, - update: { path: '/:id', method: 'PUT' }, - delete: { path: '/:id', method: 'DELETE' }, - detail: { path: '/:id', method: 'GET' }, - getRoles: { path: '/roles', method: 'GET' } - } - }, - 'role-management': { - basePath: '/auth/roles', - operations: { - list: { path: '', method: 'GET' }, - create: { path: '', method: 'POST' }, - update: { path: '/:id', method: 'PUT' }, - delete: { path: '/:id', method: 'DELETE' }, - detail: { path: '/:id', method: 'GET' } - } - }, - 'system-settings': { - basePath: '/auth/settings', - operations: { - list: { path: '', method: 'GET' }, - update: { path: '', method: 'PUT' } - } - }, - 'route-sync': { - basePath: '/auth/route-sync', - operations: { - list: { path: '', method: 'GET' }, - test: { path: '/test', method: 'POST' }, - status: { path: '/status', method: 'GET' } - } - } - } + this.defaultApiMappings = _RouteConfig_js__WEBPACK_IMPORTED_MODULE_0__.RouteConfig.defaultApiMappings } // 生成路由映射 @@ -14044,25 +14120,45 @@ class RouteMapper { // 获取子路由映射 _getSubRouteMapping(routePath) { try { - return _generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_1__.subRouteMappings[routePath] || null + return Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())[routePath] || null } catch (error) { return null } } - // 获取模块的API配置 + // 获取模块的API配置 - 合并生成的文件和默认配置 _getApiConfigForModule(module) { + let apiConfig = null + // 首先尝试从生成的路由映射文件获取 try { - if (_generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_1__.moduleApiMappings && _generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_1__.moduleApiMappings[module]) { - return _generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_1__.moduleApiMappings[module] + if (Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()) && Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())[module]) { + apiConfig = { ...Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())[module] } } } catch (error) { // 如果获取失败,使用默认配置 } - // 使用默认配置 - return this.defaultApiMappings[module] + // 如果没有从生成文件获取到,使用默认配置 + if (!apiConfig) { + apiConfig = { ...this.defaultApiMappings[module] } + } else { + // 合并默认配置中的缺失操作 + const defaultConfig = this.defaultApiMappings[module] + if (defaultConfig && defaultConfig.operations) { + if (!apiConfig.operations) { + apiConfig.operations = {} + } + // 只添加生成文件中没有的操作 + Object.keys(defaultConfig.operations).forEach(operation => { + if (!apiConfig.operations[operation]) { + apiConfig.operations[operation] = defaultConfig.operations[operation] + } + }) + } + } + + return apiConfig } // 验证映射完整性 @@ -14070,17 +14166,9 @@ class RouteMapper { const errors = [] mappings.forEach((mapping, index) => { - if (!mapping.frontend_route) { - errors.push(`映射 ${index}: 缺少前端路由`) - } - if (!mapping.backend_route) { - errors.push(`映射 ${index}: 缺少后端路由`) - } - if (!mapping.http_method) { - errors.push(`映射 ${index}: 缺少HTTP方法`) - } - if (!mapping.module) { - errors.push(`映射 ${index}: 缺少模块信息`) + const validation = _RouteConfig_js__WEBPACK_IMPORTED_MODULE_0__.RouteUtils.validateMapping(mapping, index) + if (!validation.isValid) { + errors.push(...validation.errors) } }) @@ -14156,11 +14244,6 @@ class RouteSyncManager { await this.performInitialSync() } - // 注释掉定时同步,只执行一次初始同步 - // if (this.config.syncInterval > 0) { - // this.setupPeriodicSync() - // } - this.isInitialized = true } @@ -14196,90 +14279,6 @@ class RouteSyncManager { } } - // 重试同步 - async retrySync(attempt = 1) { - if (attempt > this.config.retryAttempts) { - console.error(`❌ 重试次数已达上限 (${this.config.retryAttempts})`) - return false - } - - try { - await new Promise(resolve => setTimeout(resolve, this.config.retryDelay)) - - const frontendRoutes = this.routeCollector.collectRoutes() - const routeMappings = this.routeMapper.generateRouteMappings(frontendRoutes) - const result = await this.routeSyncService.syncRoutes(routeMappings) - - if (result.success) { - return true - } else { - return await this.retrySync(attempt + 1) - } - } catch (error) { - console.error(`❌ 重试同步失败 (${attempt}/${this.config.retryAttempts}):`, error) - return await this.retrySync(attempt + 1) - } - } - - // 设置定时同步 - setupPeriodicSync() { - if (this.syncTimer) { - clearInterval(this.syncTimer) - } - - this.syncTimer = setInterval(async () => { - try { - const frontendRoutes = this.routeCollector.collectRoutes() - const routeMappings = this.routeMapper.generateRouteMappings(frontendRoutes) - await this.routeSyncService.syncRoutes(routeMappings) - } catch (error) { - console.error('❌ 定时路由同步失败:', error) - } - }, this.config.syncInterval) - } - - // 手动触发同步 - async manualSync() { - if (!this.isInitialized) { - console.error('❌ 路由同步管理器未初始化') - return false - } - - try { - const frontendRoutes = this.routeCollector.collectRoutes() - const routeMappings = this.routeMapper.generateRouteMappings(frontendRoutes) - const result = await this.routeSyncService.syncRoutes(routeMappings) - - return result.success - } catch (error) { - console.error('❌ 手动同步失败:', error) - return false - } - } - - // 获取同步状态 - getSyncStatus() { - return { - isInitialized: this.isInitialized, - hasSyncTimer: !!this.syncTimer, - syncInterval: this.config.syncInterval, - autoSync: this.config.autoSync - } - } - - // 更新配置 - updateConfig(newConfig) { - this.config = { - ...this.config, - ...newConfig - } - - // 如果修改了同步间隔,重新设置定时器 - if (newConfig.syncInterval !== undefined) { - this.setupPeriodicSync() - } - } - // 停止同步 stop() { if (this.syncTimer) { @@ -14313,9 +14312,11 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ RouteSyncService: () => (/* binding */ RouteSyncService) /* harmony export */ }); /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ "./node_modules/axios/lib/axios.js"); +/* harmony import */ var _RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./RouteConfig.js */ "./src/renderer/modules/route-sync/RouteConfig.js"); // 路由同步服务 - 负责与后端API通信并同步路由信息 + // 路由同步服务 class RouteSyncService { constructor(apiBaseUrl = 'http://localhost:8080') { @@ -14426,12 +14427,12 @@ class RouteSyncService { if (!frontendRouteGroups[frontendRoute]) { frontendRouteGroups[frontendRoute] = { path: frontendRoute, - name: this._extractRouteName(frontendRoute), - component: this._generateComponent(frontendRoute, module), + name: _RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__.RouteUtils.extractRouteName(frontendRoute), + component: _RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__.RouteUtils.generateComponent(frontendRoute, module), module: module, - description: this._generateDescription(frontendRoute, module), - sort: this._generateSort(frontendRoute, module), - type: this._determineRouteType(frontendRoute, module), + description: _RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__.RouteUtils.generateDescription(_RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__.RouteUtils.extractRouteName(frontendRoute), module), + sort: _RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__.RouteUtils.generateSort(module), + type: _RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__.RouteUtils.determineRouteType(frontendRoute, module), backend_routes: [] } } @@ -14455,79 +14456,6 @@ class RouteSyncService { return Object.values(frontendRouteGroups) } - // 提取路由名称 - _extractRouteName(path) { - if (path === '/' || path === '') return 'Home' - - const segments = path.split('/').filter(Boolean) - if (segments.length === 0) return 'Home' - - const lastSegment = segments[segments.length - 1] - return lastSegment.charAt(0).toUpperCase() + lastSegment.slice(1) - } - - // 生成描述 - _generateDescription(path, module) { - const descriptions = { - 'home': '首页', - 'user-management': '用户管理', - 'role-management': '角色管理', - 'system-settings': '系统设置', - 'route-sync': '路由同步测试' - } - - return descriptions[module] || `${this._extractRouteName(path)}页面` - } - - // 确定路由类型 - _determineRouteType(path, module) { - if (path === '/' || path === '') return 'home' - - const typeMap = { - 'user-management': 'list', - 'role-management': 'list', - 'system-settings': 'form', - 'route-sync': 'test' - } - - return typeMap[module] || 'list' - } - - // 生成组件名称 - _generateComponent(path, module) { - if (path === '/' || path === '') return 'Home' - - const segments = path.split('/').filter(Boolean) - if (segments.length === 0) return 'Home' - - const lastSegment = segments[segments.length - 1] - const componentName = lastSegment.charAt(0).toUpperCase() + lastSegment.slice(1) - - // 特殊处理某些路径 - if (path === '/route-sync') { - return 'RouteSync' - } - - return componentName - } - - // 生成排序值 - _generateSort(path, module) { - const sortMap = { - 'home': 1, - 'user-management': 10, - 'role-management': 20, - 'system-settings': 30, - 'route-sync': 100 - } - - return sortMap[module] || 50 - } - - // 手动触发同步 - async manualSync(routeMappings) { - return await this.syncRoutes(routeMappings) - } // 获取同步状态 getSyncStatus() { @@ -14539,248 +14467,6 @@ class RouteSyncService { } -/***/ }), - -/***/ "./src/renderer/modules/route-sync/RouteUtils.js": -/*!*******************************************************!*\ - !*** ./src/renderer/modules/route-sync/RouteUtils.js ***! - \*******************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ RouteUtils: () => (/* binding */ RouteUtils) -/* harmony export */ }); -/* harmony import */ var _generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./generated-route-mapping.js */ "./src/renderer/modules/route-sync/generated-route-mapping.js"); -// 路由工具类 - - -class RouteUtils { - // 从路径提取模块名 - static extractModuleFromPath(path) { - if (path === '/' || path === '') { - return 'core' - } - - const segments = path.split('/').filter(Boolean) - if (segments.length === 0) { - return 'core' - } - - // 获取第一个段作为模块名 - const firstPart = segments[0] - - // 映射模块名 - const moduleMap = { - 'user-management': 'user-management', - 'role-management': 'role-management', - 'settings': 'system-settings', - 'user-profile': 'user-management', - 'route-sync': 'route-sync' - } - - return moduleMap[firstPart] || firstPart - } - - // 加载生成的路由映射文件 - static loadGeneratedMapping() { - try { - // 直接返回导入的数据 - return Promise.resolve({ - mainRoutes: _generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_0__.mainRoutes, - moduleApiMappings: _generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_0__.moduleApiMappings, - subRouteMappings: _generated_route_mapping_js__WEBPACK_IMPORTED_MODULE_0__.subRouteMappings - }) - } catch (error) { - console.error('❌ 加载生成的路由映射文件失败:', error) - return Promise.resolve(null) - } - } - - // 验证映射 - static validateMapping(mapping, index) { - const errors = [] - - if (!mapping.frontend_route) { - errors.push(`映射 ${index}: 缺少前端路由`) - } - - if (!mapping.backend_route) { - errors.push(`映射 ${index}: 缺少后端路由`) - } - - if (!mapping.http_method) { - errors.push(`映射 ${index}: 缺少HTTP方法`) - } - - if (!mapping.module) { - errors.push(`映射 ${index}: 缺少模块信息`) - } - - return { - isValid: errors.length === 0, - errors: errors - } - } - - // 生成路由描述 - static generateDescription(name, module) { - const descriptions = { - 'home': '首页', - 'user-management': '用户管理', - 'role-management': '角色管理', - 'system-settings': '系统设置', - 'route-sync': '路由同步测试' - } - - return descriptions[module] || `${name}页面` - } - - // 确定路由类型 - static determineRouteType(path, module) { - if (path === '/' || path === '') return 'home' - - const typeMap = { - 'user-management': 'list', - 'role-management': 'list', - 'system-settings': 'form', - 'route-sync': 'test' - } - - return typeMap[module] || 'list' - } -} - - -/***/ }), - -/***/ "./src/renderer/modules/route-sync/generated-route-mapping.js": -/*!********************************************************************!*\ - !*** ./src/renderer/modules/route-sync/generated-route-mapping.js ***! - \********************************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__), -/* harmony export */ mainRoutes: () => (/* binding */ mainRoutes), -/* harmony export */ moduleApiMappings: () => (/* binding */ moduleApiMappings), -/* harmony export */ subRouteMappings: () => (/* binding */ subRouteMappings) -/* harmony export */ }); -// 自动生成的路由映射文件 -// 此文件由 route-mapping-plugin 在构建时生成 -// 请勿手动修改 - -const mainRoutes = [ - { - "path": "/", - "name": "Home", - "module": "home", - "description": "首页", - "type": "home" - }, - { - "path": "/user-management", - "name": "UserManagement", - "module": "user-management", - "description": "用户管理", - "type": "list" - }, - { - "path": "/settings", - "name": "Settings", - "module": "system-settings", - "description": "系统设置", - "type": "form" - }, - { - "path": "/user-profile", - "name": "UserProfile", - "module": "user-management", - "description": "用户管理", - "type": "list" - }, - { - "path": "/role-management", - "name": "RoleManagement", - "module": "role-management", - "description": "角色管理", - "type": "list" - }, - { - "path": "/route-sync", - "name": "RouteSyncTest", - "module": "route-sync", - "description": "路由同步测试", - "type": "test" - } -] - -// 模块到API映射配置 -const moduleApiMappings = { - 'user-management': { - basePath: '/auth/admin/users', - operations: { - list: { path: '', method: 'GET' }, - search: { path: '/search', method: 'POST' }, - filter: { path: '/filter', method: 'POST' }, - create: { path: '', method: 'POST' }, - update: { path: '/:id', method: 'PUT' }, - detail: { path: '/:id', method: 'GET' }, - delete: { path: '/:id', method: 'DELETE' }, - getRoles: { path: '/roles', method: 'GET' } - } - }, - 'role-management': { - basePath: '/auth/roles', - operations: { - list: { path: '', method: 'GET' }, - search: { path: '/search', method: 'POST' }, - filter: { path: '/filter', method: 'POST' }, - create: { path: '', method: 'POST' }, - update: { path: '/:id', method: 'PUT' }, - detail: { path: '/:id', method: 'GET' }, - delete: { path: '/:id', method: 'DELETE' } - } - }, - 'system-settings': { - basePath: '/auth/settings', - operations: { - list: { path: '', method: 'GET' }, - update: { path: '', method: 'PUT' } - } - }, - 'route-sync': { - basePath: '/auth/route-sync', - operations: { - list: { path: '', method: 'GET' }, - test: { path: '/test', method: 'POST' }, - status: { path: '/status', method: 'GET' } - } - } -} - -// 子路由到主路由的映射 -const subRouteMappings = { - '/user-management/create': { mainRoute: '/user-management', operation: 'create' }, - '/user-management/edit': { mainRoute: '/user-management', operation: 'update' }, - '/user-management/delete': { mainRoute: '/user-management', operation: 'delete' }, - '/user-management/detail': { mainRoute: '/user-management', operation: 'detail' }, - '/role-management/create': { mainRoute: '/role-management', operation: 'create' }, - '/role-management/edit': { mainRoute: '/role-management', operation: 'update' }, - '/role-management/delete': { mainRoute: '/role-management', operation: 'delete' }, - '/role-management/detail': { mainRoute: '/role-management', operation: 'detail' } -} - -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ - mainRoutes, - moduleApiMappings, - subRouteMappings -}); - - /***/ }), /***/ "./src/renderer/modules/route-sync/index.js": @@ -14793,15 +14479,18 @@ const subRouteMappings = { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ RouteCollector: () => (/* reexport safe */ _RouteCollector__WEBPACK_IMPORTED_MODULE_1__.RouteCollector), +/* harmony export */ RouteConfig: () => (/* reexport safe */ _RouteConfig__WEBPACK_IMPORTED_MODULE_4__.RouteConfig), /* harmony export */ RouteMapper: () => (/* reexport safe */ _RouteMapper__WEBPACK_IMPORTED_MODULE_2__.RouteMapper), /* harmony export */ RouteSyncManager: () => (/* reexport safe */ _RouteSyncManager__WEBPACK_IMPORTED_MODULE_3__.RouteSyncManager), /* harmony export */ RouteSyncService: () => (/* reexport safe */ _RouteSyncService__WEBPACK_IMPORTED_MODULE_0__.RouteSyncService), +/* harmony export */ RouteUtils: () => (/* reexport safe */ _RouteConfig__WEBPACK_IMPORTED_MODULE_4__.RouteUtils), /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /* harmony import */ var _RouteSyncService__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./RouteSyncService */ "./src/renderer/modules/route-sync/RouteSyncService.js"); /* harmony import */ var _RouteCollector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./RouteCollector */ "./src/renderer/modules/route-sync/RouteCollector.js"); /* harmony import */ var _RouteMapper__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./RouteMapper */ "./src/renderer/modules/route-sync/RouteMapper.js"); /* harmony import */ var _RouteSyncManager__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./RouteSyncManager */ "./src/renderer/modules/route-sync/RouteSyncManager.js"); +/* harmony import */ var _RouteConfig__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./RouteConfig */ "./src/renderer/modules/route-sync/RouteConfig.js"); // 路由同步模块 @@ -14810,6 +14499,7 @@ __webpack_require__.r(__webpack_exports__); + // 默认导出路由同步管理器 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_RouteSyncManager__WEBPACK_IMPORTED_MODULE_3__.RouteSyncManager); @@ -16131,7 +15821,7 @@ __webpack_require__.r(__webpack_exports__); /******/ /******/ /* webpack/runtime/getFullHash */ /******/ (() => { -/******/ __webpack_require__.h = () => ("78f195cd268ee251") +/******/ __webpack_require__.h = () => ("a79c70d541afd8fd") /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ diff --git a/gofaster/app/plugins/route-mapping-plugin.js b/gofaster/app/plugins/route-mapping-plugin.js index 056d0f7..2b569de 100644 --- a/gofaster/app/plugins/route-mapping-plugin.js +++ b/gofaster/app/plugins/route-mapping-plugin.js @@ -1,4 +1,5 @@ import { resolve } from 'path' +import { readFileSync, existsSync, readdirSync } from 'fs' import fs from 'fs' import * as parser from '@babel/parser' import traverse from '@babel/traverse' @@ -50,6 +51,49 @@ export function routeMappingPlugin() { throw error } }, + + // 从模块配置中读取模块名称(同步,基于AST解析 config.js) + readModuleNamesFromConfig() { + try { + const configPath = resolve(__dirname, '../src/renderer/modules/config.js') + if (!existsSync(configPath)) { + return [] + } + + const code = readFileSync(configPath, 'utf-8') + const ast = parser.parse(code, { sourceType: 'module' }) + const modules = [] + + traverse(ast, { + ExportNamedDeclaration(path) { + const decl = path.node.declaration + if (decl && decl.type === 'VariableDeclaration') { + decl.declarations.forEach(d => { + if ( + d.id && d.id.name === 'MODULE_CONFIG' && + d.init && d.init.type === 'ObjectExpression' + ) { + d.init.properties.forEach(prop => { + if (prop.type === 'ObjectProperty') { + if (prop.key.type === 'Identifier') { + modules.push(prop.key.name) + } else if (prop.key.type === 'StringLiteral') { + modules.push(prop.key.value) + } + } + }) + } + }) + } + } + }) + + return modules + } catch (e) { + console.warn('⚠️ 读取 MODULE_CONFIG 失败,使用默认模块集合: ', e.message) + return [] + } + }, // 分析路由AST analyzeRouterAST() { @@ -441,14 +485,17 @@ export function routeMappingPlugin() { // 查找组件文件 findComponentFiles() { const componentFiles = [] - const moduleDirs = ['user-management', 'role-management', 'system-settings'] - + let moduleDirs = this.readModuleNamesFromConfig() + if (!moduleDirs || moduleDirs.length === 0) { + throw new Error('未能从 MODULE_CONFIG 读取到任何模块,请检查 app/src/renderer/modules/config.js 中的 MODULE_CONFIG 配置') + } + moduleDirs.forEach(moduleName => { const viewsPath = resolve(__dirname, `../src/renderer/modules/${moduleName}/views`) const componentsPath = resolve(__dirname, `../src/renderer/modules/${moduleName}/components`) - - if (fs.existsSync(viewsPath)) { - const files = fs.readdirSync(viewsPath).filter(f => f.endsWith('.vue')) + + if (existsSync(viewsPath)) { + const files = readdirSync(viewsPath).filter(f => f.endsWith('.vue')) files.forEach(file => { componentFiles.push({ name: file.replace('.vue', ''), @@ -458,9 +505,9 @@ export function routeMappingPlugin() { }) }) } - - if (fs.existsSync(componentsPath)) { - const files = fs.readdirSync(componentsPath).filter(f => f.endsWith('.vue')) + + if (existsSync(componentsPath)) { + const files = readdirSync(componentsPath).filter(f => f.endsWith('.vue')) files.forEach(file => { componentFiles.push({ name: file.replace('.vue', ''), @@ -471,19 +518,22 @@ export function routeMappingPlugin() { }) } }) - + return componentFiles }, // 查找服务文件 findServiceFiles() { const serviceFiles = [] - const moduleDirs = ['user-management', 'role-management', 'system-settings'] - + let moduleDirs = this.readModuleNamesFromConfig() + if (!moduleDirs || moduleDirs.length === 0) { + throw new Error('未能从 MODULE_CONFIG 读取到任何模块,请检查 app/src/renderer/modules/config.js 中的 MODULE_CONFIG 配置') + } + moduleDirs.forEach(moduleName => { const servicesPath = resolve(__dirname, `../src/renderer/modules/${moduleName}/services`) - if (fs.existsSync(servicesPath)) { - const files = fs.readdirSync(servicesPath).filter(f => f.endsWith('.js')) + if (existsSync(servicesPath)) { + const files = readdirSync(servicesPath).filter(f => f.endsWith('.js')) files.forEach(file => { serviceFiles.push({ name: file.replace('.js', ''), @@ -493,7 +543,7 @@ export function routeMappingPlugin() { }) } }) - + return serviceFiles }, diff --git a/gofaster/app/src/renderer/modules/config.js b/gofaster/app/src/renderer/modules/config.js index 3eda182..026cbaf 100644 --- a/gofaster/app/src/renderer/modules/config.js +++ b/gofaster/app/src/renderer/modules/config.js @@ -28,7 +28,14 @@ export const MODULE_CONFIG = { priority: 3 }, - + // 角色管理模块配置 + 'role-management': { + name: 'Role Management', + description: '角色管理功能模块', + version: '1.0.0', + dependencies: ['core'], + priority: 4 + } } // 获取模块配置 diff --git a/gofaster/app/src/renderer/modules/route-sync/RouteCollector.js b/gofaster/app/src/renderer/modules/route-sync/RouteCollector.js index 0f1ffba..9460403 100644 --- a/gofaster/app/src/renderer/modules/route-sync/RouteCollector.js +++ b/gofaster/app/src/renderer/modules/route-sync/RouteCollector.js @@ -1,5 +1,6 @@ // 路由收集器 - 收集前端路由信息 import { mainRoutes } from './generated-route-mapping.js' +import { RouteUtils } from './RouteConfig.js' // 路由收集器 export class RouteCollector { @@ -20,7 +21,7 @@ export class RouteCollector { const frontendRoutes = mainRoutes.map(route => { // 确保模块信息正确 if (!route.module) { - route.module = this._extractModuleFromPath(route.path) + route.module = RouteUtils.extractModuleFromPath(route.path) } return { @@ -40,28 +41,6 @@ export class RouteCollector { } } - // 从路径提取模块名 - _extractModuleFromPath(path) { - if (path === '/' || path === '') return 'home' - - const segments = path.split('/').filter(Boolean) - if (segments.length === 0) return 'home' - - // 获取第一个段作为模块名 - const module = segments[0] - - // 映射模块名 - const moduleMap = { - 'user-management': 'user-management', - 'role-management': 'role-management', - 'settings': 'system-settings', - 'user-profile': 'user-management', - 'route-sync': 'route-sync' - } - - return moduleMap[module] || module - } - // 获取菜单路由 getMenuRoutes() { return this.routes.filter(route => route.name && route.name !== '') diff --git a/gofaster/app/src/renderer/modules/route-sync/RouteConfig.js b/gofaster/app/src/renderer/modules/route-sync/RouteConfig.js new file mode 100644 index 0000000..193d401 --- /dev/null +++ b/gofaster/app/src/renderer/modules/route-sync/RouteConfig.js @@ -0,0 +1,117 @@ +// 路由配置和映射 - 统一管理所有路由相关的配置 +export const RouteConfig = { + // 路由描述映射 + descriptions: { + 'home': '首页', + 'user-management': '用户管理', + 'role-management': '角色管理', + 'system-settings': '系统设置', + 'route-sync': '路由同步测试' + }, + + // 路由类型映射 + typeMap: { + 'user-management': 'list', + 'role-management': 'list', + 'system-settings': 'form', + 'route-sync': 'test' + }, + + // 排序值映射 + sortMap: { + 'home': 1, + 'user-management': 10, + 'role-management': 20, + 'system-settings': 30, + 'route-sync': 100 + } +} + +// 路由工具类 +export class RouteUtils { + // 从路径提取模块名 + static extractModuleFromPath(path) { + if (path === '/' || path === '') { + return 'core' + } + + const segments = path.split('/').filter(Boolean) + if (segments.length === 0) { + return 'core' + } + + const firstPart = segments[0] + return firstPart + } + + // 生成路由描述 + static generateDescription(name, module) { + return RouteConfig.descriptions[module] || `${name}页面` + } + + // 确定路由类型 + static determineRouteType(path, module) { + if (path === '/' || path === '') return 'home' + return RouteConfig.typeMap[module] || 'list' + } + + // 生成排序值 + static generateSort(module) { + return RouteConfig.sortMap[module] || 50 + } + + // 提取路由名称 + static extractRouteName(path) { + if (path === '/' || path === '') return 'Home' + + const segments = path.split('/').filter(Boolean) + if (segments.length === 0) return 'Home' + + const lastSegment = segments[segments.length - 1] + return lastSegment.charAt(0).toUpperCase() + lastSegment.slice(1) + } + + // 生成组件名称 + static generateComponent(path, module) { + if (path === '/' || path === '') return 'Home' + + const segments = path.split('/').filter(Boolean) + if (segments.length === 0) return 'Home' + + const lastSegment = segments[segments.length - 1] + const componentName = lastSegment.charAt(0).toUpperCase() + lastSegment.slice(1) + + // 特殊处理某些路径 + if (path === '/route-sync') { + return 'RouteSync' + } + + return componentName + } + + // 验证映射 + static validateMapping(mapping, index) { + const errors = [] + + if (!mapping.frontend_route) { + errors.push(`映射 ${index}: 缺少前端路由`) + } + + if (!mapping.backend_route) { + errors.push(`映射 ${index}: 缺少后端路由`) + } + + if (!mapping.http_method) { + errors.push(`映射 ${index}: 缺少HTTP方法`) + } + + if (!mapping.module) { + errors.push(`映射 ${index}: 缺少模块信息`) + } + + return { + isValid: errors.length === 0, + errors: errors + } + } +} diff --git a/gofaster/app/src/renderer/modules/route-sync/RouteMapper.js b/gofaster/app/src/renderer/modules/route-sync/RouteMapper.js index 3b33293..a137ef3 100644 --- a/gofaster/app/src/renderer/modules/route-sync/RouteMapper.js +++ b/gofaster/app/src/renderer/modules/route-sync/RouteMapper.js @@ -1,47 +1,10 @@ // 路由映射器 - 将前端路由映射到后端API -import { RouteUtils } from './RouteUtils.js' +import { RouteUtils, RouteConfig } from './RouteConfig.js' import { subRouteMappings, moduleApiMappings } from './generated-route-mapping.js' export class RouteMapper { constructor() { - this.defaultApiMappings = { - 'user-management': { - basePath: '/auth/admin/users', - operations: { - list: { path: '', method: 'GET' }, - create: { path: '', method: 'POST' }, - update: { path: '/:id', method: 'PUT' }, - delete: { path: '/:id', method: 'DELETE' }, - detail: { path: '/:id', method: 'GET' }, - getRoles: { path: '/roles', method: 'GET' } - } - }, - 'role-management': { - basePath: '/auth/roles', - operations: { - list: { path: '', method: 'GET' }, - create: { path: '', method: 'POST' }, - update: { path: '/:id', method: 'PUT' }, - delete: { path: '/:id', method: 'DELETE' }, - detail: { path: '/:id', method: 'GET' } - } - }, - 'system-settings': { - basePath: '/auth/settings', - operations: { - list: { path: '', method: 'GET' }, - update: { path: '', method: 'PUT' } - } - }, - 'route-sync': { - basePath: '/auth/route-sync', - operations: { - list: { path: '', method: 'GET' }, - test: { path: '/test', method: 'POST' }, - status: { path: '/status', method: 'GET' } - } - } - } + this.defaultApiMappings = RouteConfig.defaultApiMappings } // 生成路由映射 @@ -122,19 +85,39 @@ export class RouteMapper { } } - // 获取模块的API配置 + // 获取模块的API配置 - 合并生成的文件和默认配置 _getApiConfigForModule(module) { + let apiConfig = null + // 首先尝试从生成的路由映射文件获取 try { if (moduleApiMappings && moduleApiMappings[module]) { - return moduleApiMappings[module] + apiConfig = { ...moduleApiMappings[module] } } } catch (error) { // 如果获取失败,使用默认配置 } - // 使用默认配置 - return this.defaultApiMappings[module] + // 如果没有从生成文件获取到,使用默认配置 + if (!apiConfig) { + apiConfig = { ...this.defaultApiMappings[module] } + } else { + // 合并默认配置中的缺失操作 + const defaultConfig = this.defaultApiMappings[module] + if (defaultConfig && defaultConfig.operations) { + if (!apiConfig.operations) { + apiConfig.operations = {} + } + // 只添加生成文件中没有的操作 + Object.keys(defaultConfig.operations).forEach(operation => { + if (!apiConfig.operations[operation]) { + apiConfig.operations[operation] = defaultConfig.operations[operation] + } + }) + } + } + + return apiConfig } // 验证映射完整性 @@ -142,17 +125,9 @@ export class RouteMapper { const errors = [] mappings.forEach((mapping, index) => { - if (!mapping.frontend_route) { - errors.push(`映射 ${index}: 缺少前端路由`) - } - if (!mapping.backend_route) { - errors.push(`映射 ${index}: 缺少后端路由`) - } - if (!mapping.http_method) { - errors.push(`映射 ${index}: 缺少HTTP方法`) - } - if (!mapping.module) { - errors.push(`映射 ${index}: 缺少模块信息`) + const validation = RouteUtils.validateMapping(mapping, index) + if (!validation.isValid) { + errors.push(...validation.errors) } }) diff --git a/gofaster/app/src/renderer/modules/route-sync/RouteSyncManager.js b/gofaster/app/src/renderer/modules/route-sync/RouteSyncManager.js index d7a532d..2dfba97 100644 --- a/gofaster/app/src/renderer/modules/route-sync/RouteSyncManager.js +++ b/gofaster/app/src/renderer/modules/route-sync/RouteSyncManager.js @@ -46,11 +46,6 @@ export class RouteSyncManager { await this.performInitialSync() } - // 注释掉定时同步,只执行一次初始同步 - // if (this.config.syncInterval > 0) { - // this.setupPeriodicSync() - // } - this.isInitialized = true } @@ -86,90 +81,6 @@ export class RouteSyncManager { } } - // 重试同步 - async retrySync(attempt = 1) { - if (attempt > this.config.retryAttempts) { - console.error(`❌ 重试次数已达上限 (${this.config.retryAttempts})`) - return false - } - - try { - await new Promise(resolve => setTimeout(resolve, this.config.retryDelay)) - - const frontendRoutes = this.routeCollector.collectRoutes() - const routeMappings = this.routeMapper.generateRouteMappings(frontendRoutes) - const result = await this.routeSyncService.syncRoutes(routeMappings) - - if (result.success) { - return true - } else { - return await this.retrySync(attempt + 1) - } - } catch (error) { - console.error(`❌ 重试同步失败 (${attempt}/${this.config.retryAttempts}):`, error) - return await this.retrySync(attempt + 1) - } - } - - // 设置定时同步 - setupPeriodicSync() { - if (this.syncTimer) { - clearInterval(this.syncTimer) - } - - this.syncTimer = setInterval(async () => { - try { - const frontendRoutes = this.routeCollector.collectRoutes() - const routeMappings = this.routeMapper.generateRouteMappings(frontendRoutes) - await this.routeSyncService.syncRoutes(routeMappings) - } catch (error) { - console.error('❌ 定时路由同步失败:', error) - } - }, this.config.syncInterval) - } - - // 手动触发同步 - async manualSync() { - if (!this.isInitialized) { - console.error('❌ 路由同步管理器未初始化') - return false - } - - try { - const frontendRoutes = this.routeCollector.collectRoutes() - const routeMappings = this.routeMapper.generateRouteMappings(frontendRoutes) - const result = await this.routeSyncService.syncRoutes(routeMappings) - - return result.success - } catch (error) { - console.error('❌ 手动同步失败:', error) - return false - } - } - - // 获取同步状态 - getSyncStatus() { - return { - isInitialized: this.isInitialized, - hasSyncTimer: !!this.syncTimer, - syncInterval: this.config.syncInterval, - autoSync: this.config.autoSync - } - } - - // 更新配置 - updateConfig(newConfig) { - this.config = { - ...this.config, - ...newConfig - } - - // 如果修改了同步间隔,重新设置定时器 - if (newConfig.syncInterval !== undefined) { - this.setupPeriodicSync() - } - } - // 停止同步 stop() { if (this.syncTimer) { diff --git a/gofaster/app/src/renderer/modules/route-sync/RouteSyncService.js b/gofaster/app/src/renderer/modules/route-sync/RouteSyncService.js index 9062e3f..68f4757 100644 --- a/gofaster/app/src/renderer/modules/route-sync/RouteSyncService.js +++ b/gofaster/app/src/renderer/modules/route-sync/RouteSyncService.js @@ -1,5 +1,6 @@ // 路由同步服务 - 负责与后端API通信并同步路由信息 import axios from 'axios' +import { RouteUtils } from './RouteConfig.js' // 路由同步服务 export class RouteSyncService { @@ -111,12 +112,12 @@ export class RouteSyncService { if (!frontendRouteGroups[frontendRoute]) { frontendRouteGroups[frontendRoute] = { path: frontendRoute, - name: this._extractRouteName(frontendRoute), - component: this._generateComponent(frontendRoute, module), + name: RouteUtils.extractRouteName(frontendRoute), + component: RouteUtils.generateComponent(frontendRoute, module), module: module, - description: this._generateDescription(frontendRoute, module), - sort: this._generateSort(frontendRoute, module), - type: this._determineRouteType(frontendRoute, module), + description: RouteUtils.generateDescription(RouteUtils.extractRouteName(frontendRoute), module), + sort: RouteUtils.generateSort(module), + type: RouteUtils.determineRouteType(frontendRoute, module), backend_routes: [] } } @@ -140,79 +141,6 @@ export class RouteSyncService { return Object.values(frontendRouteGroups) } - // 提取路由名称 - _extractRouteName(path) { - if (path === '/' || path === '') return 'Home' - - const segments = path.split('/').filter(Boolean) - if (segments.length === 0) return 'Home' - - const lastSegment = segments[segments.length - 1] - return lastSegment.charAt(0).toUpperCase() + lastSegment.slice(1) - } - - // 生成描述 - _generateDescription(path, module) { - const descriptions = { - 'home': '首页', - 'user-management': '用户管理', - 'role-management': '角色管理', - 'system-settings': '系统设置', - 'route-sync': '路由同步测试' - } - - return descriptions[module] || `${this._extractRouteName(path)}页面` - } - - // 确定路由类型 - _determineRouteType(path, module) { - if (path === '/' || path === '') return 'home' - - const typeMap = { - 'user-management': 'list', - 'role-management': 'list', - 'system-settings': 'form', - 'route-sync': 'test' - } - - return typeMap[module] || 'list' - } - - // 生成组件名称 - _generateComponent(path, module) { - if (path === '/' || path === '') return 'Home' - - const segments = path.split('/').filter(Boolean) - if (segments.length === 0) return 'Home' - - const lastSegment = segments[segments.length - 1] - const componentName = lastSegment.charAt(0).toUpperCase() + lastSegment.slice(1) - - // 特殊处理某些路径 - if (path === '/route-sync') { - return 'RouteSync' - } - - return componentName - } - - // 生成排序值 - _generateSort(path, module) { - const sortMap = { - 'home': 1, - 'user-management': 10, - 'role-management': 20, - 'system-settings': 30, - 'route-sync': 100 - } - - return sortMap[module] || 50 - } - - // 手动触发同步 - async manualSync(routeMappings) { - return await this.syncRoutes(routeMappings) - } // 获取同步状态 getSyncStatus() { diff --git a/gofaster/app/src/renderer/modules/route-sync/RouteUtils.js b/gofaster/app/src/renderer/modules/route-sync/RouteUtils.js deleted file mode 100644 index 1b8d975..0000000 --- a/gofaster/app/src/renderer/modules/route-sync/RouteUtils.js +++ /dev/null @@ -1,98 +0,0 @@ -// 路由工具类 -import { mainRoutes, moduleApiMappings, subRouteMappings } from './generated-route-mapping.js' - -export class RouteUtils { - // 从路径提取模块名 - static extractModuleFromPath(path) { - if (path === '/' || path === '') { - return 'core' - } - - const segments = path.split('/').filter(Boolean) - if (segments.length === 0) { - return 'core' - } - - // 获取第一个段作为模块名 - const firstPart = segments[0] - - // 映射模块名 - const moduleMap = { - 'user-management': 'user-management', - 'role-management': 'role-management', - 'settings': 'system-settings', - 'user-profile': 'user-management', - 'route-sync': 'route-sync' - } - - return moduleMap[firstPart] || firstPart - } - - // 加载生成的路由映射文件 - static loadGeneratedMapping() { - try { - // 直接返回导入的数据 - return Promise.resolve({ - mainRoutes, - moduleApiMappings, - subRouteMappings - }) - } catch (error) { - console.error('❌ 加载生成的路由映射文件失败:', error) - return Promise.resolve(null) - } - } - - // 验证映射 - static validateMapping(mapping, index) { - const errors = [] - - if (!mapping.frontend_route) { - errors.push(`映射 ${index}: 缺少前端路由`) - } - - if (!mapping.backend_route) { - errors.push(`映射 ${index}: 缺少后端路由`) - } - - if (!mapping.http_method) { - errors.push(`映射 ${index}: 缺少HTTP方法`) - } - - if (!mapping.module) { - errors.push(`映射 ${index}: 缺少模块信息`) - } - - return { - isValid: errors.length === 0, - errors: errors - } - } - - // 生成路由描述 - static generateDescription(name, module) { - const descriptions = { - 'home': '首页', - 'user-management': '用户管理', - 'role-management': '角色管理', - 'system-settings': '系统设置', - 'route-sync': '路由同步测试' - } - - return descriptions[module] || `${name}页面` - } - - // 确定路由类型 - static determineRouteType(path, module) { - if (path === '/' || path === '') return 'home' - - const typeMap = { - 'user-management': 'list', - 'role-management': 'list', - 'system-settings': 'form', - 'route-sync': 'test' - } - - return typeMap[module] || 'list' - } -} diff --git a/gofaster/app/src/renderer/modules/route-sync/generated-route-mapping.js b/gofaster/app/src/renderer/modules/route-sync/generated-route-mapping.js deleted file mode 100644 index e324f7c..0000000 --- a/gofaster/app/src/renderer/modules/route-sync/generated-route-mapping.js +++ /dev/null @@ -1,110 +0,0 @@ -// 自动生成的路由映射文件 -// 此文件由 route-mapping-plugin 在构建时生成 -// 请勿手动修改 - -export const mainRoutes = [ - { - "path": "/", - "name": "Home", - "module": "home", - "description": "首页", - "type": "home" - }, - { - "path": "/user-management", - "name": "UserManagement", - "module": "user-management", - "description": "用户管理", - "type": "list" - }, - { - "path": "/settings", - "name": "Settings", - "module": "system-settings", - "description": "系统设置", - "type": "form" - }, - { - "path": "/user-profile", - "name": "UserProfile", - "module": "user-management", - "description": "用户管理", - "type": "list" - }, - { - "path": "/role-management", - "name": "RoleManagement", - "module": "role-management", - "description": "角色管理", - "type": "list" - }, - { - "path": "/route-sync", - "name": "RouteSyncTest", - "module": "route-sync", - "description": "路由同步测试", - "type": "test" - } -] - -// 模块到API映射配置 -export const moduleApiMappings = { - 'user-management': { - basePath: '/auth/admin/users', - operations: { - list: { path: '', method: 'GET' }, - search: { path: '/search', method: 'POST' }, - filter: { path: '/filter', method: 'POST' }, - create: { path: '', method: 'POST' }, - update: { path: '/:id', method: 'PUT' }, - detail: { path: '/:id', method: 'GET' }, - delete: { path: '/:id', method: 'DELETE' }, - getRoles: { path: '/roles', method: 'GET' } - } - }, - 'role-management': { - basePath: '/auth/roles', - operations: { - list: { path: '', method: 'GET' }, - search: { path: '/search', method: 'POST' }, - filter: { path: '/filter', method: 'POST' }, - create: { path: '', method: 'POST' }, - update: { path: '/:id', method: 'PUT' }, - detail: { path: '/:id', method: 'GET' }, - delete: { path: '/:id', method: 'DELETE' } - } - }, - 'system-settings': { - basePath: '/auth/settings', - operations: { - list: { path: '', method: 'GET' }, - update: { path: '', method: 'PUT' } - } - }, - 'route-sync': { - basePath: '/auth/route-sync', - operations: { - list: { path: '', method: 'GET' }, - test: { path: '/test', method: 'POST' }, - status: { path: '/status', method: 'GET' } - } - } -} - -// 子路由到主路由的映射 -export const subRouteMappings = { - '/user-management/create': { mainRoute: '/user-management', operation: 'create' }, - '/user-management/edit': { mainRoute: '/user-management', operation: 'update' }, - '/user-management/delete': { mainRoute: '/user-management', operation: 'delete' }, - '/user-management/detail': { mainRoute: '/user-management', operation: 'detail' }, - '/role-management/create': { mainRoute: '/role-management', operation: 'create' }, - '/role-management/edit': { mainRoute: '/role-management', operation: 'update' }, - '/role-management/delete': { mainRoute: '/role-management', operation: 'delete' }, - '/role-management/detail': { mainRoute: '/role-management', operation: 'detail' } -} - -export default { - mainRoutes, - moduleApiMappings, - subRouteMappings -} diff --git a/gofaster/app/src/renderer/modules/route-sync/index.js b/gofaster/app/src/renderer/modules/route-sync/index.js index c4de446..32de559 100644 --- a/gofaster/app/src/renderer/modules/route-sync/index.js +++ b/gofaster/app/src/renderer/modules/route-sync/index.js @@ -3,8 +3,9 @@ import { RouteSyncService } from './RouteSyncService' import { RouteCollector } from './RouteCollector' import { RouteMapper } from './RouteMapper' import { RouteSyncManager } from './RouteSyncManager' +import { RouteUtils, RouteConfig } from './RouteConfig' -export { RouteSyncService, RouteCollector, RouteMapper, RouteSyncManager } +export { RouteSyncService, RouteCollector, RouteMapper, RouteSyncManager, RouteUtils, RouteConfig } // 默认导出路由同步管理器 export default RouteSyncManager diff --git a/win_text_editor/lib/modules/pdf_parse/controllers/pdf_parse_controller.dart b/win_text_editor/lib/modules/pdf_parse/controllers/pdf_parse_controller.dart index 35f3a1a..c9b1b11 100644 --- a/win_text_editor/lib/modules/pdf_parse/controllers/pdf_parse_controller.dart +++ b/win_text_editor/lib/modules/pdf_parse/controllers/pdf_parse_controller.dart @@ -409,6 +409,34 @@ class PdfParseController extends BaseContentController { return coordinate; } + // 调整宫位:增加180度(6个宫位) + String _adjustPalaceBy180Degrees(String palace) { + if (palace.isEmpty) return palace; + + const palaces = [ + '子', + '丑', + '寅', + '卯', + '辰', + '巳', + '午', + '未', + '申', + '酉', + '戌', + '亥', + ]; + + // 找到当前宫位的索引 + final currentIndex = palaces.indexOf(palace); + if (currentIndex == -1) return palace; + + // 增加6个宫位(180度) + final adjustedIndex = (currentIndex + 6) % 12; + return palaces[adjustedIndex]; + } + // 从度数计算宫位(地支) // 规则:每30度一个宫位,从"子"开始(0°对应子,30°对应丑,60°对应寅,...) String _extractPalaceFromDegrees(double degrees) { @@ -862,10 +890,12 @@ class PdfParseController extends BaseContentController { if (originalValue.isNotEmpty) { // 查找对应的宫位列(向左查找最近的宫位列) String palace = ''; + int palaceColIndex = -1; for (int palaceCol = col - 1; palaceCol >= 0; palaceCol--) { if (palaceCol < header.length && header[palaceCol].endsWith('宫')) { palace = row[palaceCol]; + palaceColIndex = palaceCol; break; } } @@ -883,6 +913,12 @@ class PdfParseController extends BaseContentController { header[col], ); row[col] = finalValue; + + // 如果当前列是"南"列,也需要修正对应的南宫宫位(增加180度,即6个宫位) + if (header[col] == '南' && palaceColIndex >= 0) { + final adjustedPalace = _adjustPalaceBy180Degrees(palace); + row[palaceColIndex] = adjustedPalace; + } } } } @@ -1153,10 +1189,7 @@ class PdfParseController extends BaseContentController { row.addAll(['', '', '', '', '']); // 会、半合、刑、合、冲 } - // 第一部分:计算"会"(度数的数值相同) - _calculateHui(); - - // 第二部分:计算所有相位关系(半合、刑、合、冲) + // 计算所有相位关系(会、半合、刑、合、冲) _calculateAllPhaseRelationships(); } @@ -1206,7 +1239,7 @@ class PdfParseController extends BaseContentController { } } - // 计算所有相位关系:半合、刑、合、冲 + // 计算所有相位关系:会、半合、刑、合、冲 void _calculateAllPhaseRelationships() { // 从度数坐标中提取度数和分钟的函数(忽略秒数) Map? extractDegreeAndMinutes(String coordinate) { @@ -1258,6 +1291,7 @@ class PdfParseController extends BaseContentController { } // 初始化各种相位关系的结果 + final huiResults = []; // 会 final banHeResults = []; // 半合 final xingResults = []; // 刑 final heResults = []; // 合 @@ -1304,7 +1338,15 @@ class PdfParseController extends BaseContentController { // 检查是否包含"水"星,决定误差范围 final containsWater = star1 == '水' || star2 == '水'; - final errorRange = containsWater ? 45 : 30; // 水星±45分,其他±30分 + final errorRange = containsWater ? 90 : 60; // 水星±45分,其他±30分 + + // 0. 会:两星相差60分(如果有水星参与则相差90分) + const huiTargetMinutes = 0; // 水星90分,其他60分 + final huiMin = huiTargetMinutes - errorRange; + final huiMax = huiTargetMinutes + errorRange; + if (diff >= huiMin && diff <= huiMax) { + huiResults.add('$star1$star2会($diffText)'); + } // 1. 半合:60度±误差范围 final banHeMin = (60 * 60) - errorRange; // 60度 - 误差(分钟) @@ -1320,11 +1362,10 @@ class PdfParseController extends BaseContentController { xingResults.add('$star1$star2刑($diffText)'); } - // 3. 合:相位差绝对值小于1度,或者 120度±误差范围 - // 小于1度 = 小于60分钟 + // 3. 合:120度±误差范围 final heMin = (120 * 60) - errorRange; // 120度 - 误差(分钟) final heMax = (120 * 60) + errorRange; // 120度 + 误差(分钟) - if (diff < 60 || (diff >= heMin && diff <= heMax)) { + if (diff >= heMin && diff <= heMax) { heResults.add('$star1$star2合($diffText)'); } @@ -1338,6 +1379,9 @@ class PdfParseController extends BaseContentController { } // 填写各种相位关系列 + if (huiResults.isNotEmpty) { + row[row.length - 5] = huiResults.join('; '); // 会列 + } if (banHeResults.isNotEmpty) { row[row.length - 4] = banHeResults.join('; '); // 半合列 } @@ -1353,79 +1397,6 @@ class PdfParseController extends BaseContentController { } } - // 计算"会":度数的数值相同就判定为"会" - void _calculateHui() { - // 从度数坐标中提取度数数值的函数 - int? extractDegreeValue(String coordinate) { - if (coordinate.isEmpty) return null; - - // 移除 R/D 标记和多余的引号 - String cleanedValue = coordinate.replaceAll(RegExp(r'[RD]'), ''); - cleanedValue = cleanedValue.replaceAll(RegExp(r'[""]+'), ''); - - // 匹配度数格式:15°30'45 或 15°30 - final match = RegExp(r"^(\d+)°").firstMatch(cleanedValue); - if (match != null) { - try { - return int.parse(match.group(1)!); - } catch (e) { - return null; - } - } - return null; - } - - // 遍历每一行数据 - for (int r = 1; r < _analyzedTable.length; r++) { - final row = _analyzedTable[r]; - - // 收集所有度数数值 - final degreeValues = >{}; // 度数 -> 星座列表 - - // 遍历所有列,找到数据列(非宫位列,非前4列,非关系列) - for (int col = 4; col < row.length - 5; col++) { - // 从第4列开始,减去5个关系列 - if (col < _analyzedTable[0].length && - !_analyzedTable[0][col].endsWith('宫')) { - final coordinate = row[col]; - if (coordinate.isNotEmpty) { - // 跳过"月亮"的"会"计算 - if (_analyzedTable[0][col] == '月') { - continue; - } - - final degreeValue = extractDegreeValue(coordinate); - if (degreeValue != null) { - degreeValues.putIfAbsent(degreeValue, () => []); - degreeValues[degreeValue]!.add(_analyzedTable[0][col]); // 添加星座名称 - } - } - } - } - - // 找出度数相同的星座组合("会") - final huiResults = []; - degreeValues.forEach((degree, stars) { - if (stars.length > 1) { - // 过滤掉南北两星的组合 - final filteredStars = - stars.where((star) => star != '南' && star != '北').toList(); - - // 如果过滤后仍有多个星座,则形成"会" - if (filteredStars.length > 1) { - // 格式:金土会(345°) - huiResults.add('${filteredStars.join("")}会(${degree}°)'); - } - } - }); - - // 填写"会"列(第一个关系列) - if (huiResults.isNotEmpty) { - row[row.length - 5] = huiResults.join('; '); - } - } - } - // 根据列索引获取星座名称 String _getStarNameFromColumnIndex(int colIndex) { // 前4列:Date, Time, Lat, Lon