|
@@ -526,83 +526,39 @@ const ClearTeachingRelationship = async ()=>{
|
|
|
|
|
|
|
|
// 批量导入/导出
|
|
// 批量导入/导出
|
|
|
|
|
|
|
|
-//前端 导出 Excel
|
|
|
|
|
|
|
+
|
|
|
const LoopAddSheet=(finalTableColumn, finalTableData,workbook,sheetName )=>{
|
|
const LoopAddSheet=(finalTableColumn, finalTableData,workbook,sheetName )=>{
|
|
|
// 1. 提取表头
|
|
// 1. 提取表头
|
|
|
- // 行政班和教学班不一样
|
|
|
|
|
- let headers = [] // 行政班表头数据
|
|
|
|
|
- let topHeaders:any[] = [] // 教学班 表头数据
|
|
|
|
|
- let bottomHeaders:any[] = [] // 教学班 子表头数据
|
|
|
|
|
|
|
+ let headers = [] // 表头数据
|
|
|
|
|
|
|
|
// 2.创建工作表
|
|
// 2.创建工作表
|
|
|
const worksheet = workbook.addWorksheet(sheetName);
|
|
const worksheet = workbook.addWorksheet(sheetName);
|
|
|
|
|
|
|
|
// 3. 添加表头行
|
|
// 3. 添加表头行
|
|
|
let headerRow
|
|
let headerRow
|
|
|
- let subHeaderRow
|
|
|
|
|
-
|
|
|
|
|
if(sheetName == '行政班'){
|
|
if(sheetName == '行政班'){
|
|
|
headers = finalTableColumn.map(column => column.label || column.name)
|
|
headers = finalTableColumn.map(column => column.label || column.name)
|
|
|
- // 行政班:普通表头
|
|
|
|
|
- headerRow = worksheet.addRow(headers)
|
|
|
|
|
- // 定义表头样式
|
|
|
|
|
- headerRow.eachCell((cell) => {
|
|
|
|
|
- cell.style = {
|
|
|
|
|
- font: { name: 'Microsoft YaHei', size: 12, bold: true, color: { argb: 'FF333333' } },
|
|
|
|
|
- fill: { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFF4F6F8' } },
|
|
|
|
|
- border: {
|
|
|
|
|
- top: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- left: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- },
|
|
|
|
|
- alignment: { vertical: 'middle', horizontal: 'left', wrapText: true },
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
}else if(sheetName == '教学班'){
|
|
}else if(sheetName == '教学班'){
|
|
|
finalTableColumn.forEach(column => {
|
|
finalTableColumn.forEach(column => {
|
|
|
- topHeaders.push(column.label || column.name)
|
|
|
|
|
- topHeaders.push('') // 占位,用于合并
|
|
|
|
|
- bottomHeaders.push('班级')
|
|
|
|
|
- bottomHeaders.push('教师')
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // 添加第一层表头
|
|
|
|
|
- headerRow = worksheet.addRow(topHeaders)
|
|
|
|
|
- // 添加第二层表头
|
|
|
|
|
- // subHeaderRow = worksheet.addRow(bottomHeaders)
|
|
|
|
|
-
|
|
|
|
|
- // 定义第一层表头样式
|
|
|
|
|
- headerRow.eachCell((cell) => {
|
|
|
|
|
- cell.style = {
|
|
|
|
|
- font: { name: 'Microsoft YaHei', size: 12, bold: true, color: { argb: 'FF333333' } },
|
|
|
|
|
- fill: { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFF4F6F8' } },
|
|
|
|
|
- border: {
|
|
|
|
|
- top: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- left: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- },
|
|
|
|
|
- alignment: { vertical: 'middle', horizontal: 'center', wrapText: true },
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ headers.push(`${column.label || column.name}班级`)
|
|
|
|
|
+ headers.push(`${column.label || column.name}教师`)
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
- // 定义第二层表头样式
|
|
|
|
|
- // subHeaderRow.eachCell((cell) => {
|
|
|
|
|
- // cell.style = {
|
|
|
|
|
- // font: { name: 'Microsoft YaHei', size: 11, bold: true, color: { argb: 'FF333333' } },
|
|
|
|
|
- // fill: { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFF9FAFB' } },
|
|
|
|
|
- // border: {
|
|
|
|
|
- // top: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- // left: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- // bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- // right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
- // },
|
|
|
|
|
- // alignment: { vertical: 'middle', horizontal: 'center', wrapText: true },
|
|
|
|
|
- // }
|
|
|
|
|
- // })
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ // 添加表头
|
|
|
|
|
+ headerRow = worksheet.addRow(headers)
|
|
|
|
|
+ // 定义表头样式
|
|
|
|
|
+ headerRow.eachCell((cell) => {
|
|
|
|
|
+ cell.style = {
|
|
|
|
|
+ font: { name: 'Microsoft YaHei', size: 12, color: { argb: 'FF333333' } },
|
|
|
|
|
+ border: {
|
|
|
|
|
+ top: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
+ left: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
+ bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
+ right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
|
|
+ },
|
|
|
|
|
+ alignment: { vertical: 'middle', horizontal: 'center', wrapText: true },
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
// 4. 添加数据行
|
|
// 4. 添加数据行
|
|
|
// 行政班 和 教学班 不一样
|
|
// 行政班 和 教学班 不一样
|
|
@@ -634,45 +590,44 @@ const LoopAddSheet=(finalTableColumn, finalTableData,workbook,sheetName )=>{
|
|
|
bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
|
|
|
},
|
|
},
|
|
|
- alignment: { vertical: 'top', horizontal: 'left', wrapText: true },
|
|
|
|
|
|
|
+ alignment: { vertical: 'middle', horizontal: 'center', wrapText: true },
|
|
|
|
|
+
|
|
|
};
|
|
};
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // 5. 设置列宽
|
|
|
|
|
- if(sheetName == '行政班'){
|
|
|
|
|
- worksheet.columns = headers.map(() => ({ width: 25 }));
|
|
|
|
|
- }else if(sheetName == '教学班'){
|
|
|
|
|
- worksheet.columns = bottomHeaders.map(() => ({ width: 25 }));
|
|
|
|
|
- //放到最后合并 合并第一层表头的两列,放到设置列表前面,合并头的 宽度会缩小
|
|
|
|
|
- let colIndex = 1
|
|
|
|
|
- finalTableColumn.forEach(() => {
|
|
|
|
|
- worksheet.mergeCells(1, colIndex, 1, colIndex + 1)
|
|
|
|
|
- colIndex += 2
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 5. 设置列宽并固定表头行
|
|
|
|
|
+ worksheet.columns = headers.map(() => ({ width: 25 }));
|
|
|
|
|
+ // 设置表头的第一行固定
|
|
|
|
|
+ worksheet.views = [{ state: 'frozen', ySplit: 1 }];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+//前端 导出 Excel
|
|
|
const HandleExportExcel = async () => {
|
|
const HandleExportExcel = async () => {
|
|
|
- // 1. 初始化sheet列表
|
|
|
|
|
- let sheetList = [
|
|
|
|
|
- {
|
|
|
|
|
- tableColumn:filterAdministrativeClassTableColumns.value,
|
|
|
|
|
- tableData:administrativeClassTableData.value,
|
|
|
|
|
- sheetName:'行政班'
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- tableColumn:filterTeachingClassTableColumns.value,
|
|
|
|
|
- tableData:teachingClassTableData.value,
|
|
|
|
|
- sheetName:'教学班'
|
|
|
|
|
- },
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ // 1. 初始化表数据
|
|
|
|
|
+ let tableColumn = []
|
|
|
|
|
+ let tableData = []
|
|
|
|
|
+ let sheetName = ''
|
|
|
|
|
+ // 班级名称
|
|
|
|
|
+ let gradeName = gradeList.value.find(item=>item.key == searchParmams.value.gradeId)?.label
|
|
|
|
|
+ // 教学班
|
|
|
|
|
+ if(searchParmams.value.classType == 'teach'){
|
|
|
|
|
+ tableColumn = filterTeachingClassTableColumns.value,
|
|
|
|
|
+ tableData = teachingClassTableData.value,
|
|
|
|
|
+ sheetName = '教学班'
|
|
|
|
|
+ // 行政班
|
|
|
|
|
+ }else if(searchParmams.value.classType == 'xingzeng'){
|
|
|
|
|
+ tableColumn = filterAdministrativeClassTableColumns.value,
|
|
|
|
|
+ tableData = administrativeClassTableData.value,
|
|
|
|
|
+ sheetName = '行政班'
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 2. 创建工作簿
|
|
// 2. 创建工作簿
|
|
|
const workbook = new ExcelJS.Workbook();
|
|
const workbook = new ExcelJS.Workbook();
|
|
|
|
|
|
|
|
// 3. 添加sheet表
|
|
// 3. 添加sheet表
|
|
|
- sheetList.forEach(item=>{
|
|
|
|
|
- LoopAddSheet(item.tableColumn,item.tableData,workbook,item.sheetName)
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ LoopAddSheet(tableColumn,tableData,workbook,sheetName)
|
|
|
|
|
+
|
|
|
|
|
|
|
|
// 4. 导出文件
|
|
// 4. 导出文件
|
|
|
const buffer = await workbook.xlsx.writeBuffer();
|
|
const buffer = await workbook.xlsx.writeBuffer();
|
|
@@ -683,7 +638,7 @@ const HandleExportExcel = async () => {
|
|
|
const url = URL.createObjectURL(blob);
|
|
const url = URL.createObjectURL(blob);
|
|
|
const link = document.createElement('a');
|
|
const link = document.createElement('a');
|
|
|
link.href = url;
|
|
link.href = url;
|
|
|
- link.download = `授课关系表_${new Date().toISOString().slice(0, 10)}.xlsx`;
|
|
|
|
|
|
|
+ link.download = `${gradeName}_${sheetName}授课关系表.xlsx`;
|
|
|
link.style.visibility = 'hidden';
|
|
link.style.visibility = 'hidden';
|
|
|
document.body.appendChild(link);
|
|
document.body.appendChild(link);
|
|
|
link.click();
|
|
link.click();
|