From b81b290f7f4d97e7521003ade38efe28f2aa834d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com>
Date: Wed, 11 May 2022 13:45:00 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=A0=E5=AF=BC?=
=?UTF-8?q?=E8=88=AA=E6=9F=A5=E8=AF=A2ui?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ZR.Vue/src/views/tool/gen/editTable.vue | 67 ++++++++--------
ZR.Vue/src/views/tool/gen/genInfoForm.vue | 93 +++++++++++++----------
ZR.Vue/src/views/tool/gen/index.vue | 75 ++++++++++--------
3 files changed, 134 insertions(+), 101 deletions(-)
diff --git a/ZR.Vue/src/views/tool/gen/editTable.vue b/ZR.Vue/src/views/tool/gen/editTable.vue
index d4d4a89..accfacc 100644
--- a/ZR.Vue/src/views/tool/gen/editTable.vue
+++ b/ZR.Vue/src/views/tool/gen/editTable.vue
@@ -8,17 +8,17 @@
-
-
-
-
+
+
+
+
-
+
-
-
+
+
@@ -31,33 +31,33 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -71,12 +71,12 @@
-
+
-
+
@@ -93,10 +93,15 @@
-
+
-
+
{{ dict.dictName }}
{{ dict.dictType }}
@@ -108,7 +113,7 @@
-
+
提交
刷新
返回
@@ -128,7 +133,7 @@ export default {
name: 'genedit',
components: {
basicInfoForm,
- genInfoForm
+ genInfoForm,
},
data() {
return {
@@ -146,7 +151,7 @@ export default {
menus: [],
// 表详细信息
info: {},
- loading: true
+ loading: true,
}
},
created() {
@@ -192,7 +197,7 @@ export default {
sortField: genTable.sortField,
sortType: genTable.sortType,
checkedBtn: genTable.checkedBtn.toString(),
- permissionPrefix: genTable.permissionPrefix
+ permissionPrefix: genTable.permissionPrefix,
}
console.log('genForm', genTable)
@@ -218,7 +223,7 @@ export default {
close() {
const obj = {
path: '/tool/gen',
- query: { t: Date.now(), pageNum: this.$route.query.pageNum }
+ query: { t: Date.now(), pageNum: this.$route.query.pageNum },
}
this.$tab.closeOpenPage(obj)
},
@@ -226,9 +231,7 @@ export default {
* 排序保存
*/
sortTable(columns) {
- const el = this.$refs.dragTable.$el.querySelectorAll(
- '.el-table__body-wrapper > table > tbody'
- )[0]
+ const el = this.$refs.dragTable.$el.querySelectorAll('.el-table__body-wrapper > table > tbody')[0]
var that = this
const sortable = Sortable.create(el, {
handle: '.allowDrag',
@@ -241,7 +244,7 @@ export default {
this.$nextTick(() => {
this.columns = columns
})
- }
+ },
})
},
/**
@@ -262,14 +265,14 @@ export default {
console.warn('最后一行了')
}
}
- }
+ },
},
watch: {
columns: {
handler(val) {
this.sortTable(val)
- }
- }
- }
+ },
+ },
+ },
}
diff --git a/ZR.Vue/src/views/tool/gen/genInfoForm.vue b/ZR.Vue/src/views/tool/gen/genInfoForm.vue
index cee1e85..cccd7c4 100644
--- a/ZR.Vue/src/views/tool/gen/genInfoForm.vue
+++ b/ZR.Vue/src/views/tool/gen/genInfoForm.vue
@@ -8,7 +8,8 @@
-
+
+
@@ -70,15 +71,20 @@
-
+
-
-
+
正序
@@ -162,8 +168,12 @@
-
+
@@ -176,8 +186,12 @@
-
+
@@ -190,13 +204,17 @@
-
+
-
+
@@ -221,8 +239,10 @@
-
+
+ {{ column.csharpField }}
+ {{ column.columnComment }}
+
@@ -240,66 +260,61 @@ export default {
props: {
info: {
type: Object,
- default: null
+ default: null,
},
// 子表
tables: {
type: Array,
- default: null
+ default: null,
},
menus: {
type: Array,
- default: []
+ default: [],
},
// 列
columns: {
type: Array,
- default: []
- }
+ default: [],
+ },
},
data() {
return {
checkedBtn: [],
subColumns: [],
rules: {
- tplCategory: [
- { required: true, message: '请选择生成模板', trigger: 'blur' }
- ],
+ tplCategory: [{ required: true, message: '请选择生成模板', trigger: 'blur' }],
moduleName: [
{
required: true,
message: '请输入生成模块名',
trigger: 'blur',
- pattern: /^[A-Za-z]+$/
- }
+ pattern: /^[A-Za-z]+$/,
+ },
],
businessName: [
{
required: true,
message: '请输入生成业务名',
trigger: 'blur',
- pattern: /^[A-Za-z]+$/
- }
- ],
- functionName: [
- { required: true, message: '请输入生成功能名', trigger: 'blur' }
+ pattern: /^[A-Za-z]+$/,
+ },
],
+ functionName: [{ required: true, message: '请输入生成功能名', trigger: 'blur' }],
permissionPrefix: {
required: true,
message: '请输入权限前缀',
- trigger: 'blur'
- }
- }
+ trigger: 'blur',
+ },
+ },
}
},
watch: {
- 'info.subTableName': function(val) {
+ 'info.subTableName': function (val) {
this.setSubTableColumns(val)
},
- 'info.checkedBtn': function(val) {
- console.log(val + ',checkedBtn')
+ 'info.checkedBtn': function (val) {
this.checkedBtn = val
- }
+ },
},
methods: {
/** 转换菜单数据结构 */
@@ -310,7 +325,7 @@ export default {
return {
id: node.menuId,
label: node.menuName,
- children: node.children
+ children: node.children,
}
},
/** 选择子表名触发 */
@@ -343,7 +358,7 @@ export default {
break
}
}
- }
- }
+ },
+ },
}
diff --git a/ZR.Vue/src/views/tool/gen/index.vue b/ZR.Vue/src/views/tool/gen/index.vue
index db22125..74ae14c 100644
--- a/ZR.Vue/src/views/tool/gen/index.vue
+++ b/ZR.Vue/src/views/tool/gen/index.vue
@@ -1,6 +1,5 @@
-
@@ -16,33 +15,48 @@
导入
-
- 删除
+
+ 删除
+
-
+
- {{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}
+ {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
-
+
-
+
预览
编辑
删除
同步
- 生成代码
-
+ 生成代码
@@ -52,8 +66,15 @@
- 复制
+
+ 复制
+
@@ -63,13 +84,7 @@
From 0255b083189430477175beb0990b86de5953281e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com>
Date: Wed, 11 May 2022 13:45:19 +0800
Subject: [PATCH 2/4] add .prettierrc.js
---
ZR.Vue/.prettierrc.js | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100644 ZR.Vue/.prettierrc.js
diff --git a/ZR.Vue/.prettierrc.js b/ZR.Vue/.prettierrc.js
new file mode 100644
index 0000000..1728a06
--- /dev/null
+++ b/ZR.Vue/.prettierrc.js
@@ -0,0 +1,37 @@
+module.exports = {
+ // 一行最多 180 字符
+ printWidth: 148,
+ // 使用 2 个空格缩进
+ tabWidth: 2,
+ // 不使用缩进符,而使用空格
+ useTabs: false,
+ // 行尾不需要有分号
+ semi: false,
+ // 使用单引号
+ singleQuote: true,
+ // 对象的 key 仅在必要时用引号
+ quoteProps: 'as-needed',
+ // jsx 不使用单引号,而使用双引号
+ jsxSingleQuote: false,
+ // 末尾不需要逗号
+ trailingComma: 'all',
+ // 大括号内的首尾需要空格
+ bracketSpacing: true,
+ // jsx 标签的反尖括号需要换行
+ jsxBracketSameLine: true,
+ // 箭头函数,只有一个参数的时候,也需要括号
+ arrowParens: 'always',
+ // 每个文件格式化的范围是文件的全部内容
+ rangeStart: 0,
+ rangeEnd: Infinity,
+ // 不需要写文件开头的 @prettier
+ requirePragma: false,
+ // 不需要自动在文件开头插入 @prettier
+ insertPragma: false,
+ // 使用默认的折行标准
+ proseWrap: 'preserve',
+ // 根据显示样式决定 html 要不要折行
+ htmlWhitespaceSensitivity: 'css',
+ // 换行符使用 lf
+ endOfLine: 'auto',
+};
\ No newline at end of file
From d503970db759362960090458da53fb7cf119d127 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com>
Date: Thu, 12 May 2022 20:00:52 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=8C=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ZR.CodeGenerator/ZR.CodeGenerator.csproj | 4 ++--
ZR.Model/ZR.Model.csproj | 2 +-
ZR.Repository/ZR.Repository.csproj | 4 ++--
ZR.Tasks/ZR.Tasks.csproj | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/ZR.CodeGenerator/ZR.CodeGenerator.csproj b/ZR.CodeGenerator/ZR.CodeGenerator.csproj
index bab66bd..a44309b 100644
--- a/ZR.CodeGenerator/ZR.CodeGenerator.csproj
+++ b/ZR.CodeGenerator/ZR.CodeGenerator.csproj
@@ -11,7 +11,7 @@
-
-
+
+
diff --git a/ZR.Model/ZR.Model.csproj b/ZR.Model/ZR.Model.csproj
index 7915d47..20edbb3 100644
--- a/ZR.Model/ZR.Model.csproj
+++ b/ZR.Model/ZR.Model.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/ZR.Repository/ZR.Repository.csproj b/ZR.Repository/ZR.Repository.csproj
index e76ef0d..eefd262 100644
--- a/ZR.Repository/ZR.Repository.csproj
+++ b/ZR.Repository/ZR.Repository.csproj
@@ -11,10 +11,10 @@
-
+
-
+
diff --git a/ZR.Tasks/ZR.Tasks.csproj b/ZR.Tasks/ZR.Tasks.csproj
index 834ba93..4bdcc3f 100644
--- a/ZR.Tasks/ZR.Tasks.csproj
+++ b/ZR.Tasks/ZR.Tasks.csproj
@@ -6,8 +6,8 @@
-
-
+
+
From 8e24ac205cb2afb8a2ea952f07c6fea47fb04357 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com>
Date: Thu, 12 May 2022 21:28:27 +0800
Subject: [PATCH 4/4] =?UTF-8?q?=E7=AE=80=E5=8C=96=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E5=BA=93=E6=93=8D=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Infrastructure/OptionsSetting.cs | 8 -----
.../System/CodeGeneratorController.cs | 4 +--
ZR.Admin.WebApi/Extensions/DbExtension.cs | 32 +++++++++----------
ZR.Admin.WebApi/appsettings.json | 9 ++----
ZR.Repository/BaseRepository.cs | 24 ++++++--------
5 files changed, 31 insertions(+), 46 deletions(-)
diff --git a/Infrastructure/OptionsSetting.cs b/Infrastructure/OptionsSetting.cs
index c01060c..3c88ce3 100644
--- a/Infrastructure/OptionsSetting.cs
+++ b/Infrastructure/OptionsSetting.cs
@@ -6,13 +6,6 @@ namespace Infrastructure
///
public class OptionsSetting
{
- public static string ConnAdmin = "conn_zrAdmin";
- public static string ConnDbType = "conn_zrAdmin_type";
- public static string ConnBus = "conn_bus";
- public static string ConnBusDbType = "conn_bus_type";
-
- public string Redis { get; set; }
- public string Database { get; set; }
///
/// 是否演示模式
///
@@ -37,7 +30,6 @@ namespace Infrastructure
///
public class Upload
{
- public string UploadDirectory { get; set; }
public string UploadUrl { get; set; }
}
///
diff --git a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs
index 4b3ed0d..c2590d7 100644
--- a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs
+++ b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs
@@ -237,7 +237,7 @@ namespace ZR.Admin.WebApi.Controllers
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId);
- dto.DbType = AppSettings.GetAppConfig(OptionsSetting.ConnBusDbType, 0);
+ dto.DbType = AppSettings.GetAppConfig("gen:dbType", 0);
dto.GenTable = genTableInfo;
dto.IsPreview = true;
//生成代码
@@ -263,7 +263,7 @@ namespace ZR.Admin.WebApi.Controllers
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId);
- dto.DbType = AppSettings.GetAppConfig(OptionsSetting.ConnBusDbType, 0);
+ dto.DbType = AppSettings.GetAppConfig("gen:dbType", 0);
dto.GenTable = genTableInfo;
//自定义路径
if (genTableInfo.GenType == "1")
diff --git a/ZR.Admin.WebApi/Extensions/DbExtension.cs b/ZR.Admin.WebApi/Extensions/DbExtension.cs
index 7228e83..4183a03 100644
--- a/ZR.Admin.WebApi/Extensions/DbExtension.cs
+++ b/ZR.Admin.WebApi/Extensions/DbExtension.cs
@@ -26,43 +26,43 @@ namespace ZR.Admin.WebApi.Extensions
public static void AddDb(IConfiguration Configuration)
{
- string connStr = Configuration.GetConnectionString(OptionsSetting.ConnAdmin);
- string connStrBus = Configuration.GetConnectionString(OptionsSetting.ConnBus);
-
- int dbType = Convert.ToInt32(Configuration[OptionsSetting.ConnDbType]);
- int dbType_bus = Convert.ToInt32(Configuration[OptionsSetting.ConnBusDbType]);
+ string connStr = Configuration.GetConnectionString("conn_db");
+ int dbType = Convert.ToInt32(Configuration["conn_db_dbtype"]);
SugarIocServices.AddSqlSugar(new List() {
new IocConfig() {
- ConfigId = "0",
+ ConfigId = "0",//默认db
ConnectionString = connStr,
DbType = (IocDbType)dbType,
IsAutoCloseConnection = true
- }, new IocConfig() {
+ },
+ new IocConfig() {
ConfigId = "1",
- ConnectionString = connStrBus,
- DbType = (IocDbType)dbType_bus,
+ ConnectionString = "替换成你的字符串",
+ DbType = IocDbType.MySql,
IsAutoCloseConnection = true
}
+ //...增加其他数据库
});
SugarIocServices.ConfigurationSugar(db =>
{
+ //db0数据过滤
FilterData(0);
- //FilterData(1);
+
#region db0
- db.GetConnection(0).Aop.OnLogExecuting = (sql, pars) =>
+ db.GetConnectionScope(0).Aop.OnLogExecuting = (sql, pars) =>
{
- var param = db.GetConnection(0).Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value));
+ var param = db.GetConnectionScope(0).Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value));
logger.Info($"【sql语句】{sql},{param}\n");
};
- db.GetConnection(0).Aop.OnError = (e) =>
+ db.GetConnectionScope(0).Aop.OnError = (e) =>
{
logger.Error(e, $"执行SQL出错:{e.Message}");
};
//SQL执行完
- db.GetConnection(0).Aop.OnLogExecuted = (sql, pars) =>
+ db.GetConnectionScope(0).Aop.OnLogExecuted = (sql, pars) =>
{
//执行完了可以输出SQL执行时间 (OnLogExecutedDelegate)
};
@@ -86,7 +86,7 @@ namespace ZR.Admin.WebApi.Extensions
}
///
- /// 分页获取count 不会追加sql
+ /// 数据过滤
///
/// 多库id
private static void FilterData(int configId)
@@ -98,7 +98,7 @@ namespace ZR.Admin.WebApi.Extensions
if (user == null) return;
//管理员不过滤
if (user.RoleIds.Any(f => f.Equals("admin"))) return;
- var db = DbScoped.SugarScope.GetConnection(configId);
+ var db = DbScoped.SugarScope.GetConnectionScope(configId);
foreach (var role in user.Roles.OrderBy(f => f.DataScope))
{
string dataScope = role.DataScope;
diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json
index 0421a75..d9f765b 100644
--- a/ZR.Admin.WebApi/appsettings.json
+++ b/ZR.Admin.WebApi/appsettings.json
@@ -7,21 +7,18 @@
}
},
"ConnectionStrings": {
- "conn_zrAdmin": "server=LAPTOP-STKF2M8H\\SQLEXPRESS;uid=sa;pwd=zradmin123;database=ZrAdmin;Trusted_Connection=SSPI",
- "conn_bus": "server=LAPTOP-STKF2M8H\\SQLEXPRESS;uid=zr;pwd=zradmin123;database=ZrAdmin;Trusted_Connection=SSPI"
+ "conn_db": "server=LAPTOP-STKF2M8H\\SQLEXPRESS;uid=sa;pwd=zradmin123;database=ZrAdmin;Trusted_Connection=SSPI"
},
- "conn_zrAdmin_type": 1, //MySql = 0, SqlServer = 1
- "conn_bus_type": 1,
+ "conn_db_dbtype": 1, //ݿ MySql = 0, SqlServer = 1
"urls": "http://localhost:8888", //ĿurlĶ˿ǰ˶ӦdevServerҲҪ
"corsUrls": "http://localhost:8887", //ַǰĿǰ˷뵥Ҫã","
"JwtSettings": {
"Issuer": "ZRAdmin.NET",
"Audience": "ZRAdmin.NET",
"SecretKey": "SecretKey-ZRADMIN.NET-20210101",
- "Expire": 30//jwt¼ʱ䣨֣
+ "Expire": 1440 //jwt¼ʱ䣨֣
},
"DemoMode": false, //Ƿʾģʽ
- "DbKey": "", //ݿkey
"Upload": {
"UploadUrl": "http://localhost:8888"
},
diff --git a/ZR.Repository/BaseRepository.cs b/ZR.Repository/BaseRepository.cs
index c10ef49..16abe27 100644
--- a/ZR.Repository/BaseRepository.cs
+++ b/ZR.Repository/BaseRepository.cs
@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
+using System.Reflection;
using ZR.Model;
namespace ZR.Repository
@@ -18,22 +19,17 @@ namespace ZR.Repository
public BaseRepository(ISqlSugarClient context = null) : base(context)
{
//通过特性拿到ConfigId
- //var configId = typeof(T).GetCustomAttribute()?.configId;
- //if (configId != null)
- //{
- // itenant = DbScoped.SugarScope;//设置租户接口
- // Context = DbScoped.SugarScope.GetConnection(configId);
- //}
- //else
- //{
- // Context = context ?? DbScoped.SugarScope.GetConnection(1);//根据类传入的ConfigId自动选择
- //}
- Context = DbScoped.SugarScope.GetConnectionWithAttr();
- itenant = DbScoped.SugarScope;//设置租户接口
- if (Context == null)
+ var configId = typeof(T).GetCustomAttribute()?.configId;
+ if (configId != null)
{
- Context = DbScoped.SugarScope.GetConnection(1);//根据类传入的ConfigId自动选择
+ Context = DbScoped.SugarScope.GetConnectionScope(configId);//根据类传入的ConfigId自动选择
}
+ else
+ {
+ Context = context ?? DbScoped.SugarScope.GetConnectionScope(0);//没有默认db0
+ }
+ //Context = DbScoped.SugarScope.GetConnectionScopeWithAttr();
+ itenant = DbScoped.SugarScope;//设置租户接口
}
#region add