提交数据
|
After Width: | Height: | Size: 4.2 KiB |
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
</body>
|
||||
</html>
|
||||
|
After Width: | Height: | Size: 146 KiB |
|
After Width: | Height: | Size: 117 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 460 KiB |
|
After Width: | Height: | Size: 544 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
|
@ -0,0 +1,28 @@
|
|||
<template>
|
||||
<router-view v-slot="{ Component }">
|
||||
<component :is="Component"/>
|
||||
</router-view>
|
||||
</template>
|
||||
|
||||
<style lang="scss">
|
||||
#app {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
/*background: #f6f8f9;*/
|
||||
/*background: goldenrod;*/
|
||||
font-family: Avenir, Helvetica, Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
color: #2c3e50;
|
||||
}
|
||||
html,body{
|
||||
height: 100%;
|
||||
background: #f6f8f9;
|
||||
|
||||
}
|
||||
*{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
|
||||
<template>
|
||||
<div class="page_search">
|
||||
<el-button type="primary" size="small">新增</el-button>
|
||||
|
||||
<div class="search">
|
||||
<el-input
|
||||
v-model="search"
|
||||
placeholder="请输入名称"
|
||||
size="small"
|
||||
class="input-with-select"
|
||||
>
|
||||
<template #append>
|
||||
<el-button icon="el-icon-search"></el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
<el-button type="primary" class="search" icon="el-icon-share" @click="exportExcel">导出</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent, ref } from "vue";
|
||||
import Excel from "exceljs";
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
const search = ref("");
|
||||
|
||||
const downloadBlob=(arrayList,type,fileName)=>{
|
||||
var blob=new Blob(arrayList,{type:type});
|
||||
var a = document.createElement('a'); //创建a标签用于下载
|
||||
a.download = fileName;
|
||||
a.href = URL.createObjectURL(blob);
|
||||
document.getElementsByTagName("body")[0].appendChild(a);
|
||||
a.click();
|
||||
document.getElementsByTagName("body")[0].removeChild(a);
|
||||
};
|
||||
|
||||
const exportExcel=async()=>{
|
||||
let workbook = new Excel.Workbook();
|
||||
let worksheet = workbook.addWorksheet('报表-威尔森',{views: [{showGridLines: true}]});
|
||||
let alignObj={alignment:{vertical:'middle',horizontal:'center'}};
|
||||
let columns=[{header:"",key:"A",style:alignObj},
|
||||
{header:"",key:"B",width:12,style:alignObj},
|
||||
{header:"",key:"C",style:alignObj},
|
||||
{header:"",key:"D",style:alignObj}];
|
||||
worksheet.columns = columns;
|
||||
|
||||
// 开始添加数据
|
||||
let data=[
|
||||
{A:"COD",B:'',C:"氨氮",D:''},
|
||||
{A:"进水",B:"出水",C:"进水",D:"出水"},
|
||||
{A:1,B:2,C:3,D:4},
|
||||
{A:11,B:2,C:3,D:4},
|
||||
{A:1,B:22,C:3,D:4}
|
||||
];
|
||||
for(let i in data) {
|
||||
worksheet.addRow(data[i]).commit();
|
||||
}
|
||||
|
||||
worksheet.mergeCells('A2:B2');
|
||||
worksheet.mergeCells('C2:D2');
|
||||
|
||||
worksheet.getRow(2).border={top: {style:'thin'},left: {style:'thin'},bottom: {style:'thin'},right: {style:'thin'}}
|
||||
|
||||
//await worksheet.commit();
|
||||
|
||||
// write to a new buffer
|
||||
const buffer = await workbook.xlsx.writeBuffer();
|
||||
//console.log(buffer);
|
||||
downloadBlob([buffer],"application/octet-stream","data.xlsx");
|
||||
};
|
||||
|
||||
return {
|
||||
search,exportExcel,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page_search {
|
||||
margin: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.search {
|
||||
margin-left: 10px;
|
||||
width: 200px;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,200 @@
|
|||
const ExcelJS = require("exceljs");
|
||||
|
||||
const autoWidthAction = (val,width=10)=>{
|
||||
if (val == null) {
|
||||
width = 10;
|
||||
} else if (val.toString().charCodeAt(0) > 255) {
|
||||
/*if chinese*/
|
||||
width = val.toString().length * 2;
|
||||
} else {
|
||||
width = val.toString().length;
|
||||
}
|
||||
return width
|
||||
}
|
||||
export const exportExcel = ({column,data,filename,autoWidth})=>{
|
||||
// 创建excel
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
// 设置信息
|
||||
workbook.creator = "Me";
|
||||
workbook.title = filename;
|
||||
workbook.created = new Date();
|
||||
workbook.modified = new Date();
|
||||
// 创建工作表
|
||||
const worksheet = workbook.addWorksheet(filename);
|
||||
// 设置列名
|
||||
let columnsName = [];
|
||||
column.forEach((item,index)=>{
|
||||
let obj = {
|
||||
header: item.label, key:item.name, width: null
|
||||
}
|
||||
if(autoWidth){
|
||||
let maxArr = [autoWidthAction(item.label)]
|
||||
data.forEach(ite=>{
|
||||
let str = ite[item.name] ||''
|
||||
if(str){
|
||||
maxArr.push(autoWidthAction(str))
|
||||
}
|
||||
})
|
||||
obj.width = Math.max(...maxArr)+5
|
||||
}
|
||||
// 设置列名、键和宽度
|
||||
columnsName.push(obj);
|
||||
})
|
||||
worksheet.columns = columnsName;
|
||||
// 添加行
|
||||
worksheet.addRows(data);
|
||||
// 写入文件
|
||||
workbook.xlsx.writeBuffer().then((data) => {
|
||||
const blob = new Blob([data, { type: "application/vnd.ms-excel" }]);
|
||||
if (window.navigator.msSaveOrOpenBlob) {
|
||||
// msSaveOrOpenBlob方法返回boolean值
|
||||
navigator.msSaveBlob(blob, filename + ".xlsx");
|
||||
// 本地保存
|
||||
} else {
|
||||
const link = document.createElement("a"); // a标签下载
|
||||
link.href = window.URL.createObjectURL(blob); // href属性指定下载链接
|
||||
link.download = filename + ".xlsx"; // dowload属性指定文件名
|
||||
link.click(); // click()事件触发下载
|
||||
window.URL.revokeObjectURL(link.href); // 释放内存
|
||||
}
|
||||
});
|
||||
}
|
||||
// 默认的列宽
|
||||
export const DEFAULT_COLUMN_WIDTH = 20;
|
||||
|
||||
function getColumnNumber(width: number) {
|
||||
// 需要的列数,四舍五入
|
||||
return Math.round(width / DEFAULT_COLUMN_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
function addData(worksheet,headerKeys,headers,data){
|
||||
|
||||
}
|
||||
|
||||
export const exportMultiHeaderExcel = ({column,data,filename,autoWidth})=>{
|
||||
// 创建excel
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
// 创建工作表
|
||||
const worksheet = workbook.addWorksheet(filename);
|
||||
|
||||
// 第一行表头
|
||||
const names1= [];
|
||||
// 第二行表头
|
||||
const names2= [];
|
||||
|
||||
// 用于匹配数据的 keys
|
||||
const headerKeys= [];
|
||||
|
||||
let headers = [];
|
||||
column.forEach((item,index)=>{
|
||||
let obj = {
|
||||
header: item.label, key:item.name, width: null
|
||||
}
|
||||
let maxArr = [autoWidthAction(item.label)]
|
||||
data.forEach(ite=>{
|
||||
let str = ite[item.name] ||''
|
||||
if(str){
|
||||
maxArr.push(autoWidthAction(str))
|
||||
}
|
||||
})
|
||||
obj.width = Math.max(...maxArr)+5
|
||||
// 设置列名、键和宽度
|
||||
headers.push(obj);
|
||||
})
|
||||
|
||||
column.forEach(item => {
|
||||
if (item.children) {
|
||||
// 有 children 说明是多级表头,header name 需要两行
|
||||
item.children.forEach(child => {
|
||||
names1.push(item.label);
|
||||
names2.push(child.label);
|
||||
headerKeys.push(child.name);
|
||||
});
|
||||
} else {
|
||||
names1.push(item.label);
|
||||
names2.push(item.label);
|
||||
headerKeys.push(item.name);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 判断是否有 children, 有的话是两行表头
|
||||
const isMultiHeader = column.some(item => item.children);
|
||||
if(isMultiHeader){
|
||||
const rowHeader1 = worksheet.addRow(names1);
|
||||
const rowHeader2 = worksheet.addRow(names2);
|
||||
|
||||
console.log('rowHeader1====',names1,names2,rowHeader1,rowHeader2)
|
||||
mergeColumnCell(headers, rowHeader1, rowHeader2, names1, names2, worksheet)
|
||||
// return
|
||||
|
||||
}
|
||||
|
||||
data.forEach((item: any) => {
|
||||
const rowData = headerKeys?.map(key => item[key]);
|
||||
const row = worksheet.addRow(rowData);
|
||||
// console.log('row--------',row)
|
||||
})
|
||||
// 写入文件
|
||||
workbook.xlsx.writeBuffer().then((data) => {
|
||||
const blob = new Blob([data, { type: "application/vnd.ms-excel" }]);
|
||||
if (window.navigator.msSaveOrOpenBlob) {
|
||||
// msSaveOrOpenBlob方法返回boolean值
|
||||
navigator.msSaveBlob(blob, filename + ".xlsx");
|
||||
// 本地保存
|
||||
} else {
|
||||
const link = document.createElement("a"); // a标签下载
|
||||
link.href = window.URL.createObjectURL(blob); // href属性指定下载链接
|
||||
link.download = filename + ".xlsx"; // dowload属性指定文件名
|
||||
link.click(); // click()事件触发下载
|
||||
window.URL.revokeObjectURL(link.href); // 释放内存
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function mergeColumnCell(headers, rowHeader1, rowHeader2, nameRow1, nameRow2, worksheet){
|
||||
// 当前 index 的指针
|
||||
let pointer = -1;
|
||||
nameRow1.forEach((name, index) => {
|
||||
// 当 index 小于指针时,说明这一列已经被合并过了,不能再合并
|
||||
if (index <= pointer) return;
|
||||
// 是否应该列合并
|
||||
const shouldVerticalMerge = name === nameRow2[index];
|
||||
|
||||
|
||||
// 是否应该行合并
|
||||
const shouldHorizontalMerge = index !== nameRow1.lastIndexOf(name);
|
||||
|
||||
console.log('==',name,nameRow2[index],index,nameRow1.lastIndexOf(name),shouldVerticalMerge,shouldHorizontalMerge)
|
||||
|
||||
pointer = nameRow1.lastIndexOf(name);
|
||||
if (shouldVerticalMerge && shouldHorizontalMerge) {
|
||||
// 两个方向都合并
|
||||
worksheet.mergeCells(
|
||||
Number(rowHeader1.number),
|
||||
index + 1,
|
||||
Number(rowHeader2.number),
|
||||
nameRow1.lastIndexOf(name) + 1,
|
||||
);
|
||||
console.log('==')
|
||||
} else if (shouldVerticalMerge && !shouldHorizontalMerge) {
|
||||
// 只在垂直方向上同一列的两行合并
|
||||
worksheet.mergeCells(Number(rowHeader1.number), index + 1, Number(rowHeader2.number), index + 1);
|
||||
} else if (!shouldVerticalMerge && shouldHorizontalMerge) {
|
||||
// 只有水平方向同一行的多列合并
|
||||
worksheet.mergeCells(
|
||||
Number(rowHeader1.number),
|
||||
index + 1,
|
||||
Number(rowHeader1.number),
|
||||
nameRow1.lastIndexOf(name) + 1,
|
||||
);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
const cell = rowHeader1.getCell(index + 1);
|
||||
cell.alignment = { vertical: 'middle', horizontal: 'center', wrapText: true };
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
After Width: | Height: | Size: 634 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |