Browse Source

路由同步

master
hejl 2 days ago
parent
commit
e7dcfaafae
  1. 676
      gofaster/app/dist/renderer/js/index.js
  2. 78
      gofaster/app/plugins/route-mapping-plugin.js
  3. 9
      gofaster/app/src/renderer/modules/config.js
  4. 25
      gofaster/app/src/renderer/modules/route-sync/RouteCollector.js
  5. 117
      gofaster/app/src/renderer/modules/route-sync/RouteConfig.js
  6. 83
      gofaster/app/src/renderer/modules/route-sync/RouteMapper.js
  7. 89
      gofaster/app/src/renderer/modules/route-sync/RouteSyncManager.js
  8. 84
      gofaster/app/src/renderer/modules/route-sync/RouteSyncService.js
  9. 98
      gofaster/app/src/renderer/modules/route-sync/RouteUtils.js
  10. 110
      gofaster/app/src/renderer/modules/route-sync/generated-route-mapping.js
  11. 3
      gofaster/app/src/renderer/modules/route-sync/index.js
  12. 135
      win_text_editor/lib/modules/pdf_parse/controllers/pdf_parse_controller.dart

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

@ -13819,10 +13819,12 @@ __webpack_require__.r(__webpack_exports__); @@ -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 { @@ -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 { @@ -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 { @@ -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__); @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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__); @@ -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 { @@ -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 { @@ -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 { @@ -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 = { @@ -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__); @@ -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__); @@ -16131,7 +15821,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("78f195cd268ee251")
/******/ __webpack_require__.h = () => ("a79c70d541afd8fd")
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */

78
gofaster/app/plugins/route-mapping-plugin.js

@ -1,4 +1,5 @@ @@ -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() { @@ -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() { @@ -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() { @@ -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() { @@ -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() { @@ -493,7 +543,7 @@ export function routeMappingPlugin() {
})
}
})
return serviceFiles
},

9
gofaster/app/src/renderer/modules/config.js

@ -28,7 +28,14 @@ export const MODULE_CONFIG = { @@ -28,7 +28,14 @@ export const MODULE_CONFIG = {
priority: 3
},
// 角色管理模块配置
'role-management': {
name: 'Role Management',
description: '角色管理功能模块',
version: '1.0.0',
dependencies: ['core'],
priority: 4
}
}
// 获取模块配置

25
gofaster/app/src/renderer/modules/route-sync/RouteCollector.js

@ -1,5 +1,6 @@ @@ -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 { @@ -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 { @@ -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 !== '')

117
gofaster/app/src/renderer/modules/route-sync/RouteConfig.js

@ -0,0 +1,117 @@ @@ -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
}
}
}

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

@ -1,47 +1,10 @@ @@ -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 { @@ -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 { @@ -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)
}
})

89
gofaster/app/src/renderer/modules/route-sync/RouteSyncManager.js

@ -46,11 +46,6 @@ export class RouteSyncManager { @@ -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 { @@ -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) {

84
gofaster/app/src/renderer/modules/route-sync/RouteSyncService.js

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
// 路由同步服务 - 负责与后端API通信并同步路由信息
import axios from 'axios'
import { RouteUtils } from './RouteConfig.js'
// 路由同步服务
export class RouteSyncService {
@ -111,12 +112,12 @@ 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 { @@ -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() {

98
gofaster/app/src/renderer/modules/route-sync/RouteUtils.js

@ -1,98 +0,0 @@ @@ -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'
}
}

110
gofaster/app/src/renderer/modules/route-sync/generated-route-mapping.js

@ -1,110 +0,0 @@ @@ -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
}

3
gofaster/app/src/renderer/modules/route-sync/index.js

@ -3,8 +3,9 @@ import { RouteSyncService } from './RouteSyncService' @@ -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

135
win_text_editor/lib/modules/pdf_parse/controllers/pdf_parse_controller.dart

@ -409,6 +409,34 @@ class PdfParseController extends BaseContentController { @@ -409,6 +409,34 @@ class PdfParseController extends BaseContentController {
return coordinate;
}
// 1806
String _adjustPalaceBy180Degrees(String palace) {
if (palace.isEmpty) return palace;
const palaces = [
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
];
//
final currentIndex = palaces.indexOf(palace);
if (currentIndex == -1) return palace;
// 6180
final adjustedIndex = (currentIndex + 6) % 12;
return palaces[adjustedIndex];
}
//
// 30""0°30°60°...
String _extractPalaceFromDegrees(double degrees) {
@ -862,10 +890,12 @@ class PdfParseController extends BaseContentController { @@ -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 { @@ -883,6 +913,12 @@ class PdfParseController extends BaseContentController {
header[col],
);
row[col] = finalValue;
// ""1806
if (header[col] == '' && palaceColIndex >= 0) {
final adjustedPalace = _adjustPalaceBy180Degrees(palace);
row[palaceColIndex] = adjustedPalace;
}
}
}
}
@ -1153,10 +1189,7 @@ class PdfParseController extends BaseContentController { @@ -1153,10 +1189,7 @@ class PdfParseController extends BaseContentController {
row.addAll(['', '', '', '', '']); //
}
// ""
_calculateHui();
//
//
_calculateAllPhaseRelationships();
}
@ -1206,7 +1239,7 @@ class PdfParseController extends BaseContentController { @@ -1206,7 +1239,7 @@ class PdfParseController extends BaseContentController {
}
}
//
//
void _calculateAllPhaseRelationships() {
//
Map<String, int>? extractDegreeAndMinutes(String coordinate) {
@ -1258,6 +1291,7 @@ class PdfParseController extends BaseContentController { @@ -1258,6 +1291,7 @@ class PdfParseController extends BaseContentController {
}
//
final huiResults = <String>[]; //
final banHeResults = <String>[]; //
final xingResults = <String>[]; //
final heResults = <String>[]; //
@ -1304,7 +1338,15 @@ class PdfParseController extends BaseContentController { @@ -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. 6090
const huiTargetMinutes = 0; // 9060
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 { @@ -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 { @@ -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 { @@ -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 = <int, List<String>>{}; // ->
// 4
for (int col = 4; col < row.length - 5; col++) {
// 45
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 = <String>[];
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) {
// 4Date, Time, Lat, Lon

Loading…
Cancel
Save