代码生成新增是否显示指定按钮
This commit is contained in:
parent
d9e8de4957
commit
f4906a16de
@ -206,25 +206,24 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 预览代码
|
/// 预览代码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tableId"></param>
|
/// <param name="dto"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("preview/{tableId}")]
|
[HttpPost("preview/{tableId}")]
|
||||||
[ActionPermissionFilter(Permission = "tool:gen:preview")]
|
[ActionPermissionFilter(Permission = "tool:gen:preview")]
|
||||||
public IActionResult Preview(long tableId)
|
public IActionResult Preview([FromBody] GenerateDto dto)
|
||||||
{
|
{
|
||||||
if (tableId <= 0)
|
if (dto == null || dto.TableId <= 0)
|
||||||
{
|
{
|
||||||
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
|
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
|
||||||
}
|
}
|
||||||
var genTableInfo = GenTableService.GetGenTableInfo(tableId);
|
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
|
||||||
genTableInfo.Columns = GenTableColumnService.GenTableColumns(tableId);
|
genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId);
|
||||||
|
|
||||||
//var dictList = genTableInfo.Columns.FindAll(x => !string.IsNullOrEmpty(x.DictType));
|
//var dictList = genTableInfo.Columns.FindAll(x => !string.IsNullOrEmpty(x.DictType));
|
||||||
//foreach (var item in dictList)
|
//foreach (var item in dictList)
|
||||||
//{
|
//{
|
||||||
// item.DictDatas = SysDictDataService.SelectDictDataByType(item.DictType);
|
// item.DictDatas = SysDictDataService.SelectDictDataByType(item.DictType);
|
||||||
//}
|
//}
|
||||||
GenerateDto dto = new();
|
|
||||||
dto.GenTable = genTableInfo;
|
dto.GenTable = genTableInfo;
|
||||||
dto.ZipPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode");
|
dto.ZipPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode");
|
||||||
dto.GenCodePath = Path.Combine(dto.ZipPath, DateTime.Now.ToString("yyyyMMdd"));
|
dto.GenCodePath = Path.Combine(dto.ZipPath, DateTime.Now.ToString("yyyyMMdd"));
|
||||||
|
|||||||
@ -25,7 +25,7 @@ namespace ZR.Admin.WebApi.Framework
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static LoginUser GetLoginUser(HttpContext httpContext)
|
public static LoginUser GetLoginUser(HttpContext httpContext)
|
||||||
{
|
{
|
||||||
string token = HttpContextExtension.GetToken(httpContext);
|
string token = httpContext.GetToken();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(token))
|
if (!string.IsNullOrEmpty(token))
|
||||||
{
|
{
|
||||||
@ -58,7 +58,7 @@ namespace ZR.Admin.WebApi.Framework
|
|||||||
Audience = jwtSettings.Audience,
|
Audience = jwtSettings.Audience,
|
||||||
IssuedAt = authTime,//token生成时间
|
IssuedAt = authTime,//token生成时间
|
||||||
Expires = expiresAt,
|
Expires = expiresAt,
|
||||||
NotBefore = authTime,
|
//NotBefore = authTime,
|
||||||
TokenType = "Bearer",
|
TokenType = "Bearer",
|
||||||
//对称秘钥,签名证书
|
//对称秘钥,签名证书
|
||||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||||
@ -86,7 +86,8 @@ namespace ZR.Admin.WebApi.Framework
|
|||||||
ValidAudience = jwtSettings.Audience,
|
ValidAudience = jwtSettings.Audience,
|
||||||
IssuerSigningKey = new SymmetricSecurityKey(key),
|
IssuerSigningKey = new SymmetricSecurityKey(key),
|
||||||
ValidateLifetime = true,//是否验证Token有效期,使用当前时间与Token的Claims中的NotBefore和Expires对比
|
ValidateLifetime = true,//是否验证Token有效期,使用当前时间与Token的Claims中的NotBefore和Expires对比
|
||||||
RequireExpirationTime = true,//过期时间
|
ClockSkew = TimeSpan.FromSeconds(30)
|
||||||
|
//RequireExpirationTime = true,//过期时间
|
||||||
};
|
};
|
||||||
return tokenDescriptor;
|
return tokenDescriptor;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,6 +67,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Controllers\business\" />
|
<Folder Include="Controllers\business\" />
|
||||||
|
<Folder Include="DataProtection\" />
|
||||||
<Folder Include="wwwroot\export\" />
|
<Folder Include="wwwroot\export\" />
|
||||||
<Folder Include="wwwroot\Generatecode\" />
|
<Folder Include="wwwroot\Generatecode\" />
|
||||||
<Folder Include="wwwroot\uploads\" />
|
<Folder Include="wwwroot\uploads\" />
|
||||||
|
|||||||
@ -20,9 +20,11 @@ ${vueQueryFormHtml}
|
|||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button type="danger" :disabled="multiple" v-hasPermi="['${replaceDto.PermissionPrefix}:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
|
<el-button type="danger" :disabled="multiple" v-hasPermi="['${replaceDto.PermissionPrefix}:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
$if(replaceDto.ShowBtnExport)
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['${replaceDto.PermissionPrefix}:export']">导出</el-button>
|
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['${replaceDto.PermissionPrefix}:export']">导出</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
$end
|
||||||
$if(genTable.SortField != "" && 1 == 2)
|
$if(genTable.SortField != "" && 1 == 2)
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button type="info" plain icon="el-icon-edit" size="mini" @click="handleShowSort" v-hasPermi="['${replaceDto.PermissionPrefix}:update']">修改排序</el-button>
|
<el-button type="info" plain icon="el-icon-edit" size="mini" @click="handleShowSort" v-hasPermi="['${replaceDto.PermissionPrefix}:update']">修改排序</el-button>
|
||||||
@ -101,6 +103,13 @@ export default {
|
|||||||
form: {},
|
form: {},
|
||||||
// 时间范围数组
|
// 时间范围数组
|
||||||
timeRange: [],
|
timeRange: [],
|
||||||
|
columns: [
|
||||||
|
$set(index = 0)
|
||||||
|
$foreach(column in genTable.Columns)
|
||||||
|
{ index: $index, key: '${column.ColumnName}', label: `${column.ColumnComment}`, checked: $if(index < 9) true $else false $end },
|
||||||
|
$set(index = index + 1)
|
||||||
|
$end
|
||||||
|
],
|
||||||
$foreach(item in genTable.Columns)
|
$foreach(item in genTable.Columns)
|
||||||
$if((item.HtmlType == "radio" || item.HtmlType == "select" || item.HtmlType == "checkbox"))
|
$if((item.HtmlType == "radio" || item.HtmlType == "select" || item.HtmlType == "checkbox"))
|
||||||
// ${item.ColumnComment}选项列表
|
// ${item.ColumnComment}选项列表
|
||||||
|
|||||||
@ -52,6 +52,10 @@ namespace ZR.CodeGenerator
|
|||||||
replaceDto.ModelTypeName = dto.GenTable.ClassName;//表名对应C# 实体类名
|
replaceDto.ModelTypeName = dto.GenTable.ClassName;//表名对应C# 实体类名
|
||||||
replaceDto.PermissionPrefix = $"{dto.GenTable.ModuleName}:{dto.GenTable.ClassName.ToLower()}";//权限
|
replaceDto.PermissionPrefix = $"{dto.GenTable.ModuleName}:{dto.GenTable.ClassName.ToLower()}";//权限
|
||||||
replaceDto.Author = dto.GenTable.FunctionAuthor;
|
replaceDto.Author = dto.GenTable.FunctionAuthor;
|
||||||
|
replaceDto.ShowBtnAdd = dto.CheckedBtn.Any(f => f == 1);
|
||||||
|
replaceDto.ShowBtnEdit = dto.CheckedBtn.Any(f => f == 2);
|
||||||
|
replaceDto.ShowBtnDelete = dto.CheckedBtn.Any(f => f == 3);
|
||||||
|
replaceDto.ShowBtnExport = dto.CheckedBtn.Any(f => f == 4);
|
||||||
|
|
||||||
//循环表字段信息
|
//循环表字段信息
|
||||||
foreach (GenTableColumn dbFieldInfo in dto.GenTable.Columns)
|
foreach (GenTableColumn dbFieldInfo in dto.GenTable.Columns)
|
||||||
@ -262,7 +266,7 @@ namespace ZR.CodeGenerator
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(searcList[i].ToString()))
|
if (!string.IsNullOrEmpty(searcList[i].ToString()))
|
||||||
{
|
{
|
||||||
tableName = tableName.Replace(searcList[i], "");
|
tableName = tableName.Replace(searcList[i], "", StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,11 +280,11 @@ namespace ZR.CodeGenerator
|
|||||||
/// <returns>业务名</returns>
|
/// <returns>业务名</returns>
|
||||||
public static string GetBusinessName(string tableName)
|
public static string GetBusinessName(string tableName)
|
||||||
{
|
{
|
||||||
int lastIndex = tableName.IndexOf("_");//_前缀长度
|
//int firstIndex = tableName.IndexOf("_");//_前缀长度
|
||||||
int nameLength = tableName.Length;
|
//int nameLength = tableName.Length;
|
||||||
int subLength = (nameLength - lastIndex) - 1;
|
//int subLength = (nameLength - lastIndex) - 1;
|
||||||
string businessName = tableName[(lastIndex + 1)..];
|
//string businessName = tableName[(lastIndex + 1)..];
|
||||||
return businessName.Substring(0, 1).ToUpper() + tableName[1..].Replace("_", "");
|
return tableName.Substring(0, 1).ToUpper() + tableName[1..].Replace("_", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -427,9 +431,11 @@ namespace ZR.CodeGenerator
|
|||||||
options.Data.Set("replaceDto", replaceDto);
|
options.Data.Set("replaceDto", replaceDto);
|
||||||
options.Data.Set("options", dto.GenOptions);
|
options.Data.Set("options", dto.GenOptions);
|
||||||
options.Data.Set("genTable", dto.GenTable);
|
options.Data.Set("genTable", dto.GenTable);
|
||||||
|
options.Data.Set("btns", dto.CheckedBtn);
|
||||||
|
//options.Data.Set("codeTool", new CodeGeneratorTool());
|
||||||
|
options.EnableCache = true;
|
||||||
//...其它数据
|
//...其它数据
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,10 @@ namespace ZR.CodeGenerator.Model
|
|||||||
/// 生成代码的数据库类型 0、mysql 1、sqlserver
|
/// 生成代码的数据库类型 0、mysql 1、sqlserver
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int DbType { get; set; }
|
public int DbType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 生成的按钮功能
|
||||||
|
/// </summary>
|
||||||
|
public int[] CheckedBtn { get; set; }
|
||||||
public GenTable GenTable { get; set; }
|
public GenTable GenTable { get; set; }
|
||||||
public CodeGenerateOption GenOptions { get; set; }
|
public CodeGenerateOption GenOptions { get; set; }
|
||||||
#region 存储路径
|
#region 存储路径
|
||||||
|
|||||||
@ -25,7 +25,7 @@ namespace ZR.CodeGenerator.Model
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ModelTypeName { get; set; }
|
public string ModelTypeName { get; set; }
|
||||||
//vue、api
|
//vue、api
|
||||||
public string VueViewFormResetHtml { get; set; }
|
//public string VueViewFormResetHtml { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 前端列表查询html
|
/// 前端列表查询html
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -47,7 +47,10 @@ namespace ZR.CodeGenerator.Model
|
|||||||
/// 查询条件
|
/// 查询条件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string QueryCondition { get; set; } = "";
|
public string QueryCondition { get; set; } = "";
|
||||||
|
public bool ShowBtnExport { get; set; }
|
||||||
|
public bool ShowBtnAdd { get; set; }
|
||||||
|
public bool ShowBtnEdit { get; set; }
|
||||||
|
public bool ShowBtnDelete { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 上传URL data
|
/// 上传URL data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -95,10 +95,11 @@ export function updateGenTable(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 预览生成代码
|
// 预览生成代码
|
||||||
export function previewTable(tableId) {
|
export function previewTable(tableId, data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/tool/gen/preview/' + tableId,
|
url: '/tool/gen/preview/' + tableId,
|
||||||
method: 'get'
|
method: 'post',
|
||||||
|
data: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,17 +29,18 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="tableName" label="表名" sortable="custom" width="180" />
|
<el-table-column prop="tableName" label="表名" sortable="custom" width="180" />
|
||||||
<el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true"/>
|
<el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true" />
|
||||||
<el-table-column prop="className" label="实体" />
|
<el-table-column prop="className" label="实体" />
|
||||||
<el-table-column prop="createTime" label="创建时间" />
|
<el-table-column prop="createTime" label="创建时间" />
|
||||||
<el-table-column prop="updateTime" label="更新时间" />
|
<el-table-column prop="updateTime" label="更新时间" />
|
||||||
<el-table-column label="操作" align="center" width="350">
|
<el-table-column label="操作" align="center" width="350">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button type="text" icon="el-icon-view" @click="handlePreview(scope.row)" v-hasPermi="['tool:gen:preview']">预览</el-button>
|
<el-button type="text" icon="el-icon-view" @click="handleShowDialog(scope.row, 'preview')" v-hasPermi="['tool:gen:preview']">预览</el-button>
|
||||||
<el-button type="text" icon="el-icon-edit" @click="handleEditTable(scope.row)" v-hasPermi="['tool:gen:edit']">编辑</el-button>
|
<el-button type="text" icon="el-icon-edit" @click="handleEditTable(scope.row)" v-hasPermi="['tool:gen:edit']">编辑</el-button>
|
||||||
<el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['tool:gen:remove']">删除</el-button>
|
<el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['tool:gen:remove']">删除</el-button>
|
||||||
<el-button type="text" icon="el-icon-refresh" @click="handleRefresh(scope.row)" v-hasPermi="['tool:gen:refresh']">同步</el-button>
|
<!-- <el-button type="text" icon="el-icon-refresh" @click="handleRefresh(scope.row)" v-hasPermi="['tool:gen:refresh']">同步</el-button> -->
|
||||||
<el-button type="text" icon="el-icon-download" @click="handleShowDialog(scope.row)" v-hasPermi="['tool:gen:code']">生成代码</el-button>
|
<el-button type="text" icon="el-icon-download" @click="handleShowDialog(scope.row, 'generate')" v-hasPermi="['tool:gen:code']">生成代码
|
||||||
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@ -56,9 +57,24 @@
|
|||||||
</el-dialog>
|
</el-dialog>
|
||||||
<import-table ref="import" @ok="handleSearch" />
|
<import-table ref="import" @ok="handleSearch" />
|
||||||
|
|
||||||
<el-dialog :visible.sync="showGenerate" title="代码生成" width="800px">
|
<el-dialog :visible.sync="showGenerate" :title="preview.title" width="800px">
|
||||||
<el-form ref="codeGenerateForm" label-width="140px">
|
<el-form ref="codeGenerateForm" label-width="140px">
|
||||||
|
<el-form-item label="显示按钮">
|
||||||
|
<el-checkbox-group v-model="checkedBtnForm">
|
||||||
|
<el-checkbox :label="1" :disabled=true>
|
||||||
|
<el-tag type="primary">添加</el-tag>
|
||||||
|
</el-checkbox>
|
||||||
|
<el-checkbox :label="2" :disabled=true>
|
||||||
|
<el-tag type="success">修改</el-tag>
|
||||||
|
</el-checkbox>
|
||||||
|
<el-checkbox :label="3" :disabled=true>
|
||||||
|
<el-tag type="danger">删除</el-tag>
|
||||||
|
</el-checkbox>
|
||||||
|
<el-checkbox :label="4">
|
||||||
|
<el-tag type="warning">导出</el-tag>
|
||||||
|
</el-checkbox>
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="数据库类型">
|
<el-form-item label="数据库类型">
|
||||||
<el-radio v-model="dbType" :label="0">mySql</el-radio>
|
<el-radio v-model="dbType" :label="0">mySql</el-radio>
|
||||||
<el-radio v-model="dbType" :label="1">sqlServer</el-radio>
|
<el-radio v-model="dbType" :label="1">sqlServer</el-radio>
|
||||||
@ -103,7 +119,8 @@ export default {
|
|||||||
activeName: "0",
|
activeName: "0",
|
||||||
},
|
},
|
||||||
showGenerate: false,
|
showGenerate: false,
|
||||||
checkedCodeGenerateForm: [1, 2, 3, 4, 5, 6, 7, 8],
|
// 显示的button
|
||||||
|
checkedBtnForm: [1, 2, 3],
|
||||||
rules: {},
|
rules: {},
|
||||||
// 表数据
|
// 表数据
|
||||||
tableData: [],
|
tableData: [],
|
||||||
@ -151,15 +168,28 @@ export default {
|
|||||||
},
|
},
|
||||||
// 代码预览
|
// 代码预览
|
||||||
handlePreview(row) {
|
handlePreview(row) {
|
||||||
previewTable(row.tableId).then((res) => {
|
var seachdata = {
|
||||||
|
tableId: this.currentSelected.tableId,
|
||||||
|
checkedBtn: this.checkedBtnForm,
|
||||||
|
dbType: this.dbType,
|
||||||
|
};
|
||||||
|
previewTable(row.tableId, seachdata).then((res) => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
|
this.showGenerate = false;
|
||||||
this.preview.open = true;
|
this.preview.open = true;
|
||||||
this.preview.data = res.data;
|
this.preview.data = res.data;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleShowDialog(row) {
|
// 打开对话框、预览、生成
|
||||||
|
handleShowDialog(row, type) {
|
||||||
this.showGenerate = true;
|
this.showGenerate = true;
|
||||||
|
if (type == "generate") {
|
||||||
|
this.preview.title = "代码生成";
|
||||||
|
}
|
||||||
|
if (type == "preview") {
|
||||||
|
this.preview.title = "预览";
|
||||||
|
}
|
||||||
this.currentSelected = row;
|
this.currentSelected = row;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -167,6 +197,10 @@ export default {
|
|||||||
*/
|
*/
|
||||||
handleGenerate: async function () {
|
handleGenerate: async function () {
|
||||||
console.log(JSON.stringify(this.currentSelected));
|
console.log(JSON.stringify(this.currentSelected));
|
||||||
|
if (this.preview.title == "预览") {
|
||||||
|
this.handlePreview(this.currentSelected);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!this.currentSelected) {
|
if (!this.currentSelected) {
|
||||||
this.msgError("请先选择要生成代码的数据表");
|
this.msgError("请先选择要生成代码的数据表");
|
||||||
return false;
|
return false;
|
||||||
@ -184,8 +218,7 @@ export default {
|
|||||||
var seachdata = {
|
var seachdata = {
|
||||||
tableId: this.currentSelected.tableId,
|
tableId: this.currentSelected.tableId,
|
||||||
tableName: this.currentSelected.name,
|
tableName: this.currentSelected.name,
|
||||||
// genCodeFiles: this.checkedCodeGenerateForm,
|
checkedBtn: this.checkedBtnForm,
|
||||||
// coverd: this.coverd,
|
|
||||||
dbType: this.dbType,
|
dbType: this.dbType,
|
||||||
// queryColumn: this.checkedQueryColumn,
|
// queryColumn: this.checkedQueryColumn,
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user