Commit 382a3d01 by jianshuqin

优化:组件功能

parent f6376a7d
......@@ -31,5 +31,10 @@ namespace Bailun.DC.Models.Component.DTO
/// 字段排序
/// </summary>
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
DynamicParameters sqlparam = new DynamicParameters();
int fetch = (queryFilter.pageSize > 0 ? queryFilter.pageSize : int.MaxValue).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
string whereSql = this.GetFilterSql(queryFilter, ref sqlparam);
//排序条件SQL
......@@ -794,8 +800,8 @@ namespace Bailun.DC.Services.Component
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}";
totalSql = $"SELECT COUNT({selectSql}) FROM `{entity.DataValue}` {whereSql}";
dataSql = $"SELECT {selectSql} FROM `{entity.DataValue}` {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}";
break;
default:
//默认参数
......@@ -812,8 +818,8 @@ namespace Bailun.DC.Services.Component
}
}
}
totalSql = $"{setSql} SELECT COUNT(*) 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}";
totalSql = $"{setSql} SELECT COUNT({selectSql}) FROM ( {entity.DataValue} ) AS A {whereSql}";
dataSql = $"{setSql} SELECT {selectSql} FROM ( {entity.DataValue} ) AS A {whereSql} {(!string.IsNullOrWhiteSpace(orderbySql) ? $"ORDER BY {orderbySql}" : string.Empty) } LIMIT {offset} , {fetch}";
break;
}
MySqlConnection db = this.GetDbConnection(entity);
......
......@@ -6,6 +6,8 @@ using Newtonsoft.Json.Serialization;
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Bailun.DC.Web.Areas.Component.Controllers
{
......@@ -41,6 +43,16 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
ResultDTO result = new ResultDTO();
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.Result = true;
}
......@@ -58,6 +70,16 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
ResultDTO result = new ResultDTO();
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.Result = true;
}
......@@ -75,6 +97,16 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
byte[] data = null;
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);
if (exportResult.Item2 != null)
{
......
......@@ -5,6 +5,7 @@
v-on:search="onSearch"
v-on:reset="onReset"
v-on:export="onExport"
v-on:import="onImport"
v-on:click="onClick"></el-form-filter>
</el-header>
<el-main v-loading="$root.loading">
......
......@@ -166,15 +166,19 @@
}
},
//查询数据
onSearchData: function () {
onSearchData: function (filterParams, cb) {
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;
if (response.status === 200 && result.result && result.data) {
if (that.filterParams) {
Vue.set(that.filterParams, "total", result.data.totalCount);
}
Vue.set(that, "listData", (result.data.list || []));
if (cb) {
cb.call(this, result)
} else {
Vue.set(that, "listData", (result.data.list || []));
}
} else {
this.$message(result.message || " 未知错误!");
}
......@@ -183,14 +187,14 @@
});
},
//查询
onSearch: function (listFilter) {
onSearch: function (filterParams, cb) {
var that = this;
//查询列头
if (!that.setting || (that.setting.columnType != 3 && !(!that.isFirst && that.setting.columnType == 1))) {
that.onSearchColumn();
that.isFirst = false;
}
that.onSearchData();
that.onSearchData(filterParams, cb);
},
//排序
onSortChange: function (column) {
......
......@@ -90,7 +90,7 @@
}
},
//查询
onSearch: function (listFilter, firstPage) {
onSearch: function (filterParams, firstPage, cb) {
var that = this;
//设置当前第一页
if (that.$refs.formFilter.validate()) {
......@@ -98,10 +98,15 @@
Vue.set(that.filterParams, 'currentPage', 1);
}
Vue.set(that.filterParams, 'code', that.code);
//获取过虑条件
this.getFilter(listFilter);
//查询
that.$refs.table.onSearch();
if (!filterParams) {
//获取过虑条件
this.getFilter();
//查询
that.$refs.table.onSearch(null, cb);
} else {
//查询
that.$refs.table.onSearch(filterParams, cb);
}
} else {
var message = that.$refs.formFilter.getValidateMessage();
if (message && message.length) {
......@@ -134,11 +139,11 @@
that.onSearch();
},
//导出
onExport: function () {
onExport: function (filterParams, cb) {
var that = this;
//异步请求
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',
headers: {
'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8'
......@@ -160,8 +165,14 @@
saveAs(respons.bodyBlob, exportName);
}
}
if (cb) {
cb.call(this, respons);
}
}).catch(function (error) {
that.$message(error.message || " 未知错误!");
if (cb) {
cb.call(this, error);
}
});
} else {
var message = that.$refs.formFilter.getValidateMessage();
......@@ -170,6 +181,10 @@
}
}
},
//导入
onImport: function () {
debugger;
},
//单击事件
onClick: function (fn) {
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