Browse Source

能正常生成路由映射文件

master
hejl 3 days ago
parent
commit
8ed92aa21d
  1. 900
      gofaster/app/dist/renderer/js/index.js
  2. 11
      gofaster/app/package.json
  3. 911
      gofaster/app/plugins/route-mapping-plugin.js
  4. 14
      gofaster/app/scripts/generate-route-mappings.js
  5. 25
      gofaster/app/src/renderer/modules/route-sync/RouteCollector.js
  6. 59
      gofaster/app/src/renderer/modules/route-sync/RouteMapper.js
  7. 4
      gofaster/app/vue.config.js

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

@ -13819,7 +13819,7 @@ __webpack_require__.r(__webpack_exports__); @@ -13819,7 +13819,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ RouteCollector: () => (/* binding */ RouteCollector)
/* harmony export */ });
Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }());
/* harmony import */ var _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./direct-route-mappings.js */ "./src/renderer/modules/route-sync/direct-route-mappings.js");
/* harmony import */ var _RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./RouteConfig.js */ "./src/renderer/modules/route-sync/RouteConfig.js");
// 路由收集器 - 收集前端路由信息
@ -13835,24 +13835,21 @@ class RouteCollector { @@ -13835,24 +13835,21 @@ class RouteCollector {
collectRoutes() {
try {
// 从生成的路由映射文件收集
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; }()))) {
if (!_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings || !_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings.pageMappings) {
console.warn('⚠ 生成的路由映射文件格式不正确')
return []
}
// 转换为主入口路由格式
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 = _RouteConfig_js__WEBPACK_IMPORTED_MODULE_1__.RouteUtils.extractModuleFromPath(route.path)
}
// 从页面映射中提取路由信息
const frontendRoutes = _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_0__.directRouteMappings.pageMappings.map(mapping => {
return {
path: route.path,
name: route.name,
module: route.module,
description: route.description || route.name,
type: route.type || 'list'
path: mapping.route,
name: mapping.routeName,
module: mapping.module,
description: `${mapping.routeName}页面`,
type: 'list',
component: mapping.component,
apiCalls: mapping.apiCalls
}
})
@ -14038,7 +14035,7 @@ __webpack_require__.r(__webpack_exports__); @@ -14038,7 +14035,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ RouteMapper: () => (/* binding */ RouteMapper)
/* harmony export */ });
/* 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; }());
/* harmony import */ var _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./direct-route-mappings.js */ "./src/renderer/modules/route-sync/direct-route-mappings.js");
// 路由映射器 - 将前端路由映射到后端API
@ -14120,42 +14117,57 @@ class RouteMapper { @@ -14120,42 +14117,57 @@ class RouteMapper {
// 获取子路由映射
_getSubRouteMapping(routePath) {
try {
return Object(function webpackMissingModule() { var e = new Error("Cannot find module './generated-route-mapping.js'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())[routePath] || null
// 从新的直接映射文件中查找
if (_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings && _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.pageMappings) {
const pageMapping = _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.pageMappings.find(p => p.route === routePath)
if (pageMapping && pageMapping.apiCalls) {
return {
route: routePath,
apiCalls: pageMapping.apiCalls
}
}
}
return null
} catch (error) {
return null
}
}
// 获取模块的API配置 - 合并生成的文件和默认配置
// 获取模块的API配置 - 基于直接映射关系
_getApiConfigForModule(module) {
let apiConfig = null
// 首先尝试从生成的路由映射文件获取
// 从直接映射文件中获取API调用信息
try {
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] }
if (_direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings && _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.pageMappings) {
const moduleMappings = _direct_route_mappings_js__WEBPACK_IMPORTED_MODULE_1__.directRouteMappings.pageMappings.filter(p => p.module === module)
if (moduleMappings.length > 0) {
const operations = {}
moduleMappings.forEach(mapping => {
mapping.apiCalls.forEach(apiCall => {
const operationKey = `${apiCall.type}_${apiCall.service || apiCall.method}_${apiCall.method || apiCall.path}`
operations[operationKey] = {
path: apiCall.path || `/${apiCall.service}/${apiCall.method}`,
method: apiCall.method || 'GET'
}
})
})
if (Object.keys(operations).length > 0) {
apiConfig = {
basePath: '/api',
operations: operations
}
}
}
}
} catch (error) {
// 如果获取失败,使用默认配置
console.warn('获取直接映射配置失败:', error)
}
// 如果没有从生成文件获取到,使用默认配置
// 如果没有从直接映射获取到,使用默认配置
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
@ -14467,6 +14479,820 @@ class RouteSyncService { @@ -14467,6 +14479,820 @@ class RouteSyncService {
}
/***/ }),
/***/ "./src/renderer/modules/route-sync/direct-route-mappings.js":
/*!******************************************************************!*\
!*** ./src/renderer/modules/route-sync/direct-route-mappings.js ***!
\******************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ apiPathMappings: () => (/* binding */ apiPathMappings),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
/* harmony export */ directRouteMappings: () => (/* binding */ directRouteMappings),
/* harmony export */ moduleMappings: () => (/* binding */ moduleMappings)
/* harmony export */ });
// 第一阶段:直接路由-API映射关系
// 此文件由 route-mapping-plugin 在构建时生成
// 收集页面和弹窗组件的直接API调用关系
// 请勿手动修改
const directRouteMappings = {
// 第一层:页面组件的数据操作API
pageMappings: [
{
"route": "/user-management",
"routeName": "UserManagement",
"component": "UserManagement",
"module": "user-management",
"layer": "page",
"apiCalls": [
{
"type": "service",
"service": "userService",
"method": "getUsers",
"arguments": [
null,
null
],
"line": 69
},
{
"type": "service",
"service": "userService",
"method": "updateUser",
"arguments": [
null,
"userForm"
],
"line": 139
},
{
"type": "service",
"service": "userService",
"method": "createUser",
"arguments": [
"userForm"
],
"line": 141
},
{
"type": "service",
"service": "userService",
"method": "deleteUser",
"arguments": [
"userId"
],
"line": 153
}
],
"methods": [
"loadUsers",
"loadRoles",
"handleSearch",
"handleFilter",
"changePage",
"handlePageSizeChange",
"handleJumpPage",
"editUser",
"submitUser",
"deleteUser",
"assignRoles",
"closeModal",
"formatDate"
]
},
{
"route": "/user-profile",
"routeName": "UserProfile",
"component": "UserProfile",
"module": "user-profile",
"layer": "page",
"apiCalls": [
{
"type": "service",
"service": "userService",
"method": "getCurrentUser",
"arguments": [
"token"
],
"line": 45
}
],
"methods": [
"loadUserProfile",
"refreshProfile",
"changePassword",
"forceChangePassword",
"onPasswordChangeSuccess",
"goToLogin",
"formatDate",
"getStatusText",
"getStatusClass"
]
},
{
"route": "/role-management",
"routeName": "RoleManagement",
"component": "RoleManagement",
"module": "role-management",
"layer": "page",
"apiCalls": [
{
"type": "service",
"service": "roleService",
"method": "getRoles",
"arguments": [
null,
null
],
"line": 54
},
{
"type": "service",
"service": "roleService",
"method": "updateRole",
"arguments": [
null,
"roleForm"
],
"line": 108
},
{
"type": "service",
"service": "roleService",
"method": "createRole",
"arguments": [
"roleForm"
],
"line": 118
},
{
"type": "service",
"service": "roleService",
"method": "deleteRole",
"arguments": [
null
],
"line": 142
}
],
"methods": [
"handleSearch",
"loadRoles",
"createNewRole",
"editRole",
"saveRole",
"deleteRole",
"resetForm",
"handleCurrentChange",
"handlePageSizeChange",
"handleJumpPage",
"formatDate",
"assignPermissions",
"handlePermissionsUpdated"
]
}
],
// 第二层:弹窗组件的数据操作API
modalMappings: [
{
"component": "LoginModal",
"path": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\components\\LoginModal.vue",
"module": "user-management",
"layer": "modal",
"apiCalls": [
{
"type": "service",
"service": "userService",
"method": "login",
"arguments": [
null
],
"line": 106
},
{
"type": "service",
"service": "userService",
"method": "getCaptcha",
"arguments": [],
"line": 209
},
{
"type": "service",
"service": "userService",
"method": "getCaptcha",
"arguments": [],
"line": 230
}
],
"methods": []
},
{
"component": "PasswordChangeModal",
"path": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\components\\PasswordChangeModal.vue",
"module": "user-management",
"layer": "modal",
"apiCalls": [
{
"type": "service",
"service": "userService",
"method": "getPasswordPolicy",
"arguments": [],
"line": 97
},
{
"type": "service",
"service": "userService",
"method": "validatePassword",
"arguments": [
null
],
"line": 156
},
{
"type": "service",
"service": "userService",
"method": "changePassword",
"arguments": [
"requestData"
],
"line": 314
}
],
"methods": [
"loadPasswordPolicy",
"validatePassword",
"updateRequirements",
"calculatePasswordStrength",
"validateConfirmPassword",
"handleSubmit",
"handleClose",
"handleOverlayClick",
"clearCurrentPasswordError",
"clearNewPasswordError",
"clearConfirmPasswordError",
"handleNewPasswordInput",
"handleConfirmPasswordInput",
"resetFormState"
]
}
],
// 分析信息
analysisInfo: {
phase: 'phase1',
description: '第一阶段:收集直接映射关系',
timestamp: new Date().toISOString(),
pageCount: 3,
modalCount: 2,
totalApiCalls: 15
}
}
// 按模块分组的映射
const moduleMappings = {
"user-management": {
"pages": [
{
"route": "/user-management",
"routeName": "UserManagement",
"component": "UserManagement",
"module": "user-management",
"layer": "page",
"apiCalls": [
{
"type": "service",
"service": "userService",
"method": "getUsers",
"arguments": [
null,
null
],
"line": 69
},
{
"type": "service",
"service": "userService",
"method": "updateUser",
"arguments": [
null,
"userForm"
],
"line": 139
},
{
"type": "service",
"service": "userService",
"method": "createUser",
"arguments": [
"userForm"
],
"line": 141
},
{
"type": "service",
"service": "userService",
"method": "deleteUser",
"arguments": [
"userId"
],
"line": 153
}
],
"methods": [
"loadUsers",
"loadRoles",
"handleSearch",
"handleFilter",
"changePage",
"handlePageSizeChange",
"handleJumpPage",
"editUser",
"submitUser",
"deleteUser",
"assignRoles",
"closeModal",
"formatDate"
]
}
],
"modals": [
{
"component": "LoginModal",
"path": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\components\\LoginModal.vue",
"module": "user-management",
"layer": "modal",
"apiCalls": [
{
"type": "service",
"service": "userService",
"method": "login",
"arguments": [
null
],
"line": 106
},
{
"type": "service",
"service": "userService",
"method": "getCaptcha",
"arguments": [],
"line": 209
},
{
"type": "service",
"service": "userService",
"method": "getCaptcha",
"arguments": [],
"line": 230
}
],
"methods": []
},
{
"component": "PasswordChangeModal",
"path": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\components\\PasswordChangeModal.vue",
"module": "user-management",
"layer": "modal",
"apiCalls": [
{
"type": "service",
"service": "userService",
"method": "getPasswordPolicy",
"arguments": [],
"line": 97
},
{
"type": "service",
"service": "userService",
"method": "validatePassword",
"arguments": [
null
],
"line": 156
},
{
"type": "service",
"service": "userService",
"method": "changePassword",
"arguments": [
"requestData"
],
"line": 314
}
],
"methods": [
"loadPasswordPolicy",
"validatePassword",
"updateRequirements",
"calculatePasswordStrength",
"validateConfirmPassword",
"handleSubmit",
"handleClose",
"handleOverlayClick",
"clearCurrentPasswordError",
"clearNewPasswordError",
"clearConfirmPasswordError",
"handleNewPasswordInput",
"handleConfirmPasswordInput",
"resetFormState"
]
}
]
},
"user-profile": {
"pages": [
{
"route": "/user-profile",
"routeName": "UserProfile",
"component": "UserProfile",
"module": "user-profile",
"layer": "page",
"apiCalls": [
{
"type": "service",
"service": "userService",
"method": "getCurrentUser",
"arguments": [
"token"
],
"line": 45
}
],
"methods": [
"loadUserProfile",
"refreshProfile",
"changePassword",
"forceChangePassword",
"onPasswordChangeSuccess",
"goToLogin",
"formatDate",
"getStatusText",
"getStatusClass"
]
}
],
"modals": []
},
"role-management": {
"pages": [
{
"route": "/role-management",
"routeName": "RoleManagement",
"component": "RoleManagement",
"module": "role-management",
"layer": "page",
"apiCalls": [
{
"type": "service",
"service": "roleService",
"method": "getRoles",
"arguments": [
null,
null
],
"line": 54
},
{
"type": "service",
"service": "roleService",
"method": "updateRole",
"arguments": [
null,
"roleForm"
],
"line": 108
},
{
"type": "service",
"service": "roleService",
"method": "createRole",
"arguments": [
"roleForm"
],
"line": 118
},
{
"type": "service",
"service": "roleService",
"method": "deleteRole",
"arguments": [
null
],
"line": 142
}
],
"methods": [
"handleSearch",
"loadRoles",
"createNewRole",
"editRole",
"saveRole",
"deleteRole",
"resetForm",
"handleCurrentChange",
"handlePageSizeChange",
"handleJumpPage",
"formatDate",
"assignPermissions",
"handlePermissionsUpdated"
]
}
],
"modals": []
}
}
// 按API路径分组的映射
const apiPathMappings = {
"userService.getUsers": {
"pages": [
{
"component": "UserManagement",
"module": "user-management",
"route": "/user-management",
"apiCall": {
"type": "service",
"service": "userService",
"method": "getUsers",
"arguments": [
null,
null
],
"line": 69
}
}
],
"modals": []
},
"userService.updateUser": {
"pages": [
{
"component": "UserManagement",
"module": "user-management",
"route": "/user-management",
"apiCall": {
"type": "service",
"service": "userService",
"method": "updateUser",
"arguments": [
null,
"userForm"
],
"line": 139
}
}
],
"modals": []
},
"userService.createUser": {
"pages": [
{
"component": "UserManagement",
"module": "user-management",
"route": "/user-management",
"apiCall": {
"type": "service",
"service": "userService",
"method": "createUser",
"arguments": [
"userForm"
],
"line": 141
}
}
],
"modals": []
},
"userService.deleteUser": {
"pages": [
{
"component": "UserManagement",
"module": "user-management",
"route": "/user-management",
"apiCall": {
"type": "service",
"service": "userService",
"method": "deleteUser",
"arguments": [
"userId"
],
"line": 153
}
}
],
"modals": []
},
"userService.getCurrentUser": {
"pages": [
{
"component": "UserProfile",
"module": "user-profile",
"route": "/user-profile",
"apiCall": {
"type": "service",
"service": "userService",
"method": "getCurrentUser",
"arguments": [
"token"
],
"line": 45
}
}
],
"modals": []
},
"roleService.getRoles": {
"pages": [
{
"component": "RoleManagement",
"module": "role-management",
"route": "/role-management",
"apiCall": {
"type": "service",
"service": "roleService",
"method": "getRoles",
"arguments": [
null,
null
],
"line": 54
}
}
],
"modals": []
},
"roleService.updateRole": {
"pages": [
{
"component": "RoleManagement",
"module": "role-management",
"route": "/role-management",
"apiCall": {
"type": "service",
"service": "roleService",
"method": "updateRole",
"arguments": [
null,
"roleForm"
],
"line": 108
}
}
],
"modals": []
},
"roleService.createRole": {
"pages": [
{
"component": "RoleManagement",
"module": "role-management",
"route": "/role-management",
"apiCall": {
"type": "service",
"service": "roleService",
"method": "createRole",
"arguments": [
"roleForm"
],
"line": 118
}
}
],
"modals": []
},
"roleService.deleteRole": {
"pages": [
{
"component": "RoleManagement",
"module": "role-management",
"route": "/role-management",
"apiCall": {
"type": "service",
"service": "roleService",
"method": "deleteRole",
"arguments": [
null
],
"line": 142
}
}
],
"modals": []
},
"userService.login": {
"pages": [],
"modals": [
{
"component": "LoginModal",
"module": "user-management",
"route": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\components\\LoginModal.vue",
"apiCall": {
"type": "service",
"service": "userService",
"method": "login",
"arguments": [
null
],
"line": 106
}
}
]
},
"userService.getCaptcha": {
"pages": [],
"modals": [
{
"component": "LoginModal",
"module": "user-management",
"route": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\components\\LoginModal.vue",
"apiCall": {
"type": "service",
"service": "userService",
"method": "getCaptcha",
"arguments": [],
"line": 209
}
},
{
"component": "LoginModal",
"module": "user-management",
"route": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\components\\LoginModal.vue",
"apiCall": {
"type": "service",
"service": "userService",
"method": "getCaptcha",
"arguments": [],
"line": 230
}
}
]
},
"userService.getPasswordPolicy": {
"pages": [],
"modals": [
{
"component": "PasswordChangeModal",
"module": "user-management",
"route": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\components\\PasswordChangeModal.vue",
"apiCall": {
"type": "service",
"service": "userService",
"method": "getPasswordPolicy",
"arguments": [],
"line": 97
}
}
]
},
"userService.validatePassword": {
"pages": [],
"modals": [
{
"component": "PasswordChangeModal",
"module": "user-management",
"route": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\components\\PasswordChangeModal.vue",
"apiCall": {
"type": "service",
"service": "userService",
"method": "validatePassword",
"arguments": [
null
],
"line": 156
}
}
]
},
"userService.changePassword": {
"pages": [],
"modals": [
{
"component": "PasswordChangeModal",
"module": "user-management",
"route": "D:\\aigc\\manta\\gofaster\\app\\src\\renderer\\modules\\user-management\\components\\PasswordChangeModal.vue",
"apiCall": {
"type": "service",
"service": "userService",
"method": "changePassword",
"arguments": [
"requestData"
],
"line": 314
}
}
]
}
}
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (directRouteMappings);
/***/ }),
/***/ "./src/renderer/modules/route-sync/index.js":
@ -15821,7 +16647,7 @@ __webpack_require__.r(__webpack_exports__); @@ -15821,7 +16647,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("a79c70d541afd8fd")
/******/ __webpack_require__.h = () => ("914b31636596a80a")
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */

