From 8903aff64231b1f11775cfcd3975649896ce7966 Mon Sep 17 00:00:00 2001
From: izory <791736813@qq.com>
Date: Fri, 10 Sep 2021 10:44:17 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BB=A3=E7=A0=81=E7=94=9F?=
=?UTF-8?q?=E6=88=90=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/CodeGeneratorController.cs | 33 ++--
.../Filters/ActionPermissionFilter.cs | 2 +-
ZR.CodeGenerator/CodeGeneratorTool.cs | 16 +-
ZR.CodeGenerator/Model/GenerateDto.cs | 4 +-
ZR.Vue/public/index.html | 46 +++---
ZR.Vue/src/api/{ => system}/login.js | 0
ZR.Vue/src/api/tool/gen.js | 144 +++++-------------
ZR.Vue/src/store/modules/user.js | 2 +-
ZR.Vue/src/views/index.vue | 4 +-
ZR.Vue/src/views/login.vue | 2 +-
ZR.Vue/src/views/tool/index.vue | 38 ++---
11 files changed, 105 insertions(+), 186 deletions(-)
rename ZR.Vue/src/api/{ => system}/login.js (100%)
diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs
index 49cb10b..7cffe87 100644
--- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs
+++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs
@@ -1,20 +1,15 @@
using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Enums;
-using Infrastructure.Model;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
+using ZR.Admin.WebApi.Filters;
using ZR.CodeGenerator;
using ZR.CodeGenerator.Model;
using ZR.CodeGenerator.Service;
using ZR.Model;
using ZR.Model.Vo;
-using ZR.Service.IService;
-using ZR.Service.System;
namespace ZR.Admin.WebApi.Controllers
{
@@ -24,11 +19,6 @@ namespace ZR.Admin.WebApi.Controllers
[Route("tool/gen")]
public class CodeGeneratorController : BaseController
{
- //public ICodeGeneratorService CodeGeneratorService;
- //public CodeGeneratorController(ICodeGeneratorService codeGeneratorService)
- //{
- // CodeGeneratorService = codeGeneratorService;
- //}
private CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService();
///
@@ -36,7 +26,7 @@ namespace ZR.Admin.WebApi.Controllers
///
///
[HttpGet("getDbList")]
- //[YuebonAuthorize("GetListDataBase")]
+ [ActionPermissionFilter(Permission = "tool:gen:list")]
public IActionResult GetListDataBase()
{
var dbList = _CodeGeneraterService.GetAllDataBases();
@@ -51,7 +41,8 @@ namespace ZR.Admin.WebApi.Controllers
/// 表名
/// 分页信息
///
- [HttpGet("FindListTable")]
+ [HttpGet("getTableList")]
+ [ActionPermissionFilter(Permission = "tool:gen:list")]
public IActionResult FindListTable(string dbName, string tableName, PagerInfo pager)
{
List list = _CodeGeneraterService.GetAllTables(dbName, tableName, pager);
@@ -66,7 +57,8 @@ namespace ZR.Admin.WebApi.Controllers
///
///
///
- [HttpGet("QueryColumnInfo")]
+ [HttpGet("getColumnInfo")]
+ [ActionPermissionFilter(Permission = "tool:gen:list")]
public IActionResult QueryColumnInfo(string dbName, string tableName)
{
if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(tableName))
@@ -80,18 +72,19 @@ namespace ZR.Admin.WebApi.Controllers
///
/// 数据传输对象
///
- [HttpGet("Generate")]
- [Log(Title = "代码生成", BusinessType = BusinessType.OTHER)]
- public IActionResult Generate([FromQuery] GenerateDto dto)
+ [HttpPost("genCode")]
+ [Log(Title = "代码生成", BusinessType = BusinessType.GENCODE)]
+ [ActionPermissionFilter(Permission = "tool:gen:code")]
+ public IActionResult Generate([FromBody] GenerateDto dto)
{
- if (string.IsNullOrEmpty(dto.tables))
+ if (string.IsNullOrEmpty(dto.tableName))
{
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
}
- DbTableInfo dbTableInfo = new() { Name = dto.tables };
+ DbTableInfo dbTableInfo = new() { Name = dto.tableName };
CodeGeneratorTool.Generate(dbTableInfo, dto);
- return SUCCESS(1);
+ return SUCCESS(dbTableInfo);
}
}
}
diff --git a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs
index 88258d7..08cad61 100644
--- a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs
+++ b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs
@@ -54,7 +54,7 @@ namespace ZR.Admin.WebApi.Filters
bool isDemoMode = ConfigUtils.Instance.GetAppConfig("DemoMode", false);
//演示公开环境屏蔽权限
- string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear" };
+ string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "gen" };
if (isDemoMode && (denyPerms.Any(f => Permission.ToLower().Contains(f.ToLower())) || Permission.Equals("system")))
{
context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "演示模式 , 不允许操作" });
diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs
index 9c51eb8..8269080 100644
--- a/ZR.CodeGenerator/CodeGeneratorTool.cs
+++ b/ZR.CodeGenerator/CodeGeneratorTool.cs
@@ -64,7 +64,7 @@ namespace ZR.CodeGenerator
public static void GenerateSingle(List listField, DbTableInfo tableInfo, GenerateDto dto)
{
bool ifExsitedCovered = dto.coverd;
- var modelTypeName = GetModelName(tableInfo.Name).Replace(_option.ReplaceTableNameStr, "");//表名
+ var modelTypeName = GetModelName(tableInfo.Name);
var modelTypeDesc = tableInfo.Description;//表描述
var primaryKey = "id";//主键
@@ -107,7 +107,7 @@ namespace ZR.CodeGenerator
}
if (dto.genFiles.Contains(1))
{
- GenerateModels(_option.ModelsNamespace, modelTypeName, tableInfo.Name, modelContent, modelTypeDesc, keyTypeName, ifExsitedCovered);
+ //GenerateModels(_option.ModelsNamespace, modelTypeName, tableInfo.Name, modelContent, modelTypeDesc, keyTypeName, ifExsitedCovered);
}
if (dto.genFiles.Contains(2))
{
@@ -478,16 +478,14 @@ namespace ZR.CodeGenerator
/// 如果目标文件存在,是否覆盖。默认为false
private static void GenerateVueViews(string modelTypeName, string primaryKey, string modelTypeDesc, string vueViewListContent, string vueViewFromContent, string vueViewEditFromContent, string vueViewEditFromBindContent, string vueViewSaveBindContent, string vueViewEditFromRuleContent, bool ifExsitedCovered = false)
{
- var servicesNamespace = _option.DtosNamespace;
- var path = "..\\CodeGenerate\\";
- var parentPath = path.Substring(0, path.LastIndexOf("\\"));
- var servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\" + servicesNamespace;
+ var parentPath = "..\\CodeGenerate";//若要生成到项目中将路径改成 “..\\ZR.Vue\\src”
+ var servicesPath = parentPath + "\\views\\" + FirstLowerCase(modelTypeName);
if (!Directory.Exists(servicesPath))
{
- servicesPath = parentPath + "\\" + _option.BaseNamespace + "\\views\\" + FirstLowerCase(modelTypeName);
Directory.CreateDirectory(servicesPath);
}
var fullPath = servicesPath + "\\" + "index.vue";
+ Console.WriteLine(fullPath);
if (File.Exists(fullPath) && !ifExsitedCovered)
return;
var content = ReadTemplate("VueTemplate.txt");
@@ -505,7 +503,11 @@ namespace ZR.CodeGenerator
.Replace("{VueViewEditFromRuleContent}", vueViewEditFromRuleContent);
WriteAndSave(fullPath, content);
+ //api js
+ servicesPath = parentPath + "\\api\\";
+ Directory.CreateDirectory(servicesPath);
fullPath = servicesPath + "\\" + FirstLowerCase(modelTypeName) + ".js";
+ Console.WriteLine(fullPath);
if (File.Exists(fullPath) && !ifExsitedCovered)
return;
content = ReadTemplate("VueJsTemplate.txt");
diff --git a/ZR.CodeGenerator/Model/GenerateDto.cs b/ZR.CodeGenerator/Model/GenerateDto.cs
index be9e00f..60399fc 100644
--- a/ZR.CodeGenerator/Model/GenerateDto.cs
+++ b/ZR.CodeGenerator/Model/GenerateDto.cs
@@ -8,7 +8,7 @@ namespace ZR.CodeGenerator.Model
{
public class GenerateDto
{
- public string queryColumn { get; set; }
+ public string[] queryColumn { get; set; }
///
///
///
@@ -20,7 +20,7 @@ namespace ZR.CodeGenerator.Model
///
/// 要生成代码的表
///
- public string tables { get; set; }
+ public string tableName { get; set; }
///
/// 要删除表名的字符串用
///
diff --git a/ZR.Vue/public/index.html b/ZR.Vue/public/index.html
index 6d64bf9..c896b69 100644
--- a/ZR.Vue/public/index.html
+++ b/ZR.Vue/public/index.html
@@ -1,13 +1,16 @@
-
-
-
-
-
-
- <%= webpackConfig.name %>
-
-
-
-
-
+
+
+
+
+
+