|
@@ -14,6 +14,8 @@ 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 { selectObj } from './select'
|
|
|
|
|
|
export enum EXPORT_WORD_ENUM {
|
|
|
/** 借用藏品点交凭证 */
|
|
@@ -55,10 +57,95 @@ export enum EXPORT_WORD_ENUM {
|
|
|
/** 藏品现状登记 */
|
|
|
COLLECTION_CURRENT_STATUS = 19,
|
|
|
/** 馆内展览借用藏品登记台账 */
|
|
|
- REGISTER_LEDGER = 20
|
|
|
+ REGISTER_LEDGER = 20,
|
|
|
+ /** 藏品总账 */
|
|
|
+ COLLECTION_LEDGER = 21,
|
|
|
+ /** 藏品提退出入库登记流水账 */
|
|
|
+ COLLECTION_LOG = 22
|
|
|
}
|
|
|
|
|
|
export const EXPORT_TEMPLATE_MAP: Record<EXPORT_WORD_ENUM, ITEMPLATE> = {
|
|
|
+ [EXPORT_WORD_ENUM.COLLECTION_LOG]: {
|
|
|
+ fileName: '藏品提退出入库登记流水账',
|
|
|
+ options: {
|
|
|
+ sheetHeader: [
|
|
|
+ '序号',
|
|
|
+ '藏品总登记号',
|
|
|
+ '分类号',
|
|
|
+ '点交凭证单号',
|
|
|
+ '藏品名称',
|
|
|
+ '计件数量',
|
|
|
+ '文物现状',
|
|
|
+ ['出库记录', '提用人', '点交人', '出库时间'],
|
|
|
+ ['退库记录', '退还人', '点收人', '退库时间'],
|
|
|
+ '备注'
|
|
|
+ ],
|
|
|
+ sheetFilter: [
|
|
|
+ 'index',
|
|
|
+ 'num',
|
|
|
+ 'numType',
|
|
|
+ 'orderNum',
|
|
|
+ 'name',
|
|
|
+ 'pcs',
|
|
|
+ 'preserveState',
|
|
|
+ 'ckUser1',
|
|
|
+ 'ckUser2',
|
|
|
+ 'ckDate',
|
|
|
+ 'tkUser1',
|
|
|
+ 'tkUser2',
|
|
|
+ 'tkDate',
|
|
|
+ 'snapRtf'
|
|
|
+ ],
|
|
|
+ columnWidths: [5, 14, 8, 10, 15, 10, 10, 10, 10, 14, 10, 10, 14, 10]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [EXPORT_WORD_ENUM.COLLECTION_LEDGER]: {
|
|
|
+ fileName: '藏品总账',
|
|
|
+ options: {
|
|
|
+ sheetHeader: [
|
|
|
+ ['登记日期', '年', '月', '日'],
|
|
|
+ '藏品总登记号',
|
|
|
+ '分类号',
|
|
|
+ '藏品名称',
|
|
|
+ '时代',
|
|
|
+ ['计件', '单位', '件数'],
|
|
|
+ '尺寸、重量',
|
|
|
+ '质地',
|
|
|
+ '完残情况',
|
|
|
+ '来源',
|
|
|
+ '采集地点',
|
|
|
+ ['入馆日期', '年', '月', '日'],
|
|
|
+ '入馆凭证号',
|
|
|
+ '注销凭证号',
|
|
|
+ '级别',
|
|
|
+ '备注'
|
|
|
+ ],
|
|
|
+ sheetFilter: [
|
|
|
+ 'year',
|
|
|
+ 'month',
|
|
|
+ 'day',
|
|
|
+ 'num',
|
|
|
+ 'numType',
|
|
|
+ 'name',
|
|
|
+ 'dictAge',
|
|
|
+ 'pcsUnit',
|
|
|
+ '_pcs',
|
|
|
+ 'size',
|
|
|
+ 'dictTexture',
|
|
|
+ 'dictTorn',
|
|
|
+ 'source',
|
|
|
+ '',
|
|
|
+ 'year2',
|
|
|
+ 'month2',
|
|
|
+ 'day2',
|
|
|
+ 'inHouseNum',
|
|
|
+ '',
|
|
|
+ 'dictLevel',
|
|
|
+ 'rtf'
|
|
|
+ ],
|
|
|
+ columnWidths: [5, 5, 5, 10, 5, 10, 10, 5, 5, 10, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10]
|
|
|
+ }
|
|
|
+ },
|
|
|
[EXPORT_WORD_ENUM.COLLECTION_CURRENT_STATUS]: {
|
|
|
fileName: '藏品现状登记',
|
|
|
templateName: '16.docx'
|
|
@@ -335,11 +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))
|
|
|
- try {
|
|
|
- good.thumb && (good.thumb = await getBase64Sync(baseURL + good.thumb))
|
|
|
- } catch (err) {
|
|
|
- console.log('thumb conversion to base64 faild:', err)
|
|
|
- good.thumb = ''
|
|
|
+ if (item.options?.sheetFilter.includes('thumb')) {
|
|
|
+ try {
|
|
|
+ good.thumb && (good.thumb = await getBase64Sync(baseURL + good.thumb))
|
|
|
+ } catch (err) {
|
|
|
+ console.log('thumb conversion to base64 faild:', err)
|
|
|
+ good.thumb = ''
|
|
|
+ }
|
|
|
}
|
|
|
good.dictAge && (good.dictAge = resJiLianFu(good.dictAge))
|
|
|
good.pcsUnit && (good.pcsUnit = resJiLianFu(good.pcsUnit))
|
|
@@ -347,6 +436,8 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
good._pcs = good.pcs
|
|
|
good.pcs = good.pcs + good.pcsUnit
|
|
|
}
|
|
|
+ good.accountType &&
|
|
|
+ (good.accountType = selectObj['入藏去向'].find(i => i.value === good.accountType)?.label)
|
|
|
good.dictTexture3 && (good.dictTexture = resJiLianFu(good.dictTexture3))
|
|
|
good.dictTorn && (good.dictTorn = resJiLianFu(good.dictTorn))
|
|
|
good.source && (good.source = resJiLianFu(good.source))
|
|
@@ -361,12 +452,12 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
temp.goods = []
|
|
|
}
|
|
|
|
|
|
- // @ts-ignore
|
|
|
if (item.perLine) {
|
|
|
// @ts-ignore
|
|
|
page = calcTablePages(temp.goods, item)
|
|
|
}
|
|
|
|
|
|
+ // 处理业务数据
|
|
|
switch (type) {
|
|
|
case EXPORT_WORD_ENUM.BORROW:
|
|
|
temp = {
|
|
@@ -796,113 +887,161 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
})
|
|
|
}
|
|
|
break
|
|
|
- }
|
|
|
+ case EXPORT_WORD_ENUM.COLLECTION_LOG:
|
|
|
+ excelHandler = worksheet => {
|
|
|
+ const borderStyle: ExcelJS.Border = {
|
|
|
+ style: 'thin',
|
|
|
+ color: { argb: 'FF000000' }
|
|
|
+ }
|
|
|
|
|
|
- if (!item.templateName) {
|
|
|
- // 没有templateName则输出excel
|
|
|
- let mergeHeadNum = 0
|
|
|
- let headTemp: string[] = []
|
|
|
- let fatherHeadTemp: {
|
|
|
- title: string
|
|
|
- position: string[]
|
|
|
- }[] = []
|
|
|
- // 表头需要占据的行数
|
|
|
- const headRow = Math.max(
|
|
|
- ...item.options?.sheetHeader.map((head: string | string[]) =>
|
|
|
- Array.isArray(head) ? head.length - 1 : 1
|
|
|
- )
|
|
|
- )
|
|
|
- const workbook = new ExcelJS.Workbook()
|
|
|
- const worksheet = workbook.addWorksheet('Sheet1', {
|
|
|
- properties: { defaultRowHeight: 30 },
|
|
|
- views: [{ showGridLines: false }],
|
|
|
- pageSetup: {
|
|
|
- horizontalCentered: true,
|
|
|
- verticalCentered: true,
|
|
|
- paperSize: 9
|
|
|
- }
|
|
|
- })
|
|
|
+ for (let row = 1; row <= temp.goods.length + 2; row++) {
|
|
|
+ for (let col = 1; col <= 14; col++) {
|
|
|
+ const cell = worksheet.getCell(row, col)
|
|
|
+ cell.border = {
|
|
|
+ top: borderStyle,
|
|
|
+ left: borderStyle,
|
|
|
+ bottom: borderStyle,
|
|
|
+ right: borderStyle
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- item.options?.sheetHeader.forEach((head: string | string[], index: number) => {
|
|
|
- if (Array.isArray(head)) {
|
|
|
- fatherHeadTemp.push({
|
|
|
- title: head.shift() || '',
|
|
|
- position: [
|
|
|
- `${getExcelColumnLetter(index + mergeHeadNum)}1`,
|
|
|
- `${getExcelColumnLetter(index + head.length - 1 + mergeHeadNum)}1`
|
|
|
- ]
|
|
|
+ worksheet.eachRow(row => {
|
|
|
+ row.eachCell(cell => {
|
|
|
+ cell.alignment = {
|
|
|
+ vertical: 'middle',
|
|
|
+ horizontal: 'center',
|
|
|
+ wrapText: true
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
- headTemp.push(...head)
|
|
|
- mergeHeadNum++
|
|
|
- } else {
|
|
|
- headTemp.push(head)
|
|
|
}
|
|
|
- })
|
|
|
- worksheet.addRow(headTemp)
|
|
|
- if (fatherHeadTemp.length) {
|
|
|
- // 存在需要合并的父级表头
|
|
|
- worksheet.insertRow(1, [])
|
|
|
- fatherHeadTemp.forEach(head => {
|
|
|
- const cell = worksheet.getCell(head.position[0])
|
|
|
- cell.value = head.title
|
|
|
- worksheet.mergeCells(`${head.position[0]}:${head.position[1]}`)
|
|
|
+ break
|
|
|
+ case EXPORT_WORD_ENUM.COLLECTION_LEDGER:
|
|
|
+ temp.goods.forEach((i: any) => {
|
|
|
+ const createTime = dayjs(i.createTime)
|
|
|
+ const inHouseTime = dayjs(i.createTime)
|
|
|
+ i.year = createTime.format('YYYY')
|
|
|
+ i.month = createTime.format('MM')
|
|
|
+ i.day = createTime.format('DD')
|
|
|
+ i.year2 = inHouseTime.format('YYYY')
|
|
|
+ i.month2 = inHouseTime.format('MM')
|
|
|
+ i.day2 = inHouseTime.format('DD')
|
|
|
})
|
|
|
- }
|
|
|
- if (headRow > 1) {
|
|
|
- // 合并表头列
|
|
|
- headTemp.forEach((head, index) => {
|
|
|
- const pos = `${getExcelColumnLetter(index)}1:${getExcelColumnLetter(index)}${headRow}`
|
|
|
- const cell = worksheet.getCell(`${getExcelColumnLetter(index)}1`)
|
|
|
- if (!cell.isMerged) {
|
|
|
- worksheet.mergeCells(pos)
|
|
|
- cell.value = head
|
|
|
+
|
|
|
+ excelHandler = worksheet => {
|
|
|
+ const borderStyle: ExcelJS.Border = {
|
|
|
+ style: 'thin',
|
|
|
+ color: { argb: 'FF000000' }
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
|
|
|
- temp.goods.forEach((good: Record<string, any>, goodIndex: number) => {
|
|
|
- const _temp: string[] = []
|
|
|
- item.options?.sheetFilter.forEach((key: string, index: number) => {
|
|
|
- _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)
|
|
|
- })
|
|
|
+ for (let row = 1; row <= temp.goods.length + 2; row++) {
|
|
|
+ for (let col = 1; col <= 21; col++) {
|
|
|
+ const cell = worksheet.getCell(row, col)
|
|
|
+ cell.border = {
|
|
|
+ top: borderStyle,
|
|
|
+ left: borderStyle,
|
|
|
+ bottom: borderStyle,
|
|
|
+ right: borderStyle
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 设置宽度
|
|
|
- item.options?.columnWidths.forEach((width: number, index: number) => {
|
|
|
- worksheet.getColumn(index + 1).width = width
|
|
|
- })
|
|
|
+ worksheet.eachRow(row => {
|
|
|
+ row.eachCell(cell => {
|
|
|
+ cell.alignment = {
|
|
|
+ vertical: 'middle',
|
|
|
+ horizontal: 'center',
|
|
|
+ wrapText: true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
|
|
|
- excelHandler(worksheet)
|
|
|
+ if (!item.templateName) {
|
|
|
+ // 没有templateName则输出 excel
|
|
|
+ exportTempExcel(item.fileName, worksheet => {
|
|
|
+ let mergeHeadNum = 0
|
|
|
+ let headTemp: string[] = []
|
|
|
+ let fatherHeadTemp: {
|
|
|
+ title: string
|
|
|
+ position: string[]
|
|
|
+ }[] = []
|
|
|
+ // 表头需要占据的行数
|
|
|
+ const headRow = Math.max(
|
|
|
+ ...item.options?.sheetHeader.map((head: string | string[]) => (Array.isArray(head) ? 2 : 1))
|
|
|
+ )
|
|
|
|
|
|
- const buffer = await workbook.xlsx.writeBuffer()
|
|
|
- const blob = new Blob([buffer], {
|
|
|
- type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
- })
|
|
|
+ item.options?.sheetHeader.forEach((head: string | string[], index: number) => {
|
|
|
+ if (Array.isArray(head)) {
|
|
|
+ fatherHeadTemp.push({
|
|
|
+ title: head.shift() || '',
|
|
|
+ position: [
|
|
|
+ `${getExcelColumnLetter(index + mergeHeadNum)}1`,
|
|
|
+ `${getExcelColumnLetter(index + head.length - 1 + mergeHeadNum)}1`
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ headTemp.push(...head)
|
|
|
+ mergeHeadNum += head.length - 1
|
|
|
+ } else {
|
|
|
+ headTemp.push(head)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ worksheet.addRow(headTemp)
|
|
|
+ if (fatherHeadTemp.length) {
|
|
|
+ // 存在需要合并的父级表头
|
|
|
+ worksheet.insertRow(1, [])
|
|
|
+ fatherHeadTemp.forEach(head => {
|
|
|
+ const cell = worksheet.getCell(head.position[0])
|
|
|
+ cell.value = head.title
|
|
|
+ worksheet.mergeCells(`${head.position[0]}:${head.position[1]}`)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (headRow > 1) {
|
|
|
+ // 合并表头列
|
|
|
+ headTemp.forEach((head, index) => {
|
|
|
+ const pos = `${getExcelColumnLetter(index)}1:${getExcelColumnLetter(index)}${headRow}`
|
|
|
+ const cell = worksheet.getCell(`${getExcelColumnLetter(index)}1`)
|
|
|
+ if (!cell.isMerged) {
|
|
|
+ worksheet.mergeCells(pos)
|
|
|
+ cell.value = head
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ temp.goods.forEach((good: Record<string, any>, goodIndex: number) => {
|
|
|
+ const _temp: string[] = []
|
|
|
+ item.options?.sheetFilter.forEach((key: string, index: number) => {
|
|
|
+ _temp.push(good[key])
|
|
|
|
|
|
- const url = URL.createObjectURL(blob)
|
|
|
- const a = document.createElement('a')
|
|
|
- a.href = url
|
|
|
- a.download = item.fileName + '.xlsx'
|
|
|
- a.click()
|
|
|
+ // 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)
|
|
|
+ })
|
|
|
|
|
|
- // 释放内存
|
|
|
- setTimeout(() => URL.revokeObjectURL(url), 100)
|
|
|
+ // 设置宽度
|
|
|
+ item.options?.columnWidths.forEach((width: number, index: number) => {
|
|
|
+ worksheet.getColumn(index + 1).width = width
|
|
|
+ })
|
|
|
+
|
|
|
+ excelHandler(worksheet)
|
|
|
+ })
|
|
|
} else {
|
|
|
+ // 输出 word
|
|
|
exportWordDocx(`./templates/${item.templateName}`, temp, item.fileName)
|
|
|
}
|
|
|
}
|