diff --git a/src/components/TemplateLetter2025/Index.jsx b/src/components/TemplateLetter2025/Index.jsx index d7fdf2f..0a60d55 100644 --- a/src/components/TemplateLetter2025/Index.jsx +++ b/src/components/TemplateLetter2025/Index.jsx @@ -248,6 +248,87 @@ const createDoc = async ({title, subject, sectionsData}) => { // }, }); +const sectionSettings = { + properties: { + page: { + pageNumbers: { + start: 1, + formatType: NumberFormat.DECIMAL, + }, + margin: pageMargins, + }, + }, + headers: { + default: new docx.Header({ + children: [ + new docx.Paragraph({ + children: [image], + alignment: docx.AlignmentType.LEFT, // Align the image in the header + style: 'Header', + // todo: 边框位置被图文框占用 + // thematicBreak: true, + border: { + top: { style: 'none', size: 10, space: 0, color: 'bf192a' }, + bottom: { style: 'inset', size: 20, space: 0, color: 'bf192a' }, + left: { style: 'none', size: 10, space: 0, color: 'bf192a' }, + right: { style: 'none', size: 10, space: 0, color: 'bf192a' }, + }, + }), + createHeaderRight(), + // createHeaderText(), + ], + }), + }, + footers: { + default: new docx.Footer({ + children: [ + new Paragraph({ + alignment: AlignmentType.END, + style: 'Footer', + // thematicBreak: true, + border: { + top: { style: 'none', size: 10, space: 0, color: 'bf192a' }, + bottom: { style: 'inset', size: 20, space: 0, color: 'bf192a' }, + left: { style: 'none', size: 10, space: 0, color: 'bf192a' }, + right: { style: 'none', size: 10, space: 0, color: 'bf192a' }, + }, + children: [ + new TextRun({ + children: ['- ', PageNumber.CURRENT, ' -'], + size: 18, + }), + ], + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + style: 'Footer', + children: [ + new TextRun({ + text: '中国 桂林市七里店路70号创意产业园6号楼4层 桂林海纳国际旅行社有限公司 邮编541004', + // break: 1, + }), + new TextRun({ + text: 'China Highlights, Discovery Your Way (Since 1959)!', + break: 1, + font: 'Arial', + bold: true, + }), + ], + }), + // new Paragraph({ + // alignment: AlignmentType.RIGHT, + // children: [ + // new TextRun({ + // text: `${new Date().toLocaleString()}系统生成`, + // italics: true, + // size: 20, + // }), + // ], + // }), + ], + }), + }, + }; const doc = new docx.Document({ creator: 'China Highlights', subject: 'CH信笺2025', @@ -395,85 +476,7 @@ const createDoc = async ({title, subject, sectionsData}) => { }, sections: [ { - properties: { - page: { - pageNumbers: { - start: 1, - formatType: NumberFormat.DECIMAL, - }, - margin: pageMargins, - }, - }, - headers: { - default: new docx.Header({ - children: [ - new docx.Paragraph({ - children: [image], - alignment: docx.AlignmentType.LEFT, // Align the image in the header - style: 'Header', - // todo: 边框位置被图文框占用 - // thematicBreak: true, - border: { - top: { style: 'none', size: 10, space: 0, color: 'bf192a' }, - bottom: { style: 'inset', size: 20, space: 0, color: 'bf192a' }, - left: { style: 'none', size: 10, space: 0, color: 'bf192a' }, - right: { style: 'none', size: 10, space: 0, color: 'bf192a' }, - }, - }), - createHeaderRight(), - // createHeaderText(), - ], - }), - }, - footers: { - default: new docx.Footer({ - children: [ - new Paragraph({ - alignment: AlignmentType.END, - style: 'Footer', - // thematicBreak: true, - border: { - top: { style: 'none', size: 10, space: 0, color: 'bf192a' }, - bottom: { style: 'inset', size: 20, space: 0, color: 'bf192a' }, - left: { style: 'none', size: 10, space: 0, color: 'bf192a' }, - right: { style: 'none', size: 10, space: 0, color: 'bf192a' }, - }, - children: [ - new TextRun({ - children: ['- ', PageNumber.CURRENT, ' -'], - size: 18, - }), - ], - }), - new Paragraph({ - alignment: AlignmentType.CENTER, - style: 'Footer', - children: [ - new TextRun({ - text: '中国 桂林市七里店路70号创意产业园6号楼4层 桂林海纳国际旅行社有限公司 邮编541004', - // break: 1, - }), - new TextRun({ - text: 'China Highlights, Discovery Your Way (Since 1959)!', - break: 1, - font: 'Arial', - bold: true, - }), - ], - }), - // new Paragraph({ - // alignment: AlignmentType.RIGHT, - // children: [ - // new TextRun({ - // text: `${new Date().toLocaleString()}系统生成`, - // italics: true, - // size: 20, - // }), - // ], - // }), - ], - }), - }, + ...sectionSettings, children: [ createTitle(title), new docx.TableOfContents('toc', { @@ -481,6 +484,11 @@ const createDoc = async ({title, subject, sectionsData}) => { headingStyleRange: '1-5', useAppliedParagraphOutlineLevel: true, }), + ], + }, + { + ...sectionSettings, + children: [ createTitle(subject), ...sectionsData.reduce((arr, { tableTitle, tableColumns, tableData }) => {