From e6c3fccc9e412e79964a6dc2dae4c3da0c80095c Mon Sep 17 00:00:00 2001 From: licp <lichunping@guanfang.com.cn> Date: 星期二, 26 十一月 2024 15:22:28 +0800 Subject: [PATCH] 完成检验下单、检验任务、报告生成变更 --- src/components/tool/file-preview.vue | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/components/tool/file-preview.vue b/src/components/tool/file-preview.vue index d95afab..38ea63e 100644 --- a/src/components/tool/file-preview.vue +++ b/src/components/tool/file-preview.vue @@ -11,7 +11,7 @@ <div v-if="isDoc"> <p v-if="!isDocShow">鏂囨。鏃犳硶鐩存帴棰勮锛岃涓嬭浇鏌ョ湅銆�</p> <a :href="fileUrl" v-if="!isDocShow">涓嬭浇鏂囦欢</a> - <vue-office-docx + <vue-office-docx v-else :src="fileUrl" style="height: 100vh;" @rendered="renderedHandler" @@ -21,7 +21,7 @@ <div v-if="isXls"> <p v-if="!isDocShow">鏂囨。鏃犳硶鐩存帴棰勮锛岃涓嬭浇鏌ョ湅銆�</p> <a :href="fileUrl" v-if="!isDocShow">涓嬭浇鏂囦欢</a> - <vue-office-excel + <vue-office-excel v-else :src="fileUrl" :options="options" style="height: 100vh;" @@ -67,6 +67,7 @@ import VueOfficeExcel from '@vue-office/excel' //寮曞叆鐩稿叧鏍峰紡 import '@vue-office/excel/lib/index.css' +import * as XLSX from "xlsx"; export default { components: { VueOfficeDocx, @@ -108,7 +109,15 @@ return /\.(doc|docx)$/i.test(this.fileUrl); }, isXls(){ - return /\.(xls|xlsx)$/i.test(this.fileUrl); + let state = /\.(xls|xlsx)$/i.test(this.fileUrl) + if(state){ + if(/\.(xlsx)$/i.test(this.fileUrl)){ + this.options.xls = false + }else{ + this.options.xls = true + } + } + return state; }, isZipOrRar() { return /\.(zip|rar)$/i.test(this.fileUrl); @@ -156,6 +165,11 @@ return obj }) this.csvList = arr + // console.log(333,this.csvList) + this.csvList.forEach(m=>{ + console.log(this.calculateFormulas(m.column,m.tableData)) + m.tableData = this.calculateFormulas(m.column,m.tableData) + }) }).catch( err => { console.log(err) }) @@ -197,6 +211,28 @@ } return result }, + /** + * 璁$畻琛ㄦ牸鍏紡 + * + * @param tableHeaders 琛ㄥご鏁版嵁 + * @param tableData 琛ㄦ牸鏁版嵁 + */ + calculateFormulas(tableHeaders,tableData){ + // 鐢熸垚 Excel Sheet 鏍煎紡 + const sheetData = [tableHeaders.map(m=>m.label), ...tableData.map((row) => Object.values(row))]; + const worksheet = XLSX.utils.aoa_to_sheet(sheetData); + // 璁$畻鍏紡 + XLSX.utils.sheet_add_aoa(worksheet, [], { origin: -1 }); + const newSheetData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); + // 鏇存柊琛ㄥご鍜岃〃鏍兼暟鎹� + tableData = newSheetData.slice(1).map((row) => + row.reduce((obj, value, index) => { + obj[newSheetData[0][index]] = value; + return obj; + }, {}) + ); + return tableData + }, resetStyle(){ const elements = document.querySelectorAll('[style*="pt"]'); for (const element of elements) { @@ -205,7 +241,7 @@ element.setAttribute('style', style.replace(/pt/g, 'px')); } } - } + }, } } </script> -- Gitblit v1.9.3