Browse Source

前台路由信息收集OK

master
hejl 3 days ago
parent
commit
bb1cadb1d0
  1. 137
      gofaster/app/dist/renderer/js/index.js
  2. 62
      gofaster/app/src/renderer/modules/route-sync/RouteCollector.js
  3. 69
      gofaster/app/src/renderer/modules/route-sync/RouteMapper.js
  4. 4
      gofaster/app/src/renderer/modules/route-sync/direct-route-mappings.js

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

@ -13840,28 +13840,32 @@ class RouteCollector {
console.log('📊 directRouteMappings是否为undefined:', _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings === undefined) console.log('📊 directRouteMappings是否为undefined:', _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings === undefined)
// 从生成的路由映射文件收集 // 从生成的路由映射文件收集
if (!_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings || !_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings.pageMappings) { if (!_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings || !_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings.routes) {
console.warn('⚠ 生成的路由映射文件格式不正确') console.warn('⚠ 生成的路由映射文件格式不正确')
console.log('🔍 调试信息:') console.log('🔍 调试信息:')
console.log(' - directRouteMappings:', _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings) console.log(' - directRouteMappings:', _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings)
console.log(' - pageMappings:', _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings?.pageMappings) console.log(' - routes:', _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings?.routes)
console.log(' - 导入是否成功:', _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings !== undefined) console.log(' - 导入是否成功:', _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings !== undefined)
return [] return []
} }
console.log(`📊 找到 ${_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings.pageMappings.length}页面映射`) console.log(`📊 找到 ${_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings.routes.length}路由配置`)
// 从页面映射中提取路由信息 // 从路由配置中提取路由信息,并关联API映射
const frontendRoutes = _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings.pageMappings.map(mapping => { const frontendRoutes = _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings.routes.map(route => {
console.log(`📋 处理页面映射: ${mapping.route} (${mapping.component})`) console.log(`📋 处理路由: ${route.path} (${route.component})`)
// 查找该路由对应的API调用
const apiCalls = this._findApiCallsForRoute(route)
return { return {
path: mapping.route, path: route.path,
name: mapping.routeName, name: route.name,
module: mapping.module, module: route.module,
description: `${mapping.routeName}页面`, description: route.description || `${route.name || route.component}页面`,
type: 'list', type: 'list',
component: mapping.component, component: route.component,
apiCalls: mapping.apiCalls apiCalls: apiCalls
} }
}) })
@ -13875,6 +13879,40 @@ class RouteCollector {
} }
} }
// 查找路由对应的API调用
_findApiCallsForRoute(route) {
const apiCalls = []
if (!_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings.apiMappings) {
return apiCalls
}
// 遍历API映射,找到与当前路由相关的调用
_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings.apiMappings.forEach(moduleMapping => {
if (moduleMapping.module === route.module) {
moduleMapping.apiMappings.forEach(apiMapping => {
// 检查API调用是否与当前路由相关
const isRelated = apiMapping.callingComponents.some(component =>
component.component === route.component ||
component.path === route.path
)
if (isRelated) {
apiCalls.push({
type: 'api',
method: apiMapping.method,
path: apiMapping.path,
methodName: apiMapping.methodName,
serviceName: moduleMapping.serviceName
})
}
})
}
})
return apiCalls
}
// 获取菜单路由 // 获取菜单路由
getMenuRoutes() { getMenuRoutes() {
return this.routes.filter(route => route.name && route.name !== '') return this.routes.filter(route => route.name && route.name !== '')
@ -14110,9 +14148,10 @@ class RouteMapper {
http_method: apiCall.method, http_method: apiCall.method,
module: module, module: module,
operation: `${apiCall.method} ${apiCall.path}`, operation: `${apiCall.method} ${apiCall.path}`,
service: 'direct', service: apiCall.serviceName || 'direct',
method: apiCall.method, method: apiCall.method,
path: apiCall.path path: apiCall.path,
methodName: apiCall.methodName
} }
} }
@ -14155,12 +14194,14 @@ class RouteMapper {
_getSubRouteMapping(routePath) { _getSubRouteMapping(routePath) {
try { try {
// 从新的直接映射文件中查找 // 从新的直接映射文件中查找
if (_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings && _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.pageMappings) { if (_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings && _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.routes) {
const pageMapping = _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.pageMappings.find(p => p.route === routePath) const route = _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.routes.find(r => r.path === routePath)
if (pageMapping && pageMapping.apiCalls) { if (route) {
// 查找该路由对应的API调用
const apiCalls = this._findApiCallsForRoute(route)
return { return {
route: routePath, route: routePath,
apiCalls: pageMapping.apiCalls apiCalls: apiCalls
} }
} }
} }
@ -14170,24 +14211,56 @@ class RouteMapper {
} }
} }
// 查找路由对应的API调用(与RouteCollector中的方法相同)
_findApiCallsForRoute(route) {
const apiCalls = []
if (!_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.apiMappings) {
return apiCalls
}
// 遍历API映射,找到与当前路由相关的调用
_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.apiMappings.forEach(moduleMapping => {
if (moduleMapping.module === route.module) {
moduleMapping.apiMappings.forEach(apiMapping => {
// 检查API调用是否与当前路由相关
const isRelated = apiMapping.callingComponents.some(component =>
component.component === route.component ||
component.path === route.path
)
if (isRelated) {
apiCalls.push({
type: 'api',
method: apiMapping.method,
path: apiMapping.path,
methodName: apiMapping.methodName,
serviceName: moduleMapping.serviceName
})
}
})
}
})
return apiCalls
}
// 获取模块的API配置 - 基于直接映射关系 // 获取模块的API配置 - 基于直接映射关系
_getApiConfigForModule(module) { _getApiConfigForModule(module) {
let apiConfig = null let apiConfig = null
// 从直接映射文件中获取API调用信息 // 从直接映射文件中获取API调用信息
try { try {
if (_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings && _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.pageMappings) { if (_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings && _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.apiMappings) {
const moduleMappings = _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.pageMappings.filter(p => p.module === module) const moduleMapping = _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.apiMappings.find(m => m.module === module)
if (moduleMappings.length > 0) { if (moduleMapping && moduleMapping.apiMappings) {
const operations = {} const operations = {}
moduleMappings.forEach(mapping => { moduleMapping.apiMappings.forEach(apiMapping => {
mapping.apiCalls.forEach(apiCall => { const operationKey = `${apiMapping.method}_${apiMapping.methodName}_${apiMapping.path}`
const operationKey = `${apiCall.type}_${apiCall.service || apiCall.method}_${apiCall.method || apiCall.path}` operations[operationKey] = {
operations[operationKey] = { path: apiMapping.path,
path: apiCall.path || `/${apiCall.service}/${apiCall.method}`, method: apiMapping.method
method: apiCall.method || 'GET' }
}
})
}) })
if (Object.keys(operations).length > 0) { if (Object.keys(operations).length > 0) {
@ -14630,7 +14703,7 @@ const directRouteMappings = {
{ {
"module": "user-management", "module": "user-management",
"serviceName": "userService", "serviceName": "userService",
"servicePath": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\services\\userService.js", "servicePath": "D:\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\services\\userService.js",
"apiMappings": [ "apiMappings": [
{ {
"methodName": "getUsers", "methodName": "getUsers",
@ -14769,7 +14842,7 @@ const directRouteMappings = {
{ {
"module": "role-management", "module": "role-management",
"serviceName": "roleService", "serviceName": "roleService",
"servicePath": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\role-management\\services\\roleService.js", "servicePath": "D:\\manta\\gofaster\\app\\src\\renderer\\modules\\role-management\\services\\roleService.js",
"apiMappings": [ "apiMappings": [
{ {
"methodName": "getRoles", "methodName": "getRoles",
@ -16289,7 +16362,7 @@ __webpack_require__.r(__webpack_exports__);
/******/ /******/
/******/ /* webpack/runtime/getFullHash */ /******/ /* webpack/runtime/getFullHash */
/******/ (() => { /******/ (() => {
/******/ __webpack_require__.h = () => ("26e8aeeb05d3a15a") /******/ __webpack_require__.h = () => ("8b2021d89ca88b3d")
/******/ })(); /******/ })();
/******/ /******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ /* webpack/runtime/hasOwnProperty shorthand */

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

@ -17,28 +17,32 @@ export class RouteCollector {
console.log('📊 directRouteMappings是否为undefined:', directRouteMappings === undefined) console.log('📊 directRouteMappings是否为undefined:', directRouteMappings === undefined)
// 从生成的路由映射文件收集 // 从生成的路由映射文件收集
if (!directRouteMappings || !directRouteMappings.pageMappings) { if (!directRouteMappings || !directRouteMappings.routes) {
console.warn('⚠ 生成的路由映射文件格式不正确') console.warn('⚠ 生成的路由映射文件格式不正确')
console.log('🔍 调试信息:') console.log('🔍 调试信息:')
console.log(' - directRouteMappings:', directRouteMappings) console.log(' - directRouteMappings:', directRouteMappings)
console.log(' - pageMappings:', directRouteMappings?.pageMappings) console.log(' - routes:', directRouteMappings?.routes)
console.log(' - 导入是否成功:', directRouteMappings !== undefined) console.log(' - 导入是否成功:', directRouteMappings !== undefined)
return [] return []
} }
console.log(`📊 找到 ${directRouteMappings.pageMappings.length}页面映射`) console.log(`📊 找到 ${directRouteMappings.routes.length}路由配置`)
// 从页面映射中提取路由信息 // 从路由配置中提取路由信息,并关联API映射
const frontendRoutes = directRouteMappings.pageMappings.map(mapping => { const frontendRoutes = directRouteMappings.routes.map(route => {
console.log(`📋 处理页面映射: ${mapping.route} (${mapping.component})`) console.log(`📋 处理路由: ${route.path} (${route.component})`)
// 查找该路由对应的API调用
const apiCalls = this._findApiCallsForRoute(route)
return { return {
path: mapping.route, path: route.path,
name: mapping.routeName, name: route.name,
module: mapping.module, module: route.module,
description: `${mapping.routeName}页面`, description: route.description || `${route.name || route.component}页面`,
type: 'list', type: 'list',
component: mapping.component, component: route.component,
apiCalls: mapping.apiCalls apiCalls: apiCalls
} }
}) })
@ -52,6 +56,40 @@ export class RouteCollector {
} }
} }
// 查找路由对应的API调用
_findApiCallsForRoute(route) {
const apiCalls = []
if (!directRouteMappings.apiMappings) {
return apiCalls
}
// 遍历API映射,找到与当前路由相关的调用
directRouteMappings.apiMappings.forEach(moduleMapping => {
if (moduleMapping.module === route.module) {
moduleMapping.apiMappings.forEach(apiMapping => {
// 检查API调用是否与当前路由相关
const isRelated = apiMapping.callingComponents.some(component =>
component.component === route.component ||
component.path === route.path
)
if (isRelated) {
apiCalls.push({
type: 'api',
method: apiMapping.method,
path: apiMapping.path,
methodName: apiMapping.methodName,
serviceName: moduleMapping.serviceName
})
}
})
}
})
return apiCalls
}
// 获取菜单路由 // 获取菜单路由
getMenuRoutes() { getMenuRoutes() {
return this.routes.filter(route => route.name && route.name !== '') return this.routes.filter(route => route.name && route.name !== '')

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

@ -56,9 +56,10 @@ export class RouteMapper {
http_method: apiCall.method, http_method: apiCall.method,
module: module, module: module,
operation: `${apiCall.method} ${apiCall.path}`, operation: `${apiCall.method} ${apiCall.path}`,
service: 'direct', service: apiCall.serviceName || 'direct',
method: apiCall.method, method: apiCall.method,
path: apiCall.path path: apiCall.path,
methodName: apiCall.methodName
} }
} }
@ -101,12 +102,14 @@ export class RouteMapper {
_getSubRouteMapping(routePath) { _getSubRouteMapping(routePath) {
try { try {
// 从新的直接映射文件中查找 // 从新的直接映射文件中查找
if (directRouteMappings && directRouteMappings.pageMappings) { if (directRouteMappings && directRouteMappings.routes) {
const pageMapping = directRouteMappings.pageMappings.find(p => p.route === routePath) const route = directRouteMappings.routes.find(r => r.path === routePath)
if (pageMapping && pageMapping.apiCalls) { if (route) {
// 查找该路由对应的API调用
const apiCalls = this._findApiCallsForRoute(route)
return { return {
route: routePath, route: routePath,
apiCalls: pageMapping.apiCalls apiCalls: apiCalls
} }
} }
} }
@ -116,24 +119,56 @@ export class RouteMapper {
} }
} }
// 查找路由对应的API调用(与RouteCollector中的方法相同)
_findApiCallsForRoute(route) {
const apiCalls = []
if (!directRouteMappings.apiMappings) {
return apiCalls
}
// 遍历API映射,找到与当前路由相关的调用
directRouteMappings.apiMappings.forEach(moduleMapping => {
if (moduleMapping.module === route.module) {
moduleMapping.apiMappings.forEach(apiMapping => {
// 检查API调用是否与当前路由相关
const isRelated = apiMapping.callingComponents.some(component =>
component.component === route.component ||
component.path === route.path
)
if (isRelated) {
apiCalls.push({
type: 'api',
method: apiMapping.method,
path: apiMapping.path,
methodName: apiMapping.methodName,
serviceName: moduleMapping.serviceName
})
}
})
}
})
return apiCalls
}
// 获取模块的API配置 - 基于直接映射关系 // 获取模块的API配置 - 基于直接映射关系
_getApiConfigForModule(module) { _getApiConfigForModule(module) {
let apiConfig = null let apiConfig = null
// 从直接映射文件中获取API调用信息 // 从直接映射文件中获取API调用信息
try { try {
if (directRouteMappings && directRouteMappings.pageMappings) { if (directRouteMappings && directRouteMappings.apiMappings) {
const moduleMappings = directRouteMappings.pageMappings.filter(p => p.module === module) const moduleMapping = directRouteMappings.apiMappings.find(m => m.module === module)
if (moduleMappings.length > 0) { if (moduleMapping && moduleMapping.apiMappings) {
const operations = {} const operations = {}
moduleMappings.forEach(mapping => { moduleMapping.apiMappings.forEach(apiMapping => {
mapping.apiCalls.forEach(apiCall => { const operationKey = `${apiMapping.method}_${apiMapping.methodName}_${apiMapping.path}`
const operationKey = `${apiCall.type}_${apiCall.service || apiCall.method}_${apiCall.method || apiCall.path}` operations[operationKey] = {
operations[operationKey] = { path: apiMapping.path,
path: apiCall.path || `/${apiCall.service}/${apiCall.method}`, method: apiMapping.method
method: apiCall.method || 'GET' }
}
})
}) })
if (Object.keys(operations).length > 0) { if (Object.keys(operations).length > 0) {

4
gofaster/app/src/renderer/modules/route-sync/direct-route-mappings.js

@ -47,7 +47,7 @@ export const directRouteMappings = {
{ {
"module": "user-management", "module": "user-management",
"serviceName": "userService", "serviceName": "userService",
"servicePath": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\services\\userService.js", "servicePath": "D:\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\services\\userService.js",
"apiMappings": [ "apiMappings": [
{ {
"methodName": "getUsers", "methodName": "getUsers",
@ -186,7 +186,7 @@ export const directRouteMappings = {
{ {
"module": "role-management", "module": "role-management",
"serviceName": "roleService", "serviceName": "roleService",
"servicePath": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\role-management\\services\\roleService.js", "servicePath": "D:\\manta\\gofaster\\app\\src\\renderer\\modules\\role-management\\services\\roleService.js",
"apiMappings": [ "apiMappings": [
{ {
"methodName": "getRoles", "methodName": "getRoles",

Loading…
Cancel
Save