|
@@ -35,7 +35,6 @@ const handleUploadChange = (file: File) => {
|
|
|
fileDocument.value = file; // 保存文件
|
|
|
const reader = new FileReader();
|
|
|
let fileType = file.name.slice(-4);
|
|
|
- console.log("文件", file.name.slice(-4));
|
|
|
if (fileType == "xlsx") {
|
|
|
reader.onload = e => {
|
|
|
const data = new Uint8Array(e.target?.result as ArrayBuffer);
|
|
@@ -43,16 +42,36 @@ const handleUploadChange = (file: File) => {
|
|
|
const firstSheetName = workbook.SheetNames[0]; // 获取第一个工作表名
|
|
|
const worksheet = workbook.Sheets[firstSheetName]; // 获取第一个工作表
|
|
|
const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); // 将工作表转为 JSON
|
|
|
+ console.log(jsonData, "获取的数据");
|
|
|
+ if (jsonData[1].length == 6) {
|
|
|
+ tableHeaders.value = [
|
|
|
+ "工号",
|
|
|
+ "人员",
|
|
|
+ "考核模板",
|
|
|
+ "指标名称",
|
|
|
+ "完成值",
|
|
|
+ "得分"
|
|
|
+ ]; // 表头
|
|
|
|
|
|
- if (jsonData.length > 0) {
|
|
|
- tableHeaders.value = jsonData[0]; // 表头
|
|
|
- tableData.value = jsonData.slice(1).map(row => {
|
|
|
- const rowData = {};
|
|
|
- tableHeaders.value.forEach((header, index) => {
|
|
|
- rowData[header] = row[index] !== undefined ? row[index] : null; // 填充缺失值
|
|
|
- });
|
|
|
- return rowData;
|
|
|
+ const arr = jsonData.slice(2).map(row => {
|
|
|
+ if (row[0] && row[1] && row[2] && row[3]) {
|
|
|
+ const rowData = {};
|
|
|
+ tableHeaders.value.forEach((header, index) => {
|
|
|
+ if (row[index]) {
|
|
|
+ rowData[header] = row[index];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return rowData;
|
|
|
+ }
|
|
|
});
|
|
|
+ tableData.value = arr.filter(item => item);
|
|
|
+ // tableData.value = jsonData.slice(1).map(row => {
|
|
|
+ // const rowData = {};
|
|
|
+ // tableHeaders.value.forEach((header, index) => {
|
|
|
+ // rowData[header] = row[index] !== undefined ? row[index] : null; // 填充缺失值
|
|
|
+ // });
|
|
|
+ // return rowData;
|
|
|
+ // });
|
|
|
console.log("表头", tableHeaders.value);
|
|
|
ElMessage.success("文件上传成功");
|
|
|
uploadShow.value = false; // 隐藏上传区域,显示数据表
|
|
@@ -74,6 +93,7 @@ const postImportAssessmentTemplateApi = async data => {
|
|
|
}
|
|
|
try {
|
|
|
const formData = new FormData();
|
|
|
+ console.log(fileDocument.value, "获取的数据");
|
|
|
formData.append("file", fileDocument.value); // 将文件添加到表单数据
|
|
|
|
|
|
// 调用 API 上传文件
|
|
@@ -118,12 +138,13 @@ const backDefine = () => {
|
|
|
<div class="w-full bg p-3">
|
|
|
<h5>1.下载导入模板</h5>
|
|
|
<p class="text-xs mt-2 text">根据提升信息完善表格内容</p>
|
|
|
- <el-button
|
|
|
- class="mt-2"
|
|
|
- @click="
|
|
|
- assessmentDownloadDataRosterTemplateApi(route.query.assessmentType)
|
|
|
- "
|
|
|
- ><el-icon><Download /></el-icon>下载空的模板表格</el-button
|
|
|
+ <el-button class="mt-2"
|
|
|
+ ><el-icon> <Download /> </el-icon
|
|
|
+ ><a
|
|
|
+ href="http://116.148.231.9:9999/download/考核数据导入模板-人员.xlsx"
|
|
|
+ download="考核数据导入模板-人员.xlsx"
|
|
|
+ >下载空的模板表格</a
|
|
|
+ ></el-button
|
|
|
>
|
|
|
</div>
|
|
|
<div class="w-full mt-4 bg p-3">
|