Bladeren bron

修改评价账号和评价码的导出

lm 1 maand geleden
bovenliggende
commit
b3505f66b9

+ 21 - 19
src/views/reviewManagement/stepComponent/reviewAccountComponent/GenerateReviewCode.vue

@@ -240,7 +240,7 @@ const FinishReviewAccount = async()=>{
 // 导出 Excel
 const HandleExportExcel = async () => {
     // 1. 初始化sheet列表
-    let finalTableColumn = generateCodeTableColumns.value.slice(1)
+    let finalTableColumn = generateCodeTableColumns.value.slice(1).filter(column => !column.hidden)
     let finalTableData = tableData.value
     let sheetName = '评价码'
 
@@ -262,7 +262,7 @@ const HandleExportExcel = async () => {
             bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
             right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
         },
-        alignment: { vertical: 'middle', horizontal: 'left', wrapText: true },
+        alignment: { vertical: 'middle', horizontal: 'center', wrapText: true },
         }
     })
 
@@ -288,7 +288,7 @@ const HandleExportExcel = async () => {
                     bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
                     right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
                 },
-                alignment: { vertical: 'middle', horizontal: 'left', wrapText: true },
+                alignment: { vertical: 'middle', horizontal: 'center', wrapText: true },
             };
         });
         
@@ -321,6 +321,9 @@ const HandleExportExcel = async () => {
         }
         return { width: 25 };
     });
+    // 设置表头的第一行固定
+    worksheet.views = [{ state: 'frozen', ySplit: 1 }];
+
 
     // 6. 导出文件
     const buffer = await workbook.xlsx.writeBuffer();