11
gofaster/app/package.json

@ -3,11 +3,12 @@ @@ -3,11 +3,12 @@
"version": "1.0.0",
"main": "src/main/index.js",
"scripts": {
"dev": "cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js vue-cli-service build --mode development --verbose && electron .",
"dev:watch": "cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js concurrently \"vue-cli-service build --mode development --watch --verbose\" \"wait-on dist/renderer/index.html && electron .\"",
"build": "cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js vue-cli-service build --verbose && electron-builder",
"electron:serve": "cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js vue-cli-service build --mode development --verbose && electron .",
"build:vue": "cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js vue-cli-service build --mode development --verbose",
"prebuild": "node scripts/generate-route-mappings.js",
"dev": "npm run prebuild && cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js vue-cli-service build --mode development --verbose && electron .",
"dev:watch": "npm run prebuild && cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js concurrently \"vue-cli-service build --mode development --watch --verbose\" \"wait-on dist/renderer/index.html && electron .\"",
"build": "npm run prebuild && cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js vue-cli-service build --verbose && electron-builder",
"electron:serve": "npm run prebuild && cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js vue-cli-service build --mode development --verbose && electron .",
"build:vue": "npm run prebuild && cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js vue-cli-service build --mode development --verbose",
"dev:enhanced": "powershell -ExecutionPolicy Bypass -File dev-enhanced.ps1",
"dev:enhanced-bat": "dev-enhanced.bat",
"dev:debug": "cross-env VUE_CLI_BABEL_TRANSPILE_MODULES=false VUE_CLI_MODERN_BUILD=false VUE_CLI_SERVICE_CONFIG_PATH=vue.config.js DEBUG=* vue-cli-service build --mode development --verbose && electron .",

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

File diff suppressed because it is too large Load Diff

14
gofaster/app/scripts/generate-route-mappings.js

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
const { routeMappingPlugin } = require('../plugins/route-mapping-plugin.js')
// 独立运行路由映射生成
console.log('🔧 独立生成路由映射文件...')
try {
const plugin = routeMappingPlugin()
plugin.collectDirectMappings()
console.log('✅ 路由映射文件生成完成')
} catch (error) {
console.error('❌ 路由映射文件生成失败:', error)
process.exit(1)
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// 路由收集器 - 收集前端路由信息
import { mainRoutes } from './generated-route-mapping.js'
import { directRouteMappings } from './direct-route-mappings.js'
import { RouteUtils } from './RouteConfig.js'
// 路由收集器
@ -12,24 +12,21 @@ export class RouteCollector { @@ -12,24 +12,21 @@ export class RouteCollector {
collectRoutes() {
try {
// 从生成的路由映射文件收集
if (!mainRoutes || !Array.isArray(mainRoutes)) {
if (!directRouteMappings || !directRouteMappings.pageMappings) {
console.warn('⚠ 生成的路由映射文件格式不正确')
return []
}
// 转换为主入口路由格式
const frontendRoutes = mainRoutes.map(route => {
// 确保模块信息正确
if (!route.module) {
route.module = RouteUtils.extractModuleFromPath(route.path)
}
// 从页面映射中提取路由信息
const frontendRoutes = directRouteMappings.pageMappings.map(mapping => {
return {
path: route.path,
name: route.name,
module: route.module,
description: route.description || route.name,
type: route.type || 'list'
path: mapping.route,
name: mapping.routeName,
module: mapping.module,
description: `${mapping.routeName}页面`,
type: 'list',
component: mapping.component,
apiCalls: mapping.apiCalls
}
})

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

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
// 路由映射器 - 将前端路由映射到后端API
import { RouteUtils, RouteConfig } from './RouteConfig.js'
import { subRouteMappings, moduleApiMappings } from './generated-route-mapping.js'
import { directRouteMappings } from './direct-route-mappings.js'
export class RouteMapper {
constructor() {
@ -79,42 +79,57 @@ export class RouteMapper { @@ -79,42 +79,57 @@ export class RouteMapper {
// 获取子路由映射
_getSubRouteMapping(routePath) {
try {
return subRouteMappings[routePath] || null
// 从新的直接映射文件中查找
if (directRouteMappings && directRouteMappings.pageMappings) {
const pageMapping = directRouteMappings.pageMappings.find(p => p.route === routePath)
if (pageMapping && pageMapping.apiCalls) {
return {
route: routePath,
apiCalls: pageMapping.apiCalls
}
}
}
return null
} catch (error) {
return null
}
}
// 获取模块的API配置 - 合并生成的文件和默认配置
// 获取模块的API配置 - 基于直接映射关系
_getApiConfigForModule(module) {
let apiConfig = null
// 首先尝试从生成的路由映射文件获取
// 从直接映射文件中获取API调用信息
try {
if (moduleApiMappings && moduleApiMappings[module]) {
apiConfig = { ...moduleApiMappings[module] }
if (directRouteMappings && directRouteMappings.pageMappings) {
const moduleMappings = directRouteMappings.pageMappings.filter(p => p.module === module)
if (moduleMappings.length > 0) {
const operations = {}
moduleMappings.forEach(mapping => {
mapping.apiCalls.forEach(apiCall => {
const operationKey = `${apiCall.type}_${apiCall.service || apiCall.method}_${apiCall.method || apiCall.path}`
operations[operationKey] = {
path: apiCall.path || `/${apiCall.service}/${apiCall.method}`,
method: apiCall.method || 'GET'
}
})
})
if (Object.keys(operations).length > 0) {
apiConfig = {
basePath: '/api',
operations: operations
}
}
}
}
} catch (error) {
// 如果获取失败,使用默认配置
console.warn('获取直接映射配置失败:', error)
}
// 如果没有从生成文件获取到,使用默认配置
// 如果没有从直接映射获取到,使用默认配置
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

4
gofaster/app/vue.config.js

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
const path = require('path')
const { defineConfig } = require('@vue/cli-service')
const { routeMappingPlugin } = require('./plugins/route-mapping-plugin.js')
// 设置环境变量
process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = 'false'
@ -161,6 +162,9 @@ module.exports = defineConfig({ @@ -161,6 +162,9 @@ module.exports = defineConfig({
},
chainWebpack: config => {
// 添加路由映射插件
config.plugin('route-mapping').use(routeMappingPlugin())
// 强制禁用所有sourcemap,避免eval
config.devtool(false)

Loading…
Cancel
Save