Commit 382a3d01 by jianshuqin

优化:组件功能

parent f6376a7d
...@@ -31,5 +31,10 @@ namespace Bailun.DC.Models.Component.DTO ...@@ -31,5 +31,10 @@ namespace Bailun.DC.Models.Component.DTO
/// 字段排序 /// 字段排序
/// </summary> /// </summary>
public IList<FieldOrderDTO> ListOrder { get; set; } public IList<FieldOrderDTO> ListOrder { get; set; }
/// <summary>
/// 查询字段
/// </summary>
public IList<FieldOrderDTO> ListField { get; set; }
} }
} }
\ No newline at end of file
...@@ -783,6 +783,12 @@ namespace Bailun.DC.Services.Component ...@@ -783,6 +783,12 @@ namespace Bailun.DC.Services.Component
DynamicParameters sqlparam = new DynamicParameters(); DynamicParameters sqlparam = new DynamicParameters();
int fetch = (queryFilter.pageSize > 0 ? queryFilter.pageSize : int.MaxValue).Value; int fetch = (queryFilter.pageSize > 0 ? queryFilter.pageSize : int.MaxValue).Value;
int offset = (((queryFilter.CurrentPage > 1 ? queryFilter.CurrentPage : 1) - 1) * fetch).Value; int offset = (((queryFilter.CurrentPage > 1 ? queryFilter.CurrentPage : 1) - 1) * fetch).Value;
//查询字段
string selectSql = "*";
if (queryFilter?.ListField?.Count > 0)
{
selectSql = $"{(queryFilter.ListField.Any(l => l.Operator != null && l.Operator.Equals("DISTINCT", StringComparison.OrdinalIgnoreCase)) ? "DISTINCT" : string.Empty)} {string.Join(",", queryFilter.ListField.Select(l => l.Field))}";
}
//过虑条件SQL //过虑条件SQL
string whereSql = this.GetFilterSql(queryFilter, ref sqlparam); string whereSql = this.GetFilterSql(queryFilter, ref sqlparam);
//排序条件SQL //排序条件SQL
...@@ -794,8 +800,8 @@ namespace Bailun.DC.Services.Component ...@@ -794,8 +800,8 @@ namespace Bailun.DC.Services.Component
switch (entity.DataType) switch (entity.DataType)
{ {
case DataTypeEnum.Table: case DataTypeEnum.Table:
totalSql = $"SELECT COUNT(*) FROM `{entity.DataValue}` {whereSql}"; totalSql = $"SELECT COUNT({selectSql}) FROM `{entity.DataValue}` {whereSql}";
dataSql = $"SELECT * FROM `{entity.DataValue}` {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}"; dataSql = $"SELECT {selectSql} FROM `{entity.DataValue}` {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}";
break; break;
default: default:
//默认参数 //默认参数
...@@ -812,8 +818,8 @@ namespace Bailun.DC.Services.Component ...@@ -812,8 +818,8 @@ namespace Bailun.DC.Services.Component
} }
} }
} }
totalSql = $"{setSql} SELECT COUNT(*) FROM ( {entity.DataValue} ) AS A {whereSql}"; totalSql = $"{setSql} SELECT COUNT({selectSql}) FROM ( {entity.DataValue} ) AS A {whereSql}";
dataSql = $"{setSql} SELECT * FROM ( {entity.DataValue} ) AS A {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}"; dataSql = $"{setSql} SELECT {selectSql} FROM ( {entity.DataValue} ) AS A {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}";
break; break;
} }
MySqlConnection db = this.GetDbConnection(entity); MySqlConnection db = this.GetDbConnection(entity);
......
...@@ -6,6 +6,8 @@ using Newtonsoft.Json.Serialization; ...@@ -6,6 +6,8 @@ using Newtonsoft.Json.Serialization;
using System; using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Bailun.DC.Web.Areas.Component.Controllers namespace Bailun.DC.Web.Areas.Component.Controllers
{ {
...@@ -41,6 +43,16 @@ namespace Bailun.DC.Web.Areas.Component.Controllers ...@@ -41,6 +43,16 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
try try
{ {
if (Request.ContentType.Contains("application/json"))
{
using (Stream stream = Request.Body)
{
byte[] buffer = new byte[Request.ContentLength.Value];
stream.Read(buffer, 0, buffer.Length);
string content = Encoding.UTF8.GetString(buffer);
queryFilter = JsonConvert.DeserializeObject<QueryFilterDTO>(content);
}
}
result.Data = new TableService().GetListColumn(queryFilter); result.Data = new TableService().GetListColumn(queryFilter);
result.Result = true; result.Result = true;
} }
...@@ -58,6 +70,16 @@ namespace Bailun.DC.Web.Areas.Component.Controllers ...@@ -58,6 +70,16 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
try try
{ {
if (Request.ContentType.Contains("application/json"))
{
using (Stream stream = Request.Body)
{
byte[] buffer = new byte[Request.ContentLength.Value];
stream.Read(buffer, 0, buffer.Length);
string content = Encoding.UTF8.GetString(buffer);
queryFilter = JsonConvert.DeserializeObject<QueryFilterDTO>(content);
}
}
result.Data = new TableService().GetListData(queryFilter); result.Data = new TableService().GetListData(queryFilter);
result.Result = true; result.Result = true;
} }
...@@ -75,6 +97,16 @@ namespace Bailun.DC.Web.Areas.Component.Controllers ...@@ -75,6 +97,16 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
byte[] data = null; byte[] data = null;
try try
{ {
if (Request.ContentType.Contains("application/json"))
{
using (Stream stream = Request.Body)
{
byte[] buffer = new byte[Request.ContentLength.Value];
stream.Read(buffer, 0, buffer.Length);
string content = Encoding.UTF8.GetString(buffer);
queryFilter = JsonConvert.DeserializeObject<QueryFilterDTO>(content);
}
}
var exportResult = new TableService().Export(queryFilter); var exportResult = new TableService().Export(queryFilter);
if (exportResult.Item2 != null) if (exportResult.Item2 != null)
{ {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
v-on:search="onSearch" v-on:search="onSearch"
v-on:reset="onReset" v-on:reset="onReset"
v-on:export="onExport" v-on:export="onExport"
v-on:import="onImport"
v-on:click="onClick"></el-form-filter> v-on:click="onClick"></el-form-filter>
</el-header> </el-header>
<el-main v-loading="$root.loading"> <el-main v-loading="$root.loading">
......
...@@ -166,15 +166,19 @@ ...@@ -166,15 +166,19 @@
} }
}, },
//查询数据 //查询数据
onSearchData: function () { onSearchData: function (filterParams, cb) {
var that = this; var that = this;
that.$http.post("/Component/Table/GetListData", $.extend({ code: that.code }, that.filterParams), { emulateJSON: true, code: that.code }).then(function (response) { that.$http.post("/Component/Table/GetListData", $.extend({ code: that.code }, (filterParams || that.filterParams)), { emulateJSON: true, code: that.code }).then(function (response) {
var result = response.data; var result = response.data;
if (response.status === 200 && result.result && result.data) { if (response.status === 200 && result.result && result.data) {
if (that.filterParams) { if (that.filterParams) {
Vue.set(that.filterParams, "total", result.data.totalCount); Vue.set(that.filterParams, "total", result.data.totalCount);
} }
if (cb) {
cb.call(this, result)
} else {
Vue.set(that, "listData", (result.data.list || [])); Vue.set(that, "listData", (result.data.list || []));
}
} else { } else {
this.$message(result.message || " 未知错误!"); this.$message(result.message || " 未知错误!");
} }
...@@ -183,14 +187,14 @@ ...@@ -183,14 +187,14 @@
}); });
}, },
//查询 //查询
onSearch: function (listFilter) { onSearch: function (filterParams, cb) {
var that = this; var that = this;
//查询列头 //查询列头
if (!that.setting || (that.setting.columnType != 3 && !(!that.isFirst && that.setting.columnType == 1))) { if (!that.setting || (that.setting.columnType != 3 && !(!that.isFirst && that.setting.columnType == 1))) {
that.onSearchColumn(); that.onSearchColumn();
that.isFirst = false; that.isFirst = false;
} }
that.onSearchData(); that.onSearchData(filterParams, cb);
}, },
//排序 //排序
onSortChange: function (column) { onSortChange: function (column) {
......
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
} }
}, },
//查询 //查询
onSearch: function (listFilter, firstPage) { onSearch: function (filterParams, firstPage, cb) {
var that = this; var that = this;
//设置当前第一页 //设置当前第一页
if (that.$refs.formFilter.validate()) { if (that.$refs.formFilter.validate()) {
...@@ -98,10 +98,15 @@ ...@@ -98,10 +98,15 @@
Vue.set(that.filterParams, 'currentPage', 1); Vue.set(that.filterParams, 'currentPage', 1);
} }
Vue.set(that.filterParams, 'code', that.code); Vue.set(that.filterParams, 'code', that.code);
if (!filterParams) {
//获取过虑条件 //获取过虑条件
this.getFilter(listFilter); this.getFilter();
//查询 //查询
that.$refs.table.onSearch(); that.$refs.table.onSearch(null, cb);
} else {
//查询
that.$refs.table.onSearch(filterParams, cb);
}
} else { } else {
var message = that.$refs.formFilter.getValidateMessage(); var message = that.$refs.formFilter.getValidateMessage();
if (message && message.length) { if (message && message.length) {
...@@ -134,11 +139,11 @@ ...@@ -134,11 +139,11 @@
that.onSearch(); that.onSearch();
}, },
//导出 //导出
onExport: function () { onExport: function (filterParams, cb) {
var that = this; var that = this;
//异步请求 //异步请求
if (that.$refs.formFilter.validate()) { if (that.$refs.formFilter.validate()) {
that.$http.post("/Component/Table/Export", that.filterParams, { emulateJSON: true }, { that.$http.post("/Component/Table/Export", (filterParams || that.filterParams), { emulateJSON: true }, {
responseType: 'arraybuffer', responseType: 'arraybuffer',
headers: { headers: {
'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8' 'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8'
...@@ -160,8 +165,14 @@ ...@@ -160,8 +165,14 @@
saveAs(respons.bodyBlob, exportName); saveAs(respons.bodyBlob, exportName);
} }
} }
if (cb) {
cb.call(this, respons);
}
}).catch(function (error) { }).catch(function (error) {
that.$message(error.message || " 未知错误!"); that.$message(error.message || " 未知错误!");
if (cb) {
cb.call(this, error);
}
}); });
} else { } else {
var message = that.$refs.formFilter.getValidateMessage(); var message = that.$refs.formFilter.getValidateMessage();
...@@ -170,6 +181,10 @@ ...@@ -170,6 +181,10 @@
} }
} }
}, },
//导入
onImport: function () {
debugger;
},
//单击事件 //单击事件
onClick: function (fn) { onClick: function (fn) {
var that = this; var that = this;
......
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