@@ -331,7 +334,7 @@ const HandleExportExcel = async () => {
     const url = URL.createObjectURL(blob);
     const link = document.createElement('a');
     link.href = url;
-    link.download = `评价码_${new Date().toISOString().slice(0, 10)}.xlsx`;
+    link.download = `评价码列表.xlsx`;
     link.style.visibility = 'hidden';
     document.body.appendChild(link);
     link.click();
@@ -349,14 +352,17 @@ const HandleExportPdf = async () => {
 
   // 2. 格式化表格数据
   const body = finalTableData.map(row => {
-    return [
-      row.evaluationGradeName,
-      row.evaluationClassName,
-      row.genderName,
-      row.evaluationCode,
-      row.requestUrl,
-      '' // 留空给最后一列绘制二维码图片
-    ];
+    // 留空给最后一列绘制二维码图片
+    return [...finalTableColumn.map(item=>row[item.name]),'']
+
+    // return [
+    //   row.evaluationGradeName,
+    //   row.evaluationClassName,
+    //   row.genderName,
+    //   row.evaluationCode,
+    //   row.requestUrl,
+    //   '' 
+    // ];
   });
 
   // 3. 创建 PDF 实例
@@ -385,17 +391,13 @@ const HandleExportPdf = async () => {
     },
     // 手动调整列宽,给二维码列留出足够位置
     columnStyles: {
-      0: { cellWidth: 20 }, // 年级
-      1: { cellWidth: 20 }, // 班级
-      2: { cellWidth: 15 }, // 性别
-      3: { cellWidth: 25 }, // 评价码
-      4: { cellWidth: 70 }, // 网址
-      5: { cellWidth: 35 }  // 二维码
+     [finalTableColumn.length - 1]: { cellWidth: 70 }, // 网址
+     [finalTableColumn.length]:{ cellWidth: 35 },  // 二维码,
     },
     // 核心:在单元格渲染完毕后,利用钩子函数将二维码图片画进最后一列
     didDrawCell: (data) => {
       // 判断是否是最后一列且为数据行(非表头)
-      if (data.column.index === 5 && data.cell.section === 'body') {
+      if (data.column.index === finalTableColumn.length && data.cell.section === 'body') {
         const rowIndex = data.row.index;
         const qrCodeDataUrl = finalTableData[rowIndex]?.qrCode;
         if (qrCodeDataUrl) {

+ 13 - 11
src/views/reviewManagement/stepComponent/reviewAccountComponent/ReviewAccountComponent.vue

@@ -3,8 +3,7 @@
         <div class="page_search">
             <div class="search_content">
                 <div class="content_left">
-                    <el-checkbox v-model="store.state.evaluationManageStepData.isGenerateAccountByGender"  
-                        @change="(val)=>GenerateAccountByGenderOrNot(val)" >
+                    <el-checkbox v-model="store.state.evaluationManageStepData.isGenerateAccountByGender">
                         按男女生成
                     </el-checkbox>
                 </div>
@@ -416,10 +415,11 @@ const GoToGenerateCodePage = ()=>{
     router.push(`generateReviewCode?id=${route.query.id}`)
 }
 
-// 5. 批量导入/ 导出
+// 5. 批量 导出
 const HandleExportExcel = async () => {
     // 1. 初始化sheet列表
-    let finalTableColumn = tableColumns.value
+    let finalTableColumn = tableColumns.value.filter(column=>!column?.hidden)
+
     let finalTableData = tableData.value
     let sheetName = '评价账号'
 
@@ -441,7 +441,7 @@ const HandleExportExcel = async () => {
             bottom: { style: 'thin', color: { argb: 'FFD9D9D9' } },
             right: { style: 'thin', color: { argb: 'FFD9D9D9' } },
         },
-        alignment: { vertical: 'middle', horizontal: 'left', wrapText: true },
+        alignment: { vertical: 'middle', horizontal: 'center', wrapText: true },
         }
     })
 
@@ -452,7 +452,7 @@ const HandleExportExcel = async () => {
             if(column.name.startsWith('class_')){
                 return cellValue?.className
             }
-            return cellValue || '-'
+            return cellValue
         })
         const excelRow = worksheet.addRow(rowData);
         // 6. 定义数据行样式
@@ -465,26 +465,28 @@ const HandleExportExcel = async () => {
             bottom: { 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. 设置列宽
+    // 6. 设置列宽
     worksheet.columns = headers.map(() => ({ width: 25 }));
 
+    // 设置表头的第一行固定
+    worksheet.views = [{ state: 'frozen', ySplit: 1 }];
 
 
-    // 6. 导出文件
+    // 7. 导出文件
     const buffer = await workbook.xlsx.writeBuffer();
     const blob = new Blob([buffer], { 
         type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' 
     });
-    
+    let accountType = store.state.evaluationManageStepData.isGenerateAccountByGender ? '按男女生成' : '不按男女生成'
     const url = URL.createObjectURL(blob);
     const link = document.createElement('a');
     link.href = url;
-    link.download = `评价账号表_${new Date().toISOString().slice(0, 10)}.xlsx`;
+    link.download = `评价账号表_${accountType}.xlsx`;
     link.style.visibility = 'hidden';
     document.body.appendChild(link);
     link.click();

+ 48 - 93
src/views/reviewManagement/stepComponent/teachingRelationshipComponent/TeachingRelationshipComponent.vue

@@ -526,83 +526,39 @@ const ClearTeachingRelationship = async ()=>{
 
 // 批量导入/导出
 
-//前端 导出 Excel
+
 const LoopAddSheet=(finalTableColumn, finalTableData,workbook,sheetName )=>{
   // 1. 提取表头
-  // 行政班和教学班不一样
-  let headers = []               // 行政班表头数据
-  let topHeaders:any[] = []      // 教学班 表头数据
-  let bottomHeaders:any[] = []   // 教学班 子表头数据
+  let headers = []               // 表头数据
 
   // 2.创建工作表
   const worksheet = workbook.addWorksheet(sheetName);
 
   // 3. 添加表头行
   let headerRow
-  let subHeaderRow
-  
   if(sheetName == '行政班'){
     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 == '教学班'){
     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. 添加数据行
   // 行政班  和 教学班 不一样
@@ -634,45 +590,44 @@ const LoopAddSheet=(finalTableColumn, finalTableData,workbook,sheetName )=>{
           bottom: { 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 () => {
-  // 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. 创建工作簿
   const workbook = new ExcelJS.Workbook();
 
   // 3. 添加sheet表
-  sheetList.forEach(item=>{
-    LoopAddSheet(item.tableColumn,item.tableData,workbook,item.sheetName)
-  })
+  LoopAddSheet(tableColumn,tableData,workbook,sheetName)
+
 
   // 4. 导出文件
   const buffer = await workbook.xlsx.writeBuffer();
@@ -683,7 +638,7 @@ const HandleExportExcel = async () => {
   const url = URL.createObjectURL(blob);
   const link = document.createElement('a');
   link.href = url;
-  link.download = `授课关系表_${new Date().toISOString().slice(0, 10)}.xlsx`;
+  link.download = `${gradeName}_${sheetName}授课关系表.xlsx`;
   link.style.visibility = 'hidden';
   document.body.appendChild(link);
   link.click();