开发代码生成功能
This commit is contained in:
parent
23187ed8c5
commit
c1e014a5d0
@ -22,6 +22,12 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
|
||||
protected IActionResult ToRespose(ResultCode resultCode, object data = null)
|
||||
{
|
||||
string jsonStr = GetJsonStr(GetApiResult(resultCode, data), "");
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// json输出带时间格式的
|
||||
/// </summary>
|
||||
@ -40,10 +46,6 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
protected string SerializeObject(object obj)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 响应返回结果
|
||||
|
||||
60
ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs
Normal file
60
ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model;
|
||||
using ZR.Model.CodeGenerator;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成
|
||||
/// </summary>
|
||||
[Route("codeGenerator")]
|
||||
public class CodeGeneratorController : BaseController
|
||||
{
|
||||
public ICodeGeneratorService CodeGeneratorService;
|
||||
public CodeGeneratorController(ICodeGeneratorService codeGeneratorService)
|
||||
{
|
||||
CodeGeneratorService = codeGeneratorService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有数据库的信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetListDataBase")]
|
||||
//[YuebonAuthorize("GetListDataBase")]
|
||||
//[NoPermissionRequired]
|
||||
public IActionResult GetListDataBase()
|
||||
{
|
||||
List<DataBaseInfo> listTable = CodeGeneratorService.GetAllDataBases("SqlServer");
|
||||
|
||||
return SUCCESS(listTable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///获取所有表根据数据名
|
||||
/// </summary>
|
||||
/// <param name="enCode">数据库名</param>
|
||||
/// <param name="keywords">表名</param>
|
||||
/// <param name="pagerInfo">分页信息</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("FindListTable")]
|
||||
public IActionResult FindListTable(string enCode, string keywords, PagerInfo pagerInfo)
|
||||
{
|
||||
if (string.IsNullOrEmpty(enCode))
|
||||
{
|
||||
return ToRespose(ResultCode.PARAM_ERROR);
|
||||
}
|
||||
List<DbTableInfo> listTable = CodeGeneratorService.GetTablesWithPage(keywords, enCode, pagerInfo);
|
||||
|
||||
return SUCCESS(listTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,6 +18,7 @@
|
||||
"DemoMode": false, //是否演示模式
|
||||
"DbKey": "",
|
||||
"DbType": 0, //MySql = 0, SqlServer = 1, Sqlite = 2, Oracle = 3, PostgreSQL = 4,
|
||||
"CodeGenDbType": 0,//代码生成数据库类型
|
||||
"Upload": {
|
||||
"UploadDirectory": "/",
|
||||
"UploadUrl": "http://localhost:8888"
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
"DemoMode": false, //是否演示模式
|
||||
"DbKey": "",
|
||||
"DbType": 0, //MySql = 0, SqlServer = 1, Sqlite = 2, Oracle = 3, PostgreSQL = 4,
|
||||
"CodeGenDbType": 0, //代码生成数据库类型
|
||||
"Upload": {
|
||||
"UploadDirectory": "/",
|
||||
"UploadUrl": "http://localhost:8888"
|
||||
|
||||
14
ZR.Model/CodeGenerator/DataBaseInfo.cs
Normal file
14
ZR.Model/CodeGenerator/DataBaseInfo.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.CodeGenerator
|
||||
{
|
||||
public class DataBaseInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据库名称
|
||||
/// </summary>
|
||||
public string DbName { get; set; }
|
||||
}
|
||||
}
|
||||
78
ZR.Model/CodeGenerator/DbFieldInfo.cs
Normal file
78
ZR.Model/CodeGenerator/DbFieldInfo.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 表的字段
|
||||
/// </summary>
|
||||
public class DbFieldInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public DbFieldInfo()
|
||||
{
|
||||
FieldName = string.Empty;
|
||||
Description = string.Empty;
|
||||
}
|
||||
/// <summary>
|
||||
/// 字段名称
|
||||
/// </summary>
|
||||
public string FieldName { get; set; }
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// 系统数据类型,如 int
|
||||
/// </summary>
|
||||
public string DataType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据库里面存放的类型。
|
||||
/// </summary>
|
||||
public string FieldType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 代表小数位精度。
|
||||
/// </summary>
|
||||
public long? FieldScale { get; set; }
|
||||
/// <summary>
|
||||
/// 数据精度,仅数字类型有效,总共多少位数字(10进制)。
|
||||
/// 在MySql里面代表了字段长度
|
||||
/// </summary>
|
||||
public long? FieldPrecision { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public long? FieldMaxLength { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 可空
|
||||
/// </summary>
|
||||
public bool IsNullable { get; set; }
|
||||
/// <summary>
|
||||
/// 是否为主键字段
|
||||
/// </summary>
|
||||
public bool IsIdentity { get; set; }
|
||||
/// <summary>
|
||||
/// 【未用上】该字段是否自增
|
||||
/// </summary>
|
||||
public bool Increment { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 默认值
|
||||
/// </summary>
|
||||
public string FieldDefaultValue { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
75
ZR.Model/CodeGenerator/DbTableInfo.cs
Normal file
75
ZR.Model/CodeGenerator/DbTableInfo.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据表的信息
|
||||
/// </summary>
|
||||
public class DbTableInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 表格ID,表的名称。
|
||||
/// </summary>
|
||||
public string TableName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 表的别称,或者描述
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// 字段列表
|
||||
/// </summary>
|
||||
public List<DbFieldInfo> Fileds { get; set; }
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public DbTableInfo()
|
||||
{
|
||||
Fileds = new List<DbFieldInfo>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取主键的名称列表。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<string> GetIdentityList()
|
||||
{
|
||||
var list = Fileds.Where(x => x.IsIdentity);
|
||||
if (list == null) return null;
|
||||
return list.Select(x => x.FieldName).ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取主键字段列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DbFieldInfo> GetIdentityFields()
|
||||
{
|
||||
var list = Fileds.Where(x => x.IsIdentity);
|
||||
if (list == null) return null;
|
||||
return list.ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取可空字段。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DbFieldInfo> GetIsNullableFields()
|
||||
{
|
||||
var list = Fileds.Where(x => x.IsNullable);
|
||||
if (list == null) return null;
|
||||
return list.ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取不可空字段。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DbFieldInfo> GetNotNullableFields()
|
||||
{
|
||||
var list = Fileds.Where(x => !x.IsNullable);
|
||||
if (list == null) return null;
|
||||
return list.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
34
ZR.Repository/System/CodeGeneratorRepository.cs
Normal file
34
ZR.Repository/System/CodeGeneratorRepository.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model;
|
||||
using ZR.Model.CodeGenerator;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class CodeGeneratorRepository: BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取数据库信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DataBaseInfo> GetAllDataBaseInfos()
|
||||
{
|
||||
return Db.Ado.SqlQuery<DataBaseInfo>("select name as DbName from master..sysdatabases ");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DbTableInfo> GetAllTables(string dbName)
|
||||
{
|
||||
string sql = $"SELECT name as TableName FROM {dbName}..SysObjects Where XType='U' ORDER BY Name";
|
||||
return Db.Ado.SqlQuery<DbTableInfo>(sql, new { dbName});
|
||||
}
|
||||
}
|
||||
}
|
||||
17
ZR.Service/IService/ICodeGeneratorService.cs
Normal file
17
ZR.Service/IService/ICodeGeneratorService.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model;
|
||||
using ZR.Model.CodeGenerator;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
{
|
||||
public interface ICodeGeneratorService
|
||||
{
|
||||
List<DataBaseInfo> GetAllDataBases(string dbType);
|
||||
|
||||
List<DbTableInfo> GetTablesWithPage(string tablename, string dbName, PagerInfo info);
|
||||
}
|
||||
}
|
||||
67
ZR.Service/System/CodeGeneratorService.cs
Normal file
67
ZR.Service/System/CodeGeneratorService.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model;
|
||||
using ZR.Model.CodeGenerator;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ICodeGeneratorService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class CodeGeneratorService: ICodeGeneratorService
|
||||
{
|
||||
public CodeGeneratorRepository CodeGeneratorRepository;
|
||||
|
||||
public CodeGeneratorService(CodeGeneratorRepository codeGeneratorRepository)
|
||||
{
|
||||
CodeGeneratorRepository = codeGeneratorRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有数据库名
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DataBaseInfo> GetAllDataBases(string dbType)
|
||||
{
|
||||
List<DataBaseInfo> list = new List<DataBaseInfo>();
|
||||
if (dbType.Contains("SqlServer"))
|
||||
{
|
||||
list = CodeGeneratorRepository.GetAllDataBaseInfos();
|
||||
}
|
||||
else if (dbType.Contains("MySql"))
|
||||
{
|
||||
// list = mssqlExtractor.GetAllDataBases();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesWithPage(string tablename, string dbName, PagerInfo info)
|
||||
{
|
||||
var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType");
|
||||
List<DbTableInfo> list = new List<DbTableInfo>();
|
||||
if (dbType == "1")
|
||||
{
|
||||
list = CodeGeneratorRepository.GetAllTables(dbName);
|
||||
}
|
||||
else if (dbType.Contains("MySql"))
|
||||
{
|
||||
//list = mysqlExtractor.GetAllTables(this.dbName, tablename, fieldNameToSort, isDescending, info);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(tablename))
|
||||
{
|
||||
list = list.Where(f => f.TableName.Contains(tablename)).ToList();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -74,3 +74,67 @@ export function synchDb(tableName) {
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**新的代码生成 */
|
||||
|
||||
/**
|
||||
* 创建数据库连接
|
||||
*/
|
||||
export function createGetDBConn(data) {
|
||||
return request({
|
||||
url: 'CodeGenerator/CreateDBConn',
|
||||
method: 'post',
|
||||
data: data,
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取数据库
|
||||
*/
|
||||
export function codeGetDBList() {
|
||||
return request({
|
||||
url: 'CodeGenerator/GetListDataBase',
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取数据库表
|
||||
*/
|
||||
export function codeGetTableList(data) {
|
||||
return request({
|
||||
url: 'CodeGenerator/FindListTable',
|
||||
method: 'get',
|
||||
params: data,
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 生成代码
|
||||
*/
|
||||
export async function codeGenerator(data) {
|
||||
return await request({
|
||||
url: 'CodeGenerator/Generate',
|
||||
method: 'get',
|
||||
params: data,
|
||||
timeout: 0,
|
||||
})
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 数据库解密
|
||||
*/
|
||||
export function dbtoolsConnStrDecrypt(data) {
|
||||
return request({
|
||||
url: 'DbTools/ConnStrDecrypt',
|
||||
method: 'post',
|
||||
params: data,
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 数据库加密
|
||||
*/
|
||||
export function dbtoolsConnStrEncrypt(data) {
|
||||
return request({
|
||||
url: 'DbTools/ConnStrEncrypt',
|
||||
method: 'post',
|
||||
params: data,
|
||||
})
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ export default {
|
||||
name: "你好",
|
||||
userId: 1000001,
|
||||
sortId: 1,
|
||||
address: "浙江省杭州市西湖区",
|
||||
address: "",
|
||||
content: "我是一个超长超长的文字啊",
|
||||
addtime: "2021-8-7 23:00:00",
|
||||
},
|
||||
|
||||
300
ZR.Vue/src/views/tool/index.vue
Normal file
300
ZR.Vue/src/views/tool/index.vue
Normal file
@ -0,0 +1,300 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<!-- <div class="filter-container">
|
||||
<el-card>
|
||||
<el-form ref="searchDbform" :inline="true" :model="searchform" class="demo-form-inline" size="small">
|
||||
<el-form-item label="数据库地址" prop="DbAddress">
|
||||
<el-input v-model="searchDbform.DbAddress" placeholder="请输入数据库地址" autocomplete="off" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="数据库名称" prop="DbName">
|
||||
<el-input v-model="searchDbform.DbName" placeholder="请输入数据库名称" autocomplete="off" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户名" prop="DbUserName">
|
||||
<el-input v-model="searchDbform.DbUserName" placeholder="请输入用户名" autocomplete="off" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="访问密码" prop="DbPassword">
|
||||
<el-input v-model="searchDbform.DbPassword" placeholder="请输入访问密码" autocomplete="off" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="数据库类型" prop="DbType">
|
||||
<el-select v-model="searchDbform.DbType" clearable placeholder="请选数据库类型">
|
||||
<el-option v-for="item in selectDbTypes" :key="item.Id" :label="item.Title" :value="item.Id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="数据库端口" prop="DbPort">
|
||||
<el-input v-model="searchDbform.DbPort" placeholder="请输入数据库端口" autocomplete="off" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleDbConn()">链接</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div> -->
|
||||
<el-card>
|
||||
<div class="list-btn-container">
|
||||
<el-form ref="codeform" :inline="true" :rules="rules" :model="codeform" class="demo-form-inline" size="small">
|
||||
<el-form-item label="数据库">
|
||||
<el-tooltip class="item" effect="dark" content="默认为系统访问数据库" placement="top">
|
||||
<el-select v-model="searchform.DbName" clearable placeholder="请选择" @change="handleShowTable">
|
||||
<el-option v-for="item in selectedDataBase" :key="item.Id" :label="item.dbName" :value="item.dbName" />
|
||||
</el-select>
|
||||
</el-tooltip>
|
||||
</el-form-item>
|
||||
<el-form-item label="数据库表名">
|
||||
<el-input v-model="searchform.tableName" clearable placeholder="输入要查询的表名" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleSearch()">查询</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item label="项目命名空间:" prop="baseSpace">
|
||||
<el-tooltip class="item" effect="dark" content="系统会根据项目命名空间自动生成IService、Service、Models等子命名空间" placement="top">
|
||||
<el-input v-model="codeform.baseSpace" clearable placeholder="如Yuebon.WMS" />
|
||||
</el-tooltip>
|
||||
</el-form-item>
|
||||
<el-form-item label="去掉表名前缀:">
|
||||
<el-tooltip class="item" effect="dark" content="表名直接变为类名,去掉表名前缀。多个前缀用“;”隔开和结束" placement="top">
|
||||
<el-input v-model="codeform.replaceTableNameStr" clearable width="300" placeholder="多个前缀用“;”隔开" />
|
||||
</el-tooltip>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="iconfont icon-code" @click="handleGenerate()">生成代码</el-button>
|
||||
<el-button type="default" icon="el-icon-refresh" size="small" @click="loadTableData()">刷新</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<el-table ref="gridtable" v-loading="tableloading" :data="tableData" border stripe highlight-current-row style="width: 100%" :default-sort="{prop: 'TableName', order: 'ascending'}" @select="handleSelectChange" @select-all="handleSelectAllChange" @sort-change="handleSortChange">
|
||||
<el-table-column type="selection" width="50" />
|
||||
<el-table-column prop="tableName" label="表名" sortable="custom" width="380" />
|
||||
<el-table-column prop="description" label="表描述" />
|
||||
</el-table>
|
||||
<div class="pagination-container">
|
||||
<el-pagination background :current-page="pagination.pageNum" :page-sizes="[5,10,20,50,100, 200, 300, 400]" :page-size="pagination.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.pageTotal" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
createGetDBConn,
|
||||
codeGetDBList,
|
||||
codeGetTableList,
|
||||
codeGenerator,
|
||||
} from "@/api/tool/gen";
|
||||
import { downloadFile } from "@/utils/index";
|
||||
import { Loading } from "element-ui";
|
||||
|
||||
import defaultSettings from "@/settings";
|
||||
export default {
|
||||
name: "CodeGenerator",
|
||||
data() {
|
||||
return {
|
||||
searchDbform: {
|
||||
DbName: "",
|
||||
DbAddress: "",
|
||||
DbPort: "1433",
|
||||
DbUserName: "",
|
||||
DbPassword: "",
|
||||
DbType: "",
|
||||
},
|
||||
searchform: {
|
||||
DbName: "",
|
||||
tableName: "",
|
||||
},
|
||||
codeform: {
|
||||
baseSpace: "",
|
||||
replaceTableNameStr: "",
|
||||
},
|
||||
rules: {
|
||||
baseSpace: [
|
||||
{ required: true, message: "请输入项目名称", trigger: "blur" },
|
||||
{
|
||||
min: 2,
|
||||
max: 50,
|
||||
message: "长度在 2 到 50 个字符",
|
||||
trigger: "blur",
|
||||
},
|
||||
],
|
||||
replaceTableNameStr: [
|
||||
{ min: 0, max: 50, message: "长度小于50个字符", trigger: "blur" },
|
||||
],
|
||||
},
|
||||
selectDbTypes: [
|
||||
{
|
||||
Id: "SqlServer",
|
||||
Title: "SqlServer",
|
||||
},
|
||||
{
|
||||
Id: "MySql",
|
||||
Title: "MySql",
|
||||
},
|
||||
],
|
||||
tableData: [],
|
||||
tableloading: true,
|
||||
pagination: {
|
||||
pageNum: 1,
|
||||
pagesize: 20,
|
||||
pageTotal: 0,
|
||||
},
|
||||
sortableData: {
|
||||
order: "",
|
||||
sort: "",
|
||||
},
|
||||
currentSelected: [],
|
||||
selectedDataBase: [],
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.pagination.pageNum = 1;
|
||||
this.loadData();
|
||||
this.loadTableData();
|
||||
},
|
||||
methods: {
|
||||
loadData: function () {
|
||||
codeGetDBList().then((res) => {
|
||||
this.selectedDataBase = res.data;
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 加载页面table数据
|
||||
*/
|
||||
loadTableData: function () {
|
||||
if (this.searchform.dataBaseName !== "") {
|
||||
this.tableloading = true;
|
||||
var seachdata = {
|
||||
pageNum: this.pagination.pageNum,
|
||||
PageSize: this.pagination.pagesize,
|
||||
Keywords: this.searchform.tableName,
|
||||
EnCode: this.searchform.DbName,
|
||||
// Order: this.sortableData.order,
|
||||
// Sort: this.sortableData.sort,
|
||||
};
|
||||
codeGetTableList(seachdata).then((res) => {
|
||||
this.tableData = res.data;
|
||||
this.pagination.pageTotal = res.data.totalNum;
|
||||
this.tableloading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 点击查询
|
||||
*/
|
||||
handleSearch: function () {
|
||||
this.pagination.pageNum = 1;
|
||||
this.loadTableData();
|
||||
},
|
||||
handleShowTable: function () {
|
||||
this.pagination.pageNum = 1;
|
||||
// this.loadTableData();
|
||||
},
|
||||
handleDbConn: function () {
|
||||
var dataInfo = {
|
||||
DbAddress: this.searchDbform.DbAddress,
|
||||
DbPort: this.searchDbform.DbPort,
|
||||
DbName: this.searchDbform.DbName,
|
||||
DbUserName: this.searchDbform.DbUserName,
|
||||
DbPassword: this.searchDbform.DbPassword,
|
||||
DbType: this.searchDbform.DbType,
|
||||
};
|
||||
createGetDBConn(dataInfo).then((res) => {
|
||||
this.selectedDataBase = res.ResData;
|
||||
this.searchform.DbName = this.searchDbform.DbName;
|
||||
});
|
||||
this.pagination.pageNum = 1;
|
||||
this.loadTableData();
|
||||
},
|
||||
/**
|
||||
* 点击生成服务端代码
|
||||
*/
|
||||
handleGenerate: async function () {
|
||||
if (this.currentSelected.length === 0) {
|
||||
this.$alert("请先选择要生成代码的数据表", "提示");
|
||||
return false;
|
||||
} else {
|
||||
this.$refs["codeform"].validate((valid) => {
|
||||
if (valid) {
|
||||
var loadop = {
|
||||
lock: true,
|
||||
text: "正在生成代码...",
|
||||
spinner: "el-icon-loading",
|
||||
background: "rgba(0, 0, 0, 0.7)",
|
||||
};
|
||||
const pageLoading = Loading.service(loadop);
|
||||
var currentTables = "";
|
||||
this.currentSelected.forEach((element) => {
|
||||
currentTables += element.TableName + ",";
|
||||
});
|
||||
var seachdata = {
|
||||
tables: currentTables,
|
||||
baseSpace: this.codeform.baseSpace,
|
||||
replaceTableNameStr: this.codeform.replaceTableNameStr,
|
||||
};
|
||||
codeGenerator(seachdata)
|
||||
.then((res) => {
|
||||
if (res.Success) {
|
||||
downloadFile(
|
||||
defaultSettings.fileUrl + res.ResData[0],
|
||||
res.ResData[1]
|
||||
);
|
||||
this.$message({
|
||||
message: "恭喜你,代码生成完成!",
|
||||
type: "success",
|
||||
});
|
||||
} else {
|
||||
this.$message({
|
||||
message: res.ErrMsg,
|
||||
type: "error",
|
||||
});
|
||||
}
|
||||
pageLoading.close();
|
||||
})
|
||||
.catch((erre) => {
|
||||
pageLoading.close();
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 当表格的排序条件发生变化的时候会触发该事件
|
||||
*/
|
||||
handleSortChange: function (column) {
|
||||
this.sortableData.sort = column.prop;
|
||||
if (column.order === "ascending") {
|
||||
this.sortableData.order = "asc";
|
||||
} else {
|
||||
this.sortableData.order = "desc";
|
||||
}
|
||||
this.loadTableData();
|
||||
},
|
||||
/**
|
||||
* 当用户手动勾选checkbox数据行事件
|
||||
*/
|
||||
handleSelectChange: function (selection, row) {
|
||||
this.currentSelected = selection;
|
||||
},
|
||||
/**
|
||||
* 当用户手动勾选全选checkbox事件
|
||||
*/
|
||||
handleSelectAllChange: function (selection) {
|
||||
this.currentSelected = selection;
|
||||
},
|
||||
/**
|
||||
* 选择每页显示数量
|
||||
*/
|
||||
handleSizeChange(val) {
|
||||
this.pagination.pagesize = val;
|
||||
this.pagination.pageNum = 1;
|
||||
this.loadTableData();
|
||||
},
|
||||
/**
|
||||
* 选择当页面
|
||||
*/
|
||||
handleCurrentChange(val) {
|
||||
this.pagination.pageNum = val;
|
||||
this.loadTableData();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
20
ZRAdmin.xml
20
ZRAdmin.xml
@ -27,6 +27,26 @@
|
||||
<param name="data"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:ZR.Admin.WebApi.Controllers.CodeGeneratorController">
|
||||
<summary>
|
||||
代码生成
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.CodeGeneratorController.GetListDataBase">
|
||||
<summary>
|
||||
获取所有数据库的信息
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.CodeGeneratorController.FindListTable(System.String,System.String,ZR.Model.PagerInfo)">
|
||||
<summary>
|
||||
获取所有表根据数据名
|
||||
</summary>
|
||||
<param name="enCode">数据库名</param>
|
||||
<param name="keywords">表名</param>
|
||||
<param name="pagerInfo">分页信息</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.HomeController.Health">
|
||||
<summary>
|
||||
心跳
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user