fix: 保留合同表格调整后的列宽行高并修复导出水印,确保保存与导出布局一致。
This commit is contained in:
1 parent
027d1751a3
commit
94727cdca9
12 files changed
+591
-119
No files matched your search
@@ -913,11 +913,12 @@
|
||||
<div class="generate-print-dialog-header">
|
||||
<span class="generate-print-dialog-title">{{ isPreviewMode ? '预览合同' : '编辑合同' }}</span>
|
||||
<p v-if="!isPreviewMode" class="generate-print-dialog-edit-hint">
|
||||
编辑模式:鼠标移到表头格子的右边界可调列宽,移到每行最左边格子的下边界可调行高。工具栏可合并拆分、插删行列、对齐与换行。调整后请点「保存模板」。
|
||||
编辑模式:鼠标移到表头格子的右边界可调列宽,表格总宽不变,也不超出页面宽度;移到每行最左边格子的下边界可调行高。工具栏可合并拆分、插删行列、对齐与换行。调整后请点「保存模板」。
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
<TinyMceEditor
|
||||
ref="contractEditorRef"
|
||||
v-model="contractContent"
|
||||
:height="600"
|
||||
:disabled="isPreviewMode"
|
||||
@@ -1056,7 +1057,7 @@ import TinyMceEditor from '@/components/TinyMceEditor/index.vue';
|
||||
import html2canvas from 'html2canvas';
|
||||
import jsPDF from 'jspdf';
|
||||
import { fitRichTextTablesToMaxWidth } from '@/utils/tinymce-table-excel-resize';
|
||||
import { normalizeContractProductTableWidths } from '@/utils/crm/contract-product-table-widths';
|
||||
import { applySavedProductTableLayout, stampSavedProductTableLayout } from '@/utils/crm/contract-table-layout';
|
||||
import { appendContractPageWatermarks, contractWatermarkPrintCss } from '@/utils/crm/contract-watermark';
|
||||
import {
|
||||
downloadCrmAttachment,
|
||||
@@ -1119,6 +1120,8 @@ const generateContractDialog = reactive({
|
||||
visible: false
|
||||
});
|
||||
const contractContent = ref('');
|
||||
const contractEditorRef = ref<{ getHtml: () => string } | null>(null);
|
||||
const readEditorHtml = () => contractEditorRef.value?.getHtml?.() || contractContent.value;
|
||||
const isPreviewMode = ref(false);
|
||||
/** 打印弹窗内红章显隐(仅本次弹窗有效,打开时默认显示) */
|
||||
const showRedSeal = ref(true);
|
||||
@@ -2247,7 +2250,7 @@ const replacePlaceholders = (htmlContent: string, contractData: ContractVO | und
|
||||
result = result.replace(/\{\{partyASeal\}\}/gi, getSealHtml(contractData.partyA));
|
||||
result = result.replace(/\{\{partyBSeal\}\}/gi, getSealHtml(contractData.partyB));
|
||||
|
||||
return normalizeContractProductTableWidths(result);
|
||||
return applySavedProductTableLayout(result);
|
||||
};
|
||||
|
||||
/** 替换模板第五条内容 */
|
||||
@@ -2652,8 +2655,8 @@ const handleSaveTemplate = async () => {
|
||||
|
||||
$modal.loading('正在保存模板...');
|
||||
|
||||
// 获取当前富文本编辑器中的内容(用户修改后的内容)
|
||||
const currentContent = contractContent.value;
|
||||
// 读取编辑器正在显示的 HTML,避免导出仍用拖拽前的列宽
|
||||
const currentContent = readEditorHtml();
|
||||
console.log('当前编辑器内容长度:', currentContent.length);
|
||||
|
||||
// 重新获取最新合同数据
|
||||
@@ -2738,6 +2741,8 @@ const handleSaveTemplate = async () => {
|
||||
// 这些字段每次打开时都会用数据库最新数据替换
|
||||
finalTemplate = replaceDynamicFields(finalTemplate, latestContractData);
|
||||
|
||||
finalTemplate = stampSavedProductTableLayout(currentContent, finalTemplate);
|
||||
|
||||
console.log('最终保存的模板长度:', finalTemplate.length);
|
||||
console.log('最终模板包含 {{signDate}}:', finalTemplate.includes('{{signDate}}'));
|
||||
console.log('最终模板包含 {{contractNo}}:', finalTemplate.includes('{{contractNo}}'));
|
||||
@@ -2953,6 +2958,7 @@ const togglePreviewMode = () => {
|
||||
|
||||
/** 打印合同 */
|
||||
const handlePrintContract = () => {
|
||||
contractContent.value = readEditorHtml();
|
||||
// 从合同编号中提取供方编码
|
||||
// 合同编号格式:{供方编码}/X-JT + yyyyMMdd + 3位流水号
|
||||
// 例如:SX/X-JT20250926002
|
||||
@@ -3042,7 +3048,7 @@ const handleGenerateWordFromDialog = async () => {
|
||||
try {
|
||||
$modal.loading('正在生成 Word...');
|
||||
|
||||
let htmlContent = contractContent.value;
|
||||
let htmlContent = readEditorHtml();
|
||||
const res = await getContractDetail(detailContract.value.id);
|
||||
if (res?.data) {
|
||||
htmlContent = replacePlaceholders(htmlContent, res.data);
|
||||
@@ -3101,7 +3107,7 @@ const handleGeneratePdfFromDialog = async () => {
|
||||
const isSXSupplier = supplierCode === 'SX';
|
||||
|
||||
// 获取合同内容并用最新数据刷新合计区(打印弹窗与 PDF 同源)
|
||||
let htmlContent = contractContent.value;
|
||||
let htmlContent = readEditorHtml();
|
||||
const res = await getContractDetail(detailContract.value.id);
|
||||
if (res?.data) {
|
||||
htmlContent = replacePlaceholders(htmlContent, res.data);
|
||||
@@ -3149,7 +3155,7 @@ const handleGeneratePdfFromDialog = async () => {
|
||||
contentDiv.innerHTML = contentHtml;
|
||||
const fitStyle = document.createElement('style');
|
||||
fitStyle.textContent = `
|
||||
table { max-width: 100% !important; width: 100% !important; table-layout: fixed !important; box-sizing: border-box !important; }
|
||||
table { max-width: 100% !important; table-layout: fixed !important; box-sizing: border-box !important; }
|
||||
table td, table th { box-sizing: border-box !important; min-width: 0 !important; word-break: break-word; overflow-wrap: break-word; }
|
||||
`;
|
||||
contentDiv.prepend(fitStyle);
|
||||
@@ -3178,6 +3184,7 @@ const handleGeneratePdfFromDialog = async () => {
|
||||
|
||||
if (isSXSupplier) {
|
||||
appendContractPageWatermarks(watermarkDiv, tempDiv.clientWidth || 794);
|
||||
await waitForImagesLoaded(watermarkDiv);
|
||||
}
|
||||
|
||||
// 如果不是SX供方编码,再次检查并隐藏可能遗漏的logo
|
||||
|
||||
@@ -1156,11 +1156,11 @@
|
||||
<div class="generate-print-dialog-header">
|
||||
<span class="generate-print-dialog-title">{{ isPreviewMode ? '预览合同' : '编辑合同' }}</span>
|
||||
<p v-if="!isPreviewMode" class="generate-print-dialog-edit-hint">
|
||||
编辑模式:鼠标移到表头格子的右边界可调列宽,移到每行最左边格子的下边界可调行高。工具栏可合并拆分、插删行列、对齐与换行。调整后请点「保存模板」。
|
||||
编辑模式:鼠标移到表头格子的右边界可调列宽,表格总宽不变,也不超出页面宽度;移到每行最左边格子的下边界可调行高。工具栏可合并拆分、插删行列、对齐与换行。调整后请点「保存模板」。
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
<TinyMceEditor v-model="contractContent" :height="600" :disabled="isPreviewMode" :toolbar="!isPreviewMode" :contractNo="contract?.contractNo" />
|
||||
<TinyMceEditor ref="contractEditorRef" v-model="contractContent" :height="600" :disabled="isPreviewMode" :toolbar="!isPreviewMode" :contractNo="contract?.contractNo" />
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="generateContractDialog.visible = false">关 闭</el-button>
|
||||
@@ -1242,7 +1242,7 @@ import { canDeleteByCreator } from '@/utils/creator-delete';
|
||||
import html2canvas from 'html2canvas';
|
||||
import { jsPDF } from 'jspdf';
|
||||
import { fitRichTextTablesToMaxWidth } from '@/utils/tinymce-table-excel-resize';
|
||||
import { normalizeContractProductTableWidths } from '@/utils/crm/contract-product-table-widths';
|
||||
import { applySavedProductTableLayout, stampSavedProductTableLayout } from '@/utils/crm/contract-table-layout';
|
||||
import { appendContractPageWatermarks, contractWatermarkPrintCss } from '@/utils/crm/contract-watermark';
|
||||
|
||||
const router = useRouter();
|
||||
@@ -1293,6 +1293,8 @@ const generateContractDialog = reactive({
|
||||
visible: false
|
||||
});
|
||||
const contractContent = ref('');
|
||||
const contractEditorRef = ref<{ getHtml: () => string } | null>(null);
|
||||
const readEditorHtml = () => contractEditorRef.value?.getHtml?.() || contractContent.value;
|
||||
const isPreviewMode = ref(false);
|
||||
/** 打印弹窗内红章显隐(仅本次弹窗有效,打开时默认显示) */
|
||||
const showRedSeal = ref(true);
|
||||
@@ -1893,7 +1895,7 @@ const replacePlaceholders = (htmlContent: string, contractData: ContractVO | und
|
||||
}
|
||||
}
|
||||
|
||||
return normalizeContractProductTableWidths(result);
|
||||
return applySavedProductTableLayout(result);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -2314,8 +2316,8 @@ const handleSaveTemplate = async () => {
|
||||
try {
|
||||
$modal.loading('正在保存模板...');
|
||||
|
||||
// 获取当前富文本编辑器中的内容(用户修改后的内容)
|
||||
const currentContent = contractContent.value;
|
||||
// 读取编辑器正在显示的 HTML,避免保存仍用拖拽前的列宽
|
||||
const currentContent = readEditorHtml();
|
||||
|
||||
// 重新获取最新合同数据(确保使用最新数据)
|
||||
const contractRes = await getContract(contract.value.id);
|
||||
@@ -2355,6 +2357,7 @@ const handleSaveTemplate = async () => {
|
||||
|
||||
// 2. 替换其他动态字段为占位符
|
||||
finalTemplate = replaceDynamicFields(finalTemplate, latestContractData);
|
||||
finalTemplate = stampSavedProductTableLayout(currentContent, finalTemplate);
|
||||
|
||||
// 保存模板(包含第五条分结算方式草稿)
|
||||
await saveTemplate(contract.value.id, finalTemplate, settlementClauseDrafts);
|
||||
@@ -2707,6 +2710,7 @@ const calculateExecutedDays = (startDate: string): number => {
|
||||
|
||||
/** 打印合同 */
|
||||
const handlePrintContract = () => {
|
||||
contractContent.value = readEditorHtml();
|
||||
// 从合同编号中提取供方编码
|
||||
// 合同编号格式:{供方编码}/X-JT + yyyyMMdd + 3位流水号
|
||||
// 例如:SX/X-JT20250926002
|
||||
@@ -2787,6 +2791,7 @@ const handlePrintContract = () => {
|
||||
|
||||
/** 下载HTML文件 */
|
||||
const handleDownloadHtml = () => {
|
||||
contractContent.value = readEditorHtml();
|
||||
const blob = new Blob(
|
||||
[
|
||||
`
|
||||
@@ -2908,7 +2913,7 @@ const handleGenerateWordFile = async () => {
|
||||
try {
|
||||
$modal.loading('正在生成 Word...');
|
||||
|
||||
let htmlContent = contractContent.value;
|
||||
let htmlContent = readEditorHtml();
|
||||
const res = await getContract(contract.value.id);
|
||||
if (res?.data) {
|
||||
htmlContent = replacePlaceholders(htmlContent, res.data);
|
||||
@@ -2951,7 +2956,7 @@ const handleGeneratePdfFile = async () => {
|
||||
if (contract.value?.id) {
|
||||
const res = await getContract(contract.value.id);
|
||||
if (res?.data) {
|
||||
contractContent.value = replacePlaceholders(contractContent.value, res.data);
|
||||
contractContent.value = replacePlaceholders(readEditorHtml(), res.data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2978,7 +2983,7 @@ const handleGeneratePdfFile = async () => {
|
||||
contentDiv.innerHTML = contractContent.value;
|
||||
const fitStyle = document.createElement('style');
|
||||
fitStyle.textContent = `
|
||||
table { max-width: 100% !important; width: 100% !important; table-layout: fixed !important; box-sizing: border-box !important; }
|
||||
table { max-width: 100% !important; table-layout: fixed !important; box-sizing: border-box !important; }
|
||||
table td, table th { box-sizing: border-box !important; min-width: 0 !important; word-break: break-word; overflow-wrap: break-word; }
|
||||
`;
|
||||
contentDiv.prepend(fitStyle);
|
||||
@@ -3005,6 +3010,20 @@ const handleGeneratePdfFile = async () => {
|
||||
const pdfContentMaxWidth = Math.max(1, tempDiv.clientWidth - 40);
|
||||
fitRichTextTablesToMaxWidth(contentDiv, pdfContentMaxWidth);
|
||||
appendContractPageWatermarks(watermarkDiv, tempDiv.clientWidth || 794);
|
||||
const watermarkImages = watermarkDiv.querySelectorAll('img[data-contract-watermark]');
|
||||
await Promise.all(
|
||||
Array.from(watermarkImages).map(
|
||||
(img) =>
|
||||
new Promise((resolve) => {
|
||||
if (img.complete) {
|
||||
resolve(true);
|
||||
} else {
|
||||
img.onload = () => resolve(true);
|
||||
img.onerror = () => resolve(true);
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// 使用html2canvas将HTML转换为canvas
|
||||
const canvas = await html2canvas(tempDiv, {
|
||||
|
||||
@@ -628,7 +628,7 @@
|
||||
<div class="generate-print-dialog-header">
|
||||
<span class="generate-print-dialog-title">{{ isPreviewMode ? '预览报价单' : '编辑报价单' }}</span>
|
||||
<p v-if="!isPreviewMode" class="generate-print-dialog-edit-hint">
|
||||
编辑模式:鼠标移到表头格子的右边界可调列宽,移到每行最左边格子的下边界可调行高。工具栏可合并拆分、插删行列、对齐与换行。调整后请点「保存模板」。
|
||||
编辑模式:鼠标移到表头格子的右边界可调列宽,表格总宽不变,也不超出页面宽度;移到每行最左边格子的下边界可调行高。工具栏可合并拆分、插删行列、对齐与换行。调整后请点「保存模板」。
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in new issue
Block a user