# coder **Repository Path**: wynnyo/coder ## Basic Information - **Project Name**: coder - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-02-04 - **Last Updated**: 2021-02-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 说明 该项目只是整个代码生成器的一部分, 后续打算作为一个 `npm package` 直接在 vue-electron 里使用, 该包的主要作用为:把`实体配置文件`转换为对应的`代码` ## 目前进度 - 框架基本完善 - 后端代码可以生成, 并且测试基本通过, 后续考虑是否把 `权限和本地化` 作为单独模块, 目前集成在项目下 - 前端代码只是把模版定义了, 还没有测试和修改细节 ## 使用 - 在 entities 文件夹下新建实体配置文件 Order.json - 在 index.js 文件最前面修改`项目的根目录`和`选择的实体配置`, 这里只是测试用, 后续要配合Electron直接传入 ```json const rootPath = 'C:\\Users\\w2197\\source\\repos\\ABP-vNext-Vue' const entityConfigName = 'Order' ``` - 运行 ```shell yarn yarn start 或者 node index.js ``` - 截图 ![image-20210207175539519](http://images.wynnyo.com/Markdown/image-20210207175539519.png?x-oss-process=style/wynnyo-style) ## 生成文件说明 ### aspnet-core - `OrderConsts.cs` 包含数据库表名, 字段最大长度 - `Order.cs` 实体 - `SmartCanteenDbContext.cs` 添加实体的 DbSet - `OrderDbContextModelCreatingExtensions.cs` 实体和数据库的数据映射配置 - `SmartCanteenDbContextModelCreatingExtensions.cs` 注入实体的映射配置 - `OrderDto.cs` 列表Dto - `CreateUpdateOrderDto.cs` 创建和更新Dto - `OrderAutoMapperProfile.cs` AutoMapper映射 - `en.json` 英文本地化 - `zh-Hans.json` 中文本地化 - `OrderPermissions.cs` 权限定义 - `OrderPermissionDefinitionProvider.cs` 权限注册 - `IOrderAppService.cs` 服务接口 - `OrderAppService.cs` 服务类 ### vue - `api/order.js` api - `router/order.js` 路由 - `index.vue` 主页 - `create-update-dialog.vue` 创建编辑页 ## 配置文件说明 ```json { "companyName": "Xhznl", // 公司名称 "projectName": "HelloAbp", // 项目名称 "corePath": "aspnet-core", // .net core 路径 "coreSrcPath": "src", // .net core 源码位置 "domainPath": "<%=it.companyName%>.<%=it.projectName%>.Domain", "domainSharedPath": "<%=it.companyName%>.<%=it.projectName%>.Domain.Shared", "localizationPath": "Localization/<%=it.projectName%>", "applicationPath": "<%=it.companyName%>.<%=it.projectName%>.Application", "applicationPathAutoMapperProfile": "<%=it.projectName%>ApplicationAutoMapperProfile", "applicationContractsPath": "<%=it.companyName%>.<%=it.projectName%>.Application.Contracts", "entityFrameworkCorePath": "<%=it.companyName%>.<%=it.projectName%>.EntityFrameworkCore", "dbContextPath": "EntityFrameworkCore", "dbContextName": "<%=it.projectName%>DbContext", // DbContext是修改文件, 所以需要描点, 生成的文本将会添加在描点的后面 // 可以自己修改, 自定义修改需要同时在对应的DbContext加上描点内容 "dbContextAnchor": "public DbSet Users { get; set; }", "dbContextModelCreatingExtensionsName": "<%=it.projectName%>DbContextModelCreatingExtensions", // 实体和数据库的数据映射配置 "dbContextModelCreatingExtensionsAnchor": "/* Configure your own tables/entities inside here */", // 实体和数据库的数据映射配置的描点 "dbMigrationsPath": "<%=it.companyName%>.<%=it.projectName%>.EntityFrameworkCore.DbMigrations", // DbMigrations 路径, 用于生成 migration "hostPath": "<%=it.companyName%>.<%=it.projectName%>.HttpApi.Host", "vuePath": "vue", "vueSrcPath": "src", "vueApiPath": "api", "vueViewsPath": "views", "vueRouterPath": "router" } ``` ## 实体配置说明 ```json { "namespace": "Orders", // 文件对应的命名空间 "entityName": "Order", // 实体名称 "entityNamePlural": "Orders", // 实体的复数形式 "entityCnName": "订单", // 实体对应的中文 "tableName": "Orders", // 生成数据库的名字 "primaryKeyType": "Guid", // 实体主键 "baseClass": "CreationAuditedEntity", // 实体基类 "autoMigration": true, // 是否自动生成 Migration "migrationName": "Add_Order", // migrationName "updateDatabase": true, // 是否自动更新数据库 "createExcelExport": true, // 是否生成导入/导出excel "enumIcon": "document", // 菜单对应的图标名称, element-ui "userInfo": "wynnyo", // 注释中使用的用户信息 "baseProperties": [ // 这个是基类的相关配置, 主要配置 search, edit, list 前端相关的信息 { "name": "CreatorId", "cnName": "创建人", "type": "Guid", "enumName": "", "enumNamespace": "", "max": -1, "min": -1, "override": true, "required": false, "nullable": true, "search": { "isShow": true, "index": 1, "type": "select", "dataSource": "user" }, "edit": { "isShow": true, "index": 1, "type": "select", "dataSource": "user" }, "list": { "isShow": true, "index": 1, "shortable": true, "type": "select", "width": 120, "filter": [], "dataSource": "user" } } ], "properties": [ // 属性信息 { "name": "Category", // 属性名称 "cnName": "分类", // 属性中文名称 "type": "enum", // 属性类型, 常用 string, int, decimal, enum "enumName": "Category", // enum 名称 "enumNamespace": "Xhznl.HelloAbp.Orders", // enum 命名空间 "enumConver": true, // 在和数据库表映射时是否转换为 enum->name "max": -1, // 最大值, -1 为没有 "min": -1, // 最小值, -1 为没有, 目前还没有使用 "required": true, // 是否必须, 这个目前在3个地方使用, 1. 映射数据库表; 2. CreateUpdateDto验证; 3. vue 表单验证 "nullable": false, // 是否可空,这个目前一个地方使用, 1.生成属性类型时使用 "search": { // 前端高级搜索中使用 "isShow": true, // 是否显示 "index": 0, // 排序 "type": "select", // 类型 "dataSource": "" // 后续可能设计到 select 或者其他的数据源 }, "edit": { // 新增和编辑中使用 "isShow": true, // 是否显示 "index": 0, // 排序 "type": "select", // 类型 "dataSource": "" // 数据源 }, "list": { // 列表中显示 "isShow": true, // 是否显示 "index": 1, // 排序 "shortable": true, // 是否可以对该列进行重新排序 "type": "select", // 类型 "width": 120, // table 列宽 "filter": [], // vue filter, 用来显示 format "dataSource": "" // 数据源 } } ] } ```