Commit e7c62d23 by jianshuqin

优化:组件功能

parent 94e2bd0d
......@@ -30,7 +30,7 @@ namespace Bailun.DC.Models.Component.Enum
}
/// <summary>
/// 列名类型:1:Api,2:Sql,3:数据库表或视图,4:动态SQL,5:储存过程
/// 列名类型:1:Api,2:Sql,3:数据库表或视图,4:动态SQL,5:储存过程,6:储存过程名称
/// </summary>
public enum DataTypeEnum
{
......@@ -63,5 +63,11 @@ namespace Bailun.DC.Models.Component.Enum
/// </summary>
[Description("储存过程")]
ExecuteSql = 5,
/// <summary>
/// 储存过程名称
/// </summary>
[Description("储存过程名称")]
ExecuteName = 6
}
}
......@@ -106,7 +106,7 @@ namespace Bailun.DC.Services.Component
//过虑条件SQL
this.GetFilterSql(queryFilter, ref sqlparam);
//查询
using (var db = (entity.DataDB == DBEnum.DataWareHouse ? DW_DB : DB))
using (MySqlConnection db = this.GetDbConnection(entity))
{
list = DB.Query<dynamic>(entity.ColumnValue, sqlparam).ToList();
}
......@@ -374,33 +374,22 @@ namespace Bailun.DC.Services.Component
}
}
}
*/
break;
#endregion
#region 储存过程
case (int)DataTypeEnum.ExecuteSql:
recordId = this.RecordId;
string laolaoView = RecordHelper.AttendeesLaoLaoView;
string onlineBaseURL = ConfigurationManager.AppSettings["OnlineBaseURL"]?.ToLower();
case DataTypeEnum.ExecuteSql:
/*
startRecord = startRecord < 0 && query?.StartRecord > 0 ? query.StartRecord : (startRecord > 0 ? startRecord : 1);
recordCount = recordCount < 0 && query?.RecordCount > 0 ? query.RecordCount : (recordCount > 0 ? recordCount : null);
offset = (startRecord.Value - 1) * (recordCount ?? 0);
fetch = recordCount > 0 ? recordCount.Value : int.MaxValue;
//排序条件SQL
orderbySql = this.GetOrderBySql(query, code, entity.TableOrderBy);
//执行方式
switch (entity.DataMethod)
{
case (int)MethodEnum.Value:
sqlParameter = new List<SqlParameter>();
//过虑条件SQL
whereSql = this.GetFilterSql(query, ref sqlParameter, "''' +", "+'''", "'");
//替换研讨会ID
sqlParameter.Add(new SqlParameter() { ParameterName = "@RECORD_ID", Value = recordId });
sqlParameter.Add(new SqlParameter() { ParameterName = "@ATTENDEESTABLENAME", Value = laolaoView });
sqlParameter.Add(new SqlParameter() { ParameterName = "@ONLINEBASEURL", Value = onlineBaseURL });
sqlParameter.Add(new SqlParameter() { ParameterName = "@ORDER_BY", Value = orderbySql });
sqlParameter.Add(new SqlParameter() { ParameterName = "@OFFSET", Value = offset.ToString() });
sqlParameter.Add(new SqlParameter() { ParameterName = "@FETCH", Value = fetch.ToString() });
......@@ -408,8 +397,6 @@ namespace Bailun.DC.Services.Component
sql = entity.DataValue;
//替换SQL参数
//sql = Regex.Replace(entity.DataValue, "@ATTENDEESTABLENAME", laolaoView, RegexOptions.IgnoreCase);
//sql = Regex.Replace(sql, "@ONLINEBASEURL", onlineBaseURL, RegexOptions.IgnoreCase);
//sql = Regex.Replace(sql, "@ORDER_BY", orderbySql, RegexOptions.IgnoreCase);
//sql = Regex.Replace(sql, "@OFFSET", offset.ToString(), RegexOptions.IgnoreCase);
//sql = Regex.Replace(sql, "@FETCH", fetch.ToString(), RegexOptions.IgnoreCase);
......@@ -423,8 +410,13 @@ namespace Bailun.DC.Services.Component
pageList.List = ds.Tables[1];
}
}
*/
break;
case (int)MethodEnum.Name:
#endregion
#region 储存过程名称
case DataTypeEnum.ExecuteName:
/*
using (var dbContext = this.DbContext)
{
IList<string> listParameter = this.GetSpParameters(entity.DataValue);
......@@ -455,8 +447,6 @@ namespace Bailun.DC.Services.Component
pageList.List = ds.Tables[1];
}
}
break;
}
*/
break;
#endregion
......@@ -756,6 +746,24 @@ namespace Bailun.DC.Services.Component
return sql;
}
private MySqlConnection GetDbConnection(TableDTO entity)
{
MySqlConnection db = default(MySqlConnection);
switch (entity.DataDB)
{
case DBEnum.DataWareHouse:
db = DW_DB;
break;
case DBEnum.Pro:
db = PRO_DB;
break;
default:
db = DB;
break;
}
return db;
}
private (int, IDataReader) GetListDataReader(QueryFilterDTO queryFilter, TableDTO entity)
{
(int, IDataReader) reader = (0, null);
......@@ -766,10 +774,22 @@ namespace Bailun.DC.Services.Component
string whereSql = this.GetFilterSql(queryFilter, ref sqlparam);
//排序条件SQL
string orderbySql = this.GetOrderBySql(queryFilter, entity);
string fromSql = $"FROM {(entity.DataType == DataTypeEnum.Table ? $"`{entity.DataValue}`" : $"( {entity.DataValue} )")} AS A {whereSql}";
string totalSql = $"SELECT COUNT(*) {fromSql}";
string dataSql = $"SELECT A.* {fromSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}";
var db = (entity.DataDB == DBEnum.DataWareHouse ? DW_DB : DB);
//统计查询
string totalSql = default(string);
//数据查询
string dataSql = default(string);
switch (entity.DataType)
{
case DataTypeEnum.Table:
totalSql = $"SELECT COUNT(*) FROM `{entity.DataValue}` {whereSql}";
dataSql = $"SELECT * FROM `{entity.DataValue}` {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}";
break;
default:
totalSql = $"SELECT COUNT(*) FROM ( {entity.DataValue} ) AS A {whereSql}";
dataSql = $"SELECT * FROM ( {entity.DataValue} ) AS A {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}";
break;
}
MySqlConnection db = this.GetDbConnection(entity);
reader = (db.QueryFirstOrDefault<int>(totalSql, sqlparam), db.ExecuteReader(dataSql, sqlparam));
return reader;
}
......
......@@ -164,7 +164,7 @@
type="success"
icon="el-icon-plus"
v-bind:size="item.size || 'small'"
v-on:click="setArrayValue({})">
v-on:click="setArrayValue({sortable: true})">
{{"新增"}}
</el-button>
<el-table-control ref="table"
......
<el-form ref="form-filter" label-width="auto" size="medium" class="el-form-filter">
<el-form ref="form-filter" label-width="auto" size="medium" class="el-form-filter" v-bind:model="filter" v-bind:show-message="false" v-on:validate="onValidate">
<el-row v-bind:gutter="10">
<el-col v-if="filter.listFilterControl && filter.listFilterControl.length" v-bind:span="item.colSpan || 24" v-bind:class="{'auto-width': item.colSpan == null || item.colSpan == 'auto'}" v-for="(item,index) in filter.listFilterControl" v-bind:key="index">
<el-form-item v-bind:label="item.name" v-if="item.type">
<el-form-item v-if="item.type"
v-bind:label="item.name"
v-bind:prop="'listFilterControl.' + index + '.value'"
v-bind:rules="item.rules || (item.required ? { required: true, message: item.message || ('请输入' + item.name)} : null)">
<el-form-control v-bind:item="item" v-model="item.value"></el-form-control>
</el-form-item>
</el-col>
......
......@@ -47,7 +47,7 @@
class="el-table-column-search"
v-bind:slot="setting.isShowColumnSearch ? 'header' : ''" slot-scope="scope">
</div>
<el-table-column v-if="setting.listOperateColumnControl && setting.listOperateColumnControl.length > 0"
<el-table-column v-if="setting.isShowColumnSearch"
header-align="center"
v-bind:label="setting.operateColumnName || '操作'"
v-bind:show-overflow-tooltip="setting.showTooltip"
......
......@@ -6,7 +6,7 @@
},
data: function () {
return {
formValidate: null
}
},
methods: {
......@@ -92,6 +92,19 @@
}
return listFilter;
},
//获取验证错误信息
getValidateMessage: function () {
return (this.formValidate || []).filter(function (l) { return !l.valid }).map(function (l) { return l.message });
},
//验证
validate: function () {
var that = this;
var isvalid = false;
that.$refs['form-filter'].validate(function (valid) {
isvalid = valid
})
return isvalid;
},
//查询
onSearch: function () {
this.$emit("search", this.getFilter());
......@@ -112,6 +125,20 @@
onClick: function (fn) {
this.$emit("click", fn);
},
//验证事件
onValidate: function (field, valid, message) {
var that = this;
if (!that.formValidate) {
that.formValidate = []
}
var index = that.formValidate.findIndex(function (l) { return l.field == field });
if (index >= 0) {
that.formValidate[index].valid = valid;
that.formValidate[index].message = message;
} else {
this.formValidate.push({ field: field, valid: valid, message: message });
}
}
},
mounted: function () {
this.onInitValue();
......
......@@ -93,6 +93,7 @@
onSearch: function (listFilter, firstPage) {
var that = this;
//设置当前第一页
if (that.$refs.formFilter.validate()) {
if (firstPage == null || firstPage == true) {
Vue.set(that.filterParams, 'currentPage', 1);
}
......@@ -101,6 +102,12 @@
this.getFilter(listFilter);
//查询
that.$refs.table.onSearch();
} else {
var message = that.$refs.formFilter.getValidateMessage();
if (message && message.length) {
that.$message({ dangerouslyUseHTMLString: true, message: message.join("<br/>") });
}
}
},
//重置
onReset: function (listFilter) {
......@@ -130,6 +137,7 @@
onExport: function () {
var that = this;
//异步请求
if (that.$refs.formFilter.validate()) {
that.$http.post("/Component/Table/Export", that.filterParams, { emulateJSON: true }, {
responseType: 'arraybuffer',
headers: {
......@@ -155,6 +163,12 @@
}).catch(function (error) {
that.$message(error.message || " 未知错误!");
});
} else {
var message = that.$refs.formFilter.getValidateMessage();
if (message && message.length) {
that.$message({ dangerouslyUseHTMLString: true, message: message.join("<br/>") });
}
}
},
//单击事件
onClick: function (fn) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment