Commit 919807be by jianshuqin

优化:组件功能

parent b47baa44
...@@ -29,5 +29,15 @@ ...@@ -29,5 +29,15 @@
/// 格式化 /// 格式化
/// </summary> /// </summary>
public dynamic Format { get; set; } public dynamic Format { get; set; }
/// <summary>
/// 组名
/// </summary>
public string GroupName { get; set; }
/// <summary>
/// 行合并属性
/// </summary>
public string RowSpanProp { get; set; }
} }
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ using MySql.Data.MySqlClient; ...@@ -4,6 +4,7 @@ using MySql.Data.MySqlClient;
using Newtonsoft.Json; using Newtonsoft.Json;
using NPOI.HSSF.UserModel; using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.Streaming; using NPOI.XSSF.Streaming;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -258,6 +259,47 @@ namespace Bailun.DC.Services.Component ...@@ -258,6 +259,47 @@ namespace Bailun.DC.Services.Component
fontTitle.FontHeightInPoints = 12; fontTitle.FontHeightInPoints = 12;
//单元格样式 //单元格样式
ICellStyle styleTitle = workbook.CreateCellStyle(); ICellStyle styleTitle = workbook.CreateCellStyle();
ICellStyle alignmentstyle = workbook.CreateCellStyle();
alignmentstyle.VerticalAlignment = VerticalAlignment.Center;
alignmentstyle.Alignment = HorizontalAlignment.Center;
ICellStyle verticAlalignmentstyle = workbook.CreateCellStyle();
verticAlalignmentstyle.VerticalAlignment = VerticalAlignment.Center;
//合并行属性值
IDictionary<string, (int, string)> rowSpanProp = new Dictionary<string, (int, string)>();
//组头
bool hasGroup = false;
if (listColumn.Any(l => !string.IsNullOrWhiteSpace(l.GroupName)))
{
hasGroup = true;
int index = 0;
string name = default(string);
listColumn.ForEach((l, col) =>
{
var cell = headerRow.CreateCell(col);
if (string.IsNullOrWhiteSpace(l.GroupName))
{
cell.CellStyle = verticAlalignmentstyle;
cell.SetCellValue(l.Name);
sheet.AddMergedRegion(new CellRangeAddress(0, 1, col, col));
}
else
{
cell.CellStyle = alignmentstyle;
cell.SetCellValue(l.GroupName);
}
if (l.GroupName != name)
{
if (!string.IsNullOrWhiteSpace(name) || col == listColumn.Count() - 1)
{
sheet.AddMergedRegion(new CellRangeAddress(0, 0, index, col - (col == listColumn.Count() ? 0 : 1)));
}
index = col;
}
name = l.GroupName;
});
headerRow = sheet.CreateRow(1);
}
//列头
listColumn.ForEach((l, col) => listColumn.ForEach((l, col) =>
{ {
var cell = headerRow.CreateCell(col); var cell = headerRow.CreateCell(col);
...@@ -266,10 +308,12 @@ namespace Bailun.DC.Services.Component ...@@ -266,10 +308,12 @@ namespace Bailun.DC.Services.Component
}); });
for (int row = 0; row < excelMaxRowCount && reader.Read(); row++) for (int row = 0; row < excelMaxRowCount && reader.Read(); row++)
{ {
IRow dataRow = sheet.CreateRow(row + 1); IRow dataRow = sheet.CreateRow(row + 1 + (hasGroup ? 1 : 0));
listColumn.ForEach((header, col) => listColumn.ForEach((header, col) =>
{ {
string value = reader[header.Prop]?.ToString(); string value = reader[header.Prop]?.ToString();
ICell cell = dataRow.CreateCell(col);
cell.CellStyle = verticAlalignmentstyle;
if (!string.IsNullOrWhiteSpace(value)) if (!string.IsNullOrWhiteSpace(value))
{ {
if (header.Format is bool && header.Format == true) if (header.Format is bool && header.Format == true)
...@@ -291,11 +335,30 @@ namespace Bailun.DC.Services.Component ...@@ -291,11 +335,30 @@ namespace Bailun.DC.Services.Component
value = parseTime.ToString(header.Format.Replace("hh", "HH")); value = parseTime.ToString(header.Format.Replace("hh", "HH"));
} }
} }
dataRow.CreateCell(col).SetCellValue(value.ToString()); cell.SetCellValue(value.ToString());
} }
else if (dataCount > 65535) else if (dataCount > 65535)
{ {
dataRow.CreateCell(col).SetCellValue(string.Empty); cell.SetCellValue(string.Empty);
}
//合并行
if (!string.IsNullOrWhiteSpace(header.RowSpanProp))
{
if (!rowSpanProp.ContainsKey(header.Prop))
{
rowSpanProp.Add(header.Prop, (dataRow.RowNum, reader[header.RowSpanProp]?.ToString()));
}
else
{
if ((row > 0 && reader[header.RowSpanProp]?.ToString() != rowSpanProp[header.Prop].Item2) || row == excelMaxRowCount - 1)
{
sheet.AddMergedRegion(new CellRangeAddress(rowSpanProp[header.Prop].Item1, dataRow.RowNum - (row == excelMaxRowCount - 1 ? 0 : 1), col, col));
}
if (reader[header.RowSpanProp]?.ToString() != rowSpanProp[header.Prop].Item2)
{
rowSpanProp[header.Prop] = (dataRow.RowNum, reader[header.RowSpanProp]?.ToString());
}
}
} }
}); });
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
v-bind:data="listData" v-bind:data="listData"
v-bind:row-key="onRowKey" v-bind:row-key="onRowKey"
v-bind:highlightCurrentRow="setting.selectRowMethod == 1" v-bind:highlightCurrentRow="setting.selectRowMethod == 1"
v-bind:span-method="onSpanMethod"
v-on:sort-change="onSortChange" v-on:sort-change="onSortChange"
v-on:selection-change="onSelectionChange" v-on:selection-change="onSelectionChange"
v-on:select="(selection, row)=> onRowClick(row)" v-on:select="(selection, row)=> onRowClick(row)"
...@@ -82,7 +83,7 @@ ...@@ -82,7 +83,7 @@
</el-table-column> </el-table-column>
<template v-for="(column,index) in setting.listColumn"> <template v-for="(column,index) in setting.listColumn">
<el-table-column header-align="center" <el-table-column header-align="center"
v-bind:sortable="(!setting.isShowColumnSearch && (column.sortable == null || column.sortable)) ? 'custom' : false" v-bind:sortable="(!setting.isShowColumnSearch && (column.sortable == null || column.sortable) && (!column.listColumn || !column.listColumn.length)) ? 'custom' : false"
v-bind:prop="column.prop" v-bind:prop="column.prop"
v-bind:show-overflow-tooltip="setting.showTooltip" v-bind:show-overflow-tooltip="setting.showTooltip"
v-bind:label="column.name" v-bind:label="column.name"
...@@ -114,7 +115,25 @@ ...@@ -114,7 +115,25 @@
</el-form-control> </el-form-control>
</template> </template>
</el-table-column> </el-table-column>
<template slot-scope="scope"> <el-table-column v-for="(column,index) in column.listColumn"
header-align="center"
v-bind:sortable="column.sortable == null || column.sortable ? 'custom' : false"
v-bind:prop="column.prop"
v-bind:show-overflow-tooltip="setting.showTooltip"
v-bind:label="column.name"
v-bind:key="index"
v-bind:width="column.width || ''"
v-bind:min-width="!column.width && ((column.name || ' ').length * 15 + 45)">
<template slot-scope="scope">
<el-form-control v-model="scope.row[column.prop]"
v-bind:item="column"
v-bind:scope="scope"
v-on:click="javaScript.call(scope,column.click,scope)"
v-on:change="javaScript.call(scope,column.change,scope)">
</el-form-control>
</template>
</el-table-column>
<template v-if="!column.listColumn || !column.listColumn.length" slot-scope="scope">
<el-form-control v-model="scope.row[column.prop]" <el-form-control v-model="scope.row[column.prop]"
v-bind:item="column" v-bind:item="column"
v-bind:scope="scope" v-bind:scope="scope"
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
return { return {
isFirst: false, isFirst: false,
listData: [], listData: [],
olistColumn: [],
setting: {}, setting: {},
rows: [], rows: [],
row: null row: null
...@@ -102,6 +103,24 @@ ...@@ -102,6 +103,24 @@
that.onSearch(); that.onSearch();
}) })
} }
//组表头
if (that.setting.listColumn && that.setting.listColumn.length && that.setting.listColumn.findIndex(function (l) { return l.groupname }) > 0) {
//保存原生列
Vue.set(this, "olistColumn", that.setting.listColumn);
var listColumn = [];
that.setting.listColumn.forEach((l, i) => {
if (l.groupname) {
if (i == 0 || that.setting.listColumn[i - 1].groupname != l.groupname) {
listColumn.push({ name: l.groupname, listColumn: [l] });
} else {
listColumn[listColumn.length - 1].listColumn.push(l);
}
} else {
listColumn.push(l);
}
});
Vue.set(that.setting, "listColumn", listColumn);
}
} else { } else {
this.$message((!result.data && "配置错误") || (result.Message || " 未知错误!")); this.$message((!result.data && "配置错误") || (result.Message || " 未知错误!"));
} }
...@@ -242,6 +261,29 @@ ...@@ -242,6 +261,29 @@
return null; return null;
} }
}, },
//单元格合并
onSpanMethod: function (span) {
var that = this;
var cellspan = { rowspan: 1, colspan: 1 };
var listColumn = that.olistColumn && that.olistColumn.length ? that.olistColumn : that.setting.listColumn;
if (span.columnIndex < listColumn.length) {
var column = listColumn[span.columnIndex]
if (column.rowspanprop) {
if (span.rowIndex == 0 || that.listData[span.rowIndex - 1][column.rowspanprop] != that.listData[span.rowIndex][column.rowspanprop]) {
var lastIndex = that.listData.findIndex(function (l, i) { return (i > span.rowIndex && l[column.rowspanprop] != span.row[column.rowspanprop]) });
if (lastIndex < 0) {
lastIndex = that.listData.length + 1;
}
cellspan.rowspan = lastIndex - span.rowIndex;
cellspan.colspan = 1;
} else {
cellspan.rowspan = 0;
cellspan.colspan = 0;
}
}
}
return cellspan;
}
}, },
mounted: function () { mounted: function () {
this.onInit(); this.onInit();
......
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