|
@@ -1,4 +1,4 @@
|
|
|
-import { cloneDeep } from 'lodash'
|
|
|
+import { cloneDeep, isNumber } from 'lodash'
|
|
|
import ExcelJS from 'exceljs'
|
|
|
import { exportWordDocx, getBase64Sync } from './exportWord'
|
|
|
import { baseURL } from './http'
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
import { myTableTransferSize } from '@/components/MyTable'
|
|
|
import dayjs from 'dayjs'
|
|
|
import { D7CEHCK_COLLECTION_RESULT_OPTIONS } from '@/pages/D_storeManage/D7check/constants'
|
|
|
-import { exportTempExcel } from './exportExcelUtils'
|
|
|
+import { exportTempExcel, getImageBase64Extension } from './exportExcelUtils'
|
|
|
import { selectObj } from './select'
|
|
|
|
|
|
export enum EXPORT_WORD_ENUM {
|
|
@@ -293,7 +293,7 @@ export const EXPORT_TEMPLATE_MAP: Record<EXPORT_WORD_ENUM, ITEMPLATE> = {
|
|
|
'num',
|
|
|
'numType',
|
|
|
'name',
|
|
|
- 'img',
|
|
|
+ 'thumb',
|
|
|
'pcs',
|
|
|
'dictTexture',
|
|
|
'dictAge',
|
|
@@ -422,9 +422,13 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
const good = temp.goods[i]
|
|
|
good.index = i + 1
|
|
|
good.rtf && (good.rtf = removeHtmlTags(JSON.parse(good.rtf).txtArr[0].txt))
|
|
|
- if (item.options?.sheetFilter.includes('thumb')) {
|
|
|
+ // excel 需要判断表格中是否需要图片
|
|
|
+ if (!item.templateName ? item.options?.sheetFilter.includes('thumb') : good.thumb) {
|
|
|
try {
|
|
|
- good.thumb && (good.thumb = await getBase64Sync(baseURL + good.thumb))
|
|
|
+ good.thumb = await getBase64Sync(
|
|
|
+ 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
|
|
|
+ )
|
|
|
+ // good.thumb = await getBase64Sync(baseURL + good.thumb)
|
|
|
} catch (err) {
|
|
|
console.log('thumb conversion to base64 faild:', err)
|
|
|
good.thumb = ''
|
|
@@ -444,9 +448,7 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
good.dictAgeFirst && (good.dictAgeFirst = resJiLianFu(good.dictAgeFirst))
|
|
|
good.qualityUnit && (good.qualityUnit = resJiLianFu(good.qualityUnit))
|
|
|
if (good.sizeUnit || good.quality)
|
|
|
- good.size = good.sizeUnit
|
|
|
- ? myTableTransferSize(good.sizeUnit)
|
|
|
- : good.quality + good.qualityUnit
|
|
|
+ good.size = good.sizeUnit ? myTableTransferSize(good) : good.quality + good.qualityUnit
|
|
|
}
|
|
|
} else {
|
|
|
temp.goods = []
|
|
@@ -502,11 +504,12 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
break
|
|
|
case EXPORT_WORD_ENUM.VOUCHER:
|
|
|
case EXPORT_WORD_ENUM.STORAGE_VOUCHER:
|
|
|
+ const _date = dayjs(temp.date)
|
|
|
temp = {
|
|
|
...temp,
|
|
|
- year: date.format('YYYY'),
|
|
|
- month: date.format('MM'),
|
|
|
- day: date.format('DD'),
|
|
|
+ year: _date.format('YYYY'),
|
|
|
+ month: _date.format('MM'),
|
|
|
+ day: _date.format('DD'),
|
|
|
group: numberToChinese(temp.goods.length),
|
|
|
page: numberToChinese(page)
|
|
|
}
|
|
@@ -649,17 +652,16 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
.filter(([_, count]) => count > 0)
|
|
|
.map(
|
|
|
([level, count]) =>
|
|
|
- `${level === '一般' ? level + '珍贵文物' : level + '文物'}${count}件/组;\n`
|
|
|
+ `${level === '一般' ? level + '珍贵文物' : level + '文物'}${count}件/组;`
|
|
|
)
|
|
|
- .join(';')
|
|
|
+ .join('\n')
|
|
|
|
|
|
temp.goods.push({
|
|
|
index: '鉴\n定\n人\n员',
|
|
|
num: temp.authUser,
|
|
|
- img: '鉴\n定\n单\n位',
|
|
|
+ thumb: '鉴\n定\n单\n位',
|
|
|
pcs: temp.authUnit,
|
|
|
dictAge: '核\n准\n单\n位',
|
|
|
- size: temp.confirmUnit,
|
|
|
dictTorn: '说\n\n明',
|
|
|
dictLevel: `鉴定日期:${temp.date}\n鉴定总数${temp.goods.length}件/组,其中:\n${resultText}`
|
|
|
})
|
|
@@ -667,7 +669,19 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
excelHandler = worksheet => {
|
|
|
const lastIndex = temp.goods.length + 2
|
|
|
|
|
|
+ worksheet.insertRow(1, ['单位:义乌市博物馆'])
|
|
|
+ worksheet.mergeCells('A1:H1')
|
|
|
+ worksheet.mergeCells('I1:L1')
|
|
|
+ worksheet.mergeCells(`B${lastIndex}:D${lastIndex}`)
|
|
|
+ worksheet.mergeCells(`F${lastIndex}:G${lastIndex}`)
|
|
|
+ worksheet.mergeCells(`K${lastIndex}:L${lastIndex}`)
|
|
|
+
|
|
|
worksheet.eachRow(row => {
|
|
|
+ const col5 = row.getCell(5)
|
|
|
+ if (isNumber(col5.value)) {
|
|
|
+ worksheet.addImage(col5.value, `${col5.address}:${col5.address}`)
|
|
|
+ }
|
|
|
+
|
|
|
row.eachCell(cell => {
|
|
|
cell.style = {
|
|
|
font: {
|
|
@@ -683,13 +697,6 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- worksheet.insertRow(1, ['单位:义乌市博物馆'])
|
|
|
- worksheet.mergeCells('A1:H1')
|
|
|
- worksheet.mergeCells('I1:L1')
|
|
|
- worksheet.mergeCells(`B${lastIndex}:D${lastIndex}`)
|
|
|
- worksheet.mergeCells(`F${lastIndex}:G${lastIndex}`)
|
|
|
- worksheet.mergeCells(`K${lastIndex}:L${lastIndex}`)
|
|
|
-
|
|
|
const titleCell = worksheet.getCell('A1')
|
|
|
const dateCell = worksheet.getCell('I1')
|
|
|
const lastCell = worksheet.getRow(lastIndex)
|
|
@@ -961,7 +968,7 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
|
|
|
if (!item.templateName) {
|
|
|
// 没有templateName则输出 excel
|
|
|
- exportTempExcel(item.fileName, worksheet => {
|
|
|
+ exportTempExcel(item.fileName, (worksheet, workbook) => {
|
|
|
let mergeHeadNum = 0
|
|
|
let headTemp: string[] = []
|
|
|
let fatherHeadTemp: {
|
|
@@ -1013,21 +1020,18 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
temp.goods.forEach((good: Record<string, any>, goodIndex: number) => {
|
|
|
const _temp: string[] = []
|
|
|
item.options?.sheetFilter.forEach((key: string, index: number) => {
|
|
|
+ if (key === 'thumb' && Boolean(good[key])) {
|
|
|
+ const extension = getImageBase64Extension(good[key])
|
|
|
+ if (extension) {
|
|
|
+ // 插入图片
|
|
|
+ const imageId = workbook.addImage({
|
|
|
+ base64: good[key],
|
|
|
+ extension
|
|
|
+ })
|
|
|
+ good[key] = imageId
|
|
|
+ }
|
|
|
+ }
|
|
|
_temp.push(good[key])
|
|
|
-
|
|
|
- // if (key === 'thumb' && Boolean(good[key])) {
|
|
|
- // // 插入图片
|
|
|
- // const imageId = workbook.addImage({
|
|
|
- // base64: good[key],
|
|
|
- // extension: 'jpeg'
|
|
|
- // })
|
|
|
- // worksheet.addImage(
|
|
|
- // imageId,
|
|
|
- // `${getExcelColumnLetter(index)}${goodIndex + 2}:${getExcelColumnLetter(index)}${
|
|
|
- // goodIndex + 2
|
|
|
- // }`
|
|
|
- // )
|
|
|
- // }
|
|
|
})
|
|
|
worksheet.addRow(_temp)
|
|
|
})
|