代码生成增加预览功能、其他功能优化
This commit is contained in:
@@ -94,7 +94,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
//生成代码
|
||||
CodeGeneratorTool.Generate(genTableInfo, dto);
|
||||
//下载文件
|
||||
CodeGeneratorTool.ZipGenCode(dto);
|
||||
FileHelper.ZipGenCode(dto);
|
||||
|
||||
//HttpContext.Response.Headers.Add("Content-disposition", $"attachment; filename={zipFileName}");
|
||||
return SUCCESS(new { zipPath = "/Generatecode/" + dto.ZipFileName, fileName = dto.ZipFileName });
|
||||
@@ -145,7 +145,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入表
|
||||
/// 导入表结构(保存)
|
||||
/// </summary>
|
||||
/// <param name="tables"></param>
|
||||
/// <param name="dbName"></param>
|
||||
@@ -218,5 +218,32 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
}
|
||||
return SUCCESS(rows);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预览代码
|
||||
/// </summary>
|
||||
/// <param name="tableId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("preview/{tableId}")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:preview")]
|
||||
public IActionResult Preview(long tableId)
|
||||
{
|
||||
if (tableId <= 0)
|
||||
{
|
||||
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
|
||||
}
|
||||
var genTableInfo = GenTableService.GetGenTableInfo(tableId);
|
||||
genTableInfo.Columns = GenTableColumnService.GenTableColumns(tableId);
|
||||
GenerateDto dto = new();
|
||||
dto.GenTable = genTableInfo;
|
||||
dto.ZipPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode");
|
||||
dto.GenCodePath = Path.Combine(dto.ZipPath, DateTime.Now.ToString("yyyyMMdd"));
|
||||
dto.IsPreview = 1;
|
||||
dto.GenCodeFiles = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
//生成代码
|
||||
CodeGeneratorTool.Generate(genTableInfo, dto);
|
||||
|
||||
return SUCCESS(dto.GenCodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,17 @@ using ZR.Common;
|
||||
namespace {ApiControllerNamespace}.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码自动生成
|
||||
/// {FunctionName}Controller
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("{ModuleName}/{ModelName}")]
|
||||
public class {ModelName}Controller: BaseController
|
||||
{
|
||||
{
|
||||
/// <summary>
|
||||
/// {TableDesc}接口
|
||||
/// {FunctionName}接口
|
||||
/// </summary>
|
||||
private readonly I{ModelName}Service _{ModelName}Service;
|
||||
|
||||
@@ -35,7 +38,7 @@ namespace {ApiControllerNamespace}.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询{TableDesc}列表
|
||||
/// 查询{FunctionName}列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
@@ -54,7 +57,7 @@ namespace {ApiControllerNamespace}.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询{TableDesc}详情
|
||||
/// 查询{FunctionName}详情
|
||||
/// </summary>
|
||||
/// <param name="{PrimaryKey}"></param>
|
||||
/// <returns></returns>
|
||||
@@ -68,7 +71,7 @@ namespace {ApiControllerNamespace}.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加{TableDesc}
|
||||
/// 添加{FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
@@ -90,7 +93,7 @@ namespace {ApiControllerNamespace}.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新{TableDesc}
|
||||
/// 更新{FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
@@ -115,7 +118,7 @@ namespace {ApiControllerNamespace}.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除{TableDesc}
|
||||
/// 删除{FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{ids}")]
|
||||
|
||||
@@ -4,7 +4,10 @@ using {ModelsNamespace}.Models;
|
||||
namespace {IServicsNamespace}.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// 定义{TableNameDesc}服务接口
|
||||
/// {FunctionName}service接口
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
public interface I{ModelTypeName}Service: IBaseService<{ModelTypeName}>
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ using {ModelsNamespace}.Models;
|
||||
namespace {DtosNamespace}.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// {TableNameDesc}输入对象模型
|
||||
/// {FunctionName}输入对象模型
|
||||
/// </summary>
|
||||
public class {ModelTypeName}Dto
|
||||
{
|
||||
@@ -14,7 +14,7 @@ namespace {DtosNamespace}.Dto
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// {TableNameDesc}查询对象模型
|
||||
/// {FunctionName}查询对象模型
|
||||
/// </summary>
|
||||
public class {ModelTypeName}QueryDto: PagerInfo
|
||||
{
|
||||
|
||||
@@ -4,7 +4,10 @@ using System.Collections.Generic;
|
||||
namespace {ModelsNamespace}.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// {TableNameDesc},数据实体对象
|
||||
/// {FunctionName},数据实体对象
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("{TableName}")]
|
||||
public class {ModelTypeName}
|
||||
|
||||
@@ -6,20 +6,15 @@ using {ModelsNamespace}.Models;
|
||||
namespace {RepositoriesNamespace}
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成器生成
|
||||
/// {TableNameDesc}仓储接口的实现
|
||||
/// {FunctionName}仓储接口的实现
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class {ModelTypeName}Repository : BaseRepository
|
||||
{
|
||||
public {ModelTypeName}Repository()
|
||||
{
|
||||
}
|
||||
|
||||
#region 业务逻辑代码
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -13,15 +13,18 @@ using {IRepositoriesNamespace};
|
||||
namespace {ServicesNamespace}.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成器生成
|
||||
/// {FunctionName}Service业务层处理
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(I{ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)]
|
||||
public class {ModelTypeName}Service: BaseService<{ModelTypeName}>, I{ModelTypeName}Service
|
||||
{
|
||||
private readonly {ModelTypeName}Repository _repository;
|
||||
private readonly {ModelTypeName}Repository _repository;
|
||||
public {ModelTypeName}Service({ModelTypeName}Repository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
#region 业务逻辑代码
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/**
|
||||
* {ModelTypeDesc}分页查询
|
||||
* {FunctionName}分页查询
|
||||
* @param {查询条件} data
|
||||
*/
|
||||
export function list{ModelTypeName}(query) {
|
||||
@@ -13,7 +13,7 @@ export function list{ModelTypeName}(query) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增{ModelTypeDesc}
|
||||
* 新增{FunctionName}
|
||||
* @param data
|
||||
*/
|
||||
export function add{ModelTypeName}(data) {
|
||||
@@ -25,7 +25,7 @@ export function add{ModelTypeName}(data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改{ModelTypeDesc}
|
||||
* 修改{FunctionName}
|
||||
* @param data
|
||||
*/
|
||||
export function update{ModelTypeName}(data) {
|
||||
@@ -37,7 +37,7 @@ export function update{ModelTypeName}(data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取{ModelTypeDesc}详情
|
||||
* 获取{FunctionName}详情
|
||||
* @param {Id} {ModelTypeDesc}Id
|
||||
*/
|
||||
export function get{ModelTypeName}(id) {
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
<div class="app-container">
|
||||
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
||||
<el-form :model="queryParams" label-position="left" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch" @submit.native.prevent>
|
||||
{vueQueryFormHtml}
|
||||
|
||||
{vueQueryFormHtml}
|
||||
<el-row class="mb8" style="text-align:center">
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||
@@ -27,7 +26,7 @@
|
||||
<!-- 数据区域 -->
|
||||
<el-table :data="dataList" ref="table" border @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="50" />
|
||||
{VueViewListContent}
|
||||
{VueViewListContent}
|
||||
<el-table-column label="操作" align="center" width="200">
|
||||
<template slot-scope="scope">
|
||||
<el-button v-hasPermi="['{Permission}:update']" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
|
||||
@@ -42,7 +41,7 @@
|
||||
<!-- 添加或修改菜单对话框 -->
|
||||
<el-dialog :title="title" :lock-scroll="false" :visible.sync="open" >
|
||||
<el-form ref="form" :model="form" :rules="rules" :label-width="formLabelWidth">
|
||||
{VueViewFormContent}
|
||||
{VueViewFormContent}
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer" v-if="btnSubmitVisible">
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
@@ -67,7 +66,7 @@ export default {
|
||||
return {
|
||||
labelWidth: "100px",
|
||||
formLabelWidth:"100px",
|
||||
// 选中{primaryKey}数组
|
||||
// 选中{PrimaryKey}数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
@@ -96,18 +95,15 @@ export default {
|
||||
btnSubmitVisible: true,
|
||||
// 表单校验
|
||||
rules: {
|
||||
{VueViewEditFormRuleContent}
|
||||
{VueViewEditFormRuleContent}
|
||||
},
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
// 列表数据查询
|
||||
this.getList();
|
||||
// 下拉框绑定
|
||||
// this.getDicts("sys_normal_disable").then((response) => {
|
||||
// this.statusOptions = response.data;
|
||||
// });
|
||||
{MountedMethod}
|
||||
|
||||
{MountedMethod}
|
||||
},
|
||||
methods: {
|
||||
// 查询数据
|
||||
@@ -128,7 +124,7 @@ export default {
|
||||
// 重置数据表单
|
||||
reset() {
|
||||
this.form = {
|
||||
{VueViewFormResetHtml}
|
||||
{VueViewFormResetHtml}
|
||||
//TODO 根据实际内容调整
|
||||
};
|
||||
this.resetForm("form");
|
||||
@@ -146,16 +142,10 @@ export default {
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map((item) => item.{primaryKey});
|
||||
this.ids = selection.map((item) => item.{PrimaryKey});
|
||||
this.single = selection.length!=1
|
||||
this.multiple = !selection.length;
|
||||
},
|
||||
/** 选择每页显示数量*/
|
||||
handleSizeChange(val) {
|
||||
this.queryParams.pageSize = val;
|
||||
this.queryParams.pageNum = 1;
|
||||
this.handleQuery();
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.getList();
|
||||
@@ -168,8 +158,8 @@ export default {
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const {primaryKey}s = row.{primaryKey} || this.ids;
|
||||
del{ModelTypeName}({primaryKey}s.toString()).then((res) => {
|
||||
const {PrimaryKey}s = row.{PrimaryKey} || this.ids;
|
||||
del{ModelTypeName}({PrimaryKey}s.toString()).then((res) => {
|
||||
this.msgSuccess("删除成功");
|
||||
this.handleQuery();
|
||||
});
|
||||
@@ -177,12 +167,12 @@ export default {
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
const {primaryKey} = row.{primaryKey} || this.ids;
|
||||
get{ModelTypeName}({primaryKey}).then((res) => {
|
||||
const {PrimaryKey} = row.{PrimaryKey} || this.ids;
|
||||
get{ModelTypeName}({PrimaryKey}).then((res) => {
|
||||
if(res.code == 200){
|
||||
this.form = res.data;
|
||||
this.open = true;
|
||||
this.title = "修改数据";
|
||||
this.form = res.data;
|
||||
this.open = true;
|
||||
this.title = "修改数据";
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -194,7 +184,7 @@ export default {
|
||||
if (valid) {
|
||||
console.log(JSON.stringify(this.form));
|
||||
|
||||
if (this.form.{primaryKey} != undefined || this.title === '修改数据') {
|
||||
if (this.form.{PrimaryKey} != undefined || this.title === '修改数据') {
|
||||
update{ModelTypeName}(this.form).then((res) => {
|
||||
this.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
|
||||
Reference in New Issue
Block a user