新增报表导出文件管理模块,包含后端接口和前端页面 在各类报表页面添加保存报表功能 优化CoilSelector和CoilCard组件显示 调整分页大小和表格高度 统一各产线报表配置 修复文件预览组件高度问题
55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
import { uploadFile } from "@/api/system/oss";
|
|
import { exportCoilWithAll } from "@/api/wms/coil";
|
|
import { addExportFile } from "@/api/wms/exportFile";
|
|
|
|
export async function saveReportFile(coilIds, { reportParams, productionLine, reportType }) {
|
|
// 使用exportCoilWithAll接口传入coilIds获取二进制文件数据
|
|
if (!coilIds) {
|
|
throw new Error('无数据,无法保存')
|
|
}
|
|
const response = await exportCoilWithAll({ coilIds })
|
|
// 构建报告标题
|
|
function addZero(num) {
|
|
return num < 10 ? '0' + num : num
|
|
}
|
|
|
|
const now = new Date()
|
|
const year = now.getFullYear()
|
|
const month = addZero(now.getMonth() + 1)
|
|
const day = addZero(now.getDate())
|
|
console.log(productionLine)
|
|
const reportTitle = `${year}-${month}-${day}_${reportType}_${productionLine || '全厂'}`
|
|
// reportName 后再增加时间戳,避免重复
|
|
const reportName = `${reportTitle}_${new Date().getTime()}`
|
|
|
|
const file = new Blob([response], { type: 'application/vnd.ms-excel' })
|
|
const fileName = reportTitle + '.xlsx'
|
|
// 通过new File构建出excel文件
|
|
const excelFile = new File([file], fileName, { type: 'application/vnd.ms-excel' })
|
|
// 上传文件到minio
|
|
const uploadResponse = await uploadFile(excelFile)
|
|
// 构建请求体创建文件保存记录
|
|
const reportExportFile = {
|
|
reportName,
|
|
reportTitle,
|
|
reportParams: JSON.stringify(reportParams, null, 2),
|
|
productionLine,
|
|
reportType,
|
|
attachment: uploadResponse.data.url,
|
|
ossId: uploadResponse.data.ossId,
|
|
}
|
|
// 调用addExportFile接口创建文件保存记录
|
|
const res = await addExportFile(reportExportFile)
|
|
return true;
|
|
}
|
|
|
|
function createReportTitle(reportType, productionLine) {
|
|
// 获取一个yyyy-MM-dd格式的北京时间字符串
|
|
const now = new Date()
|
|
const year = now.getFullYear()
|
|
const month = addZero(now.getMonth() + 1)
|
|
const day = addZero(now.getDate())
|
|
console.log(year, month, day)
|
|
return `${year}-${month}-${day}_${reportType}_${productionLine || '全场'}`
|
|
}
|