合同打印增加

pull/781/head
quu 2025-05-04 15:34:00 +09:00
parent 08179a9f7f
commit cd17dd9d5f
2 changed files with 45 additions and 5 deletions

View File

@ -147,9 +147,14 @@ export const getOrgInfo = async (params) => {
// 打印合同 // 打印合同
export const printContract = async (id: number) => { export const printContract = async (id: number) => {
return await request.put({ url: `/crm/contract/print?id=${id}` }) return await request.get({
url: `/crm/contract/print`,
params: { contractId: id },
responseType: 'blob' // 必须加这个才能下载文件
})
} }
// ==================== 子表CRM 合同产品关联) ==================== // ==================== 子表CRM 合同产品关联) ====================
// 获得CRM 合同产品关联列表 // 获得CRM 合同产品关联列表

View File

@ -446,10 +446,45 @@ const handleSubmit = async (row: ContractApi.ContractVO) => {
} }
const onPrintContract = async (row: ContractApi.ContractVO) => { const onPrintContract = async (row: ContractApi.ContractVO) => {
try {
await message.confirm(`您确定打印【${row.name}】合同吗?`) await message.confirm(`您确定打印【${row.name}】合同吗?`)
await ContractApi.printContract(row.id) const res = await ContractApi.printContract(row.id)
if (!res) {
throw new Error('返回的合同文件为空')
}
const contentType = res.type.toLowerCase()
let fileType = 'application/msword' // 使 .doc MIME
let extension = '.doc'
if (contentType.includes('wordprocessingml')) {
fileType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' // .docx MIME
extension = '.docx'
}
// blob
const blob = new Blob([res], { type: fileType })
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
const disposition = res.headers['content-disposition']
let fileName = '合同.docx'
if (disposition && disposition.includes('filename=')) {
const match = disposition.match(/filename="?([^"]+)"?/)
if (match?.[1]) {
fileName = decodeURIComponent(match[1])
}
}
link.click()
window.URL.revokeObjectURL(url)
message.success('提交审核成功!') message.success('提交审核成功!')
await getList() await getList()
} catch (error) {
console.error('合同下载失败', error)
}
} }
/** 查看审批 */ /** 查看审批 */