|
|
|
@ -1,10 +1,11 @@ |
|
|
|
import moment from 'moment' |
|
|
|
import { getLatestSn, getLatestSnArr } from '@/api/template'; |
|
|
|
import { isValueEmpty } from '@/utils/index'; |
|
|
|
import { isValueEmpty, getStringWidth } from '@/utils/index'; |
|
|
|
import { isCommonUnit } from "@/utils/conTools"; |
|
|
|
import { sj_subpackage, sj_startConfiguration, sj_configurationCompleted } from '@/api/business/sj/sj'; |
|
|
|
import {convertConcentration} from "@/utils/conConverter";//浓度单位转换
|
|
|
|
import {volumeConverter} from "@/utils/volConverter";//体积单位转换
|
|
|
|
import * as XLSX from 'xlsx' |
|
|
|
export default { |
|
|
|
dicts: [ |
|
|
|
'business_pztj', |
|
|
|
@ -602,54 +603,16 @@ export default { |
|
|
|
} |
|
|
|
}, |
|
|
|
// 导出excel模板
|
|
|
|
exportExcel(rows, title) { |
|
|
|
exportExcel(headerArray, title = '导出模板') { |
|
|
|
this.$modal.loading() |
|
|
|
// 生成表头
|
|
|
|
let tableHtml = '<table border="1" class="html-tabel">'; |
|
|
|
tableHtml += '<tr style="background:#eee;">'; |
|
|
|
rows.forEach(item => { |
|
|
|
tableHtml += '<th style="text-align: center;">' + item + '</th>'; |
|
|
|
}); |
|
|
|
tableHtml += '</tr></table>'; // 正确闭合
|
|
|
|
|
|
|
|
// Worksheet 名称
|
|
|
|
const worksheet = title ? title : '导入模板'; |
|
|
|
|
|
|
|
// 完整的 HTML 模板(包含编码声明和 Excel 兼容命名空间)
|
|
|
|
const exportTemplate = `<!DOCTYPE html>
|
|
|
|
<html xmlns:o="urn:schemas-microsoft-com:office:office" |
|
|
|
xmlns:x="urn:schemas-microsoft-com:office:excel" |
|
|
|
xmlns="http://www.w3.org/1999/xhtml"> |
|
|
|
<head> |
|
|
|
<meta charset="UTF-8"> |
|
|
|
<!--[if gte mso 9]> |
|
|
|
<xml> |
|
|
|
<x:ExcelWorkbook> |
|
|
|
<x:ExcelWorksheets> |
|
|
|
<x:ExcelWorksheet> |
|
|
|
<x:Name>${worksheet}</x:Name> |
|
|
|
<x:WorksheetOptions> |
|
|
|
<x:DisplayGridlines/> |
|
|
|
</x:WorksheetOptions> |
|
|
|
</x:ExcelWorksheet> |
|
|
|
</x:ExcelWorksheets> |
|
|
|
</x:ExcelWorkbook> |
|
|
|
</xml> |
|
|
|
<![endif]--> |
|
|
|
</head> |
|
|
|
<body> |
|
|
|
${tableHtml} |
|
|
|
</body> |
|
|
|
</html>`; |
|
|
|
|
|
|
|
// 使用 Blob 生成文件(指定 MIME 类型为 application/vnd.ms-excel)
|
|
|
|
const blob = new Blob([exportTemplate], { type: 'application/vnd.ms-excel;charset=utf-8' }); |
|
|
|
const link = document.createElement('a'); |
|
|
|
link.href = URL.createObjectURL(blob); |
|
|
|
link.download = worksheet + '.xls'; |
|
|
|
link.click(); |
|
|
|
URL.revokeObjectURL(link.href); // 释放内存
|
|
|
|
const ws = XLSX.utils.aoa_to_sheet([headerArray]); |
|
|
|
const colWidths = headerArray.map(cell => getStringWidth(cell) + 2); |
|
|
|
ws['!cols'] = colWidths.map(width => ({ wch: width })); |
|
|
|
const wb = XLSX.utils.book_new(); |
|
|
|
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1'); |
|
|
|
XLSX.writeFile(wb, `${title}.xlsx`); |
|
|
|
this.$modal.closeLoading() |
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
} |