feat(web-admin): add Generate Word on contract print dialog
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b078245fbc
commit
9ac37d1196
1 file changed
+55
@@ -881,6 +881,9 @@
|
||||
<el-button class="btn-ghost" @click="handlePrintContract">
|
||||
<el-icon><Printer /></el-icon>打印
|
||||
</el-button>
|
||||
<el-button class="btn-ghost" :loading="wordGenerating" @click="handleGenerateWordFromDialog">
|
||||
<el-icon><Document /></el-icon>生成 Word
|
||||
</el-button>
|
||||
<el-button class="btn-main" type="primary" :loading="pdfGenerating" @click="handleGeneratePdfFromDialog">
|
||||
<el-icon><Download /></el-icon>生成 PDF
|
||||
</el-button>
|
||||
@@ -954,6 +957,12 @@ import { applyAliasDisplayMeta, formatBrandConstraintLabel, formatBrandForPrint
|
||||
import { fetchProductDetail } from '@/api/crm/product'
|
||||
import { parseTime } from '@/utils/format';
|
||||
import { canDeleteByCreator, filterDeletableByCreator, allRowsDeletableByCreator, CREATOR_DELETE_TIP } from '@/utils/creator-delete';
|
||||
import FileSaver from 'file-saver'
|
||||
import {
|
||||
buildContractDocxFileName,
|
||||
generateContractDocxBlob,
|
||||
prepareContractHtmlForDocx
|
||||
} from '@/utils/crm/contract-html-to-docx'
|
||||
import ApprovalDialog from './ApprovalDialog.vue';
|
||||
import ExecuteDialog from './ExecuteDialog.vue';
|
||||
import InvalidDialog from './InvalidDialog.vue';
|
||||
@@ -1038,6 +1047,7 @@ const isPreviewMode = ref(false);
|
||||
/** 打印弹窗内红章显隐(仅本次弹窗有效,打开时默认显示) */
|
||||
const showRedSeal = ref(true);
|
||||
const pdfGenerating = ref(false);
|
||||
const wordGenerating = ref(false);
|
||||
const currentContractId = ref<string | number>();
|
||||
|
||||
const formDialogVisible = ref(false);
|
||||
@@ -2948,6 +2958,51 @@ const handlePrintContract = () => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 从打印弹窗生成 Word(前端 HTML→DOCX) */
|
||||
const handleGenerateWordFromDialog = async () => {
|
||||
if (!detailContract.value?.id) {
|
||||
$modal.msgError('合同信息不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
wordGenerating.value = true;
|
||||
try {
|
||||
$modal.loading('正在生成 Word...');
|
||||
|
||||
let htmlContent = contractContent.value;
|
||||
const res = await getContractDetail(detailContract.value.id);
|
||||
if (res?.data) {
|
||||
htmlContent = replacePlaceholders(htmlContent, res.data);
|
||||
contractContent.value = htmlContent;
|
||||
}
|
||||
|
||||
const prepared = prepareContractHtmlForDocx({
|
||||
html: htmlContent,
|
||||
contractNo: detailContract.value.contractNo,
|
||||
origin: window.location.origin
|
||||
});
|
||||
|
||||
const blob = await generateContractDocxBlob(
|
||||
prepared,
|
||||
detailContract.value.contractName || detailContract.value.contractNo
|
||||
);
|
||||
const fileName = buildContractDocxFileName(
|
||||
detailContract.value.contractName,
|
||||
detailContract.value.contractNo
|
||||
);
|
||||
FileSaver.saveAs(blob, fileName);
|
||||
|
||||
$modal.closeLoading();
|
||||
$modal.msgSuccess('Word 生成成功');
|
||||
} catch (error) {
|
||||
console.error('生成 Word 失败:', error);
|
||||
$modal.closeLoading();
|
||||
$modal.msgError('生成 Word 失败,请重试');
|
||||
} finally {
|
||||
wordGenerating.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 从打印弹窗生成PDF(前端实现) */
|
||||
const handleGeneratePdfFromDialog = async () => {
|
||||
if (!detailContract.value?.id) {
|
||||
|
||||
Reference in new issue
Block a user