diff --git a/src/utils/index.js b/src/utils/index.js index 2eb7065..7c1eceb 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -563,3 +563,21 @@ export function isRegent(item, fieldCode = 'type') { ] return typeList.includes(type) } +/** + * 估算字符串在 Excel 中的显示宽度(简单规则:中文字符算2,英文字符算1) + * @param {string} str 要计算的字符串 + * @returns {number} 估算宽度 + */ +export function getStringWidth(str) { + if (!str) return 0 + let width = 0 + for (let char of str.toString()) { + // 中文字符范围(可根据需要扩展) + if (/[\u4e00-\u9fa5]/.test(char)) { + width += 2 + } else { + width += 1 + } + } + return width +} diff --git a/src/views/business/comps/template/mixins/templateMixin.js b/src/views/business/comps/template/mixins/templateMixin.js index 46b73ea..7ccff69 100644 --- a/src/views/business/comps/template/mixins/templateMixin.js +++ b/src/views/business/comps/template/mixins/templateMixin.js @@ -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 = '
| ' + item + ' | '; - }); - tableHtml += '
|---|