更新安全配置项目
This commit is contained in:
+56
-109
@@ -1,34 +1,35 @@
|
||||
"use client";
|
||||
|
||||
import {useState, useCallback, useEffect} from "react";
|
||||
import {useCallback, useEffect, useState} from "react";
|
||||
import {
|
||||
Upload,
|
||||
Sun,
|
||||
AlertCircle,
|
||||
Apple,
|
||||
UtensilsCrossed,
|
||||
CheckCircle2,
|
||||
Cookie,
|
||||
Download,
|
||||
Heart,
|
||||
Languages,
|
||||
CheckCircle2,
|
||||
Loader2,
|
||||
Settings,
|
||||
Sun,
|
||||
Upload,
|
||||
UtensilsCrossed,
|
||||
X,
|
||||
AlertCircle,
|
||||
Download, Settings,
|
||||
} from "lucide-react";
|
||||
import Link from 'next/link'
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {
|
||||
AlignmentType,
|
||||
Document,
|
||||
Packer,
|
||||
Table,
|
||||
TableRow,
|
||||
TableCell,
|
||||
TextRun,
|
||||
Paragraph,
|
||||
AlignmentType,
|
||||
WidthType,
|
||||
PageOrientation,
|
||||
TableLayoutType
|
||||
Paragraph,
|
||||
Table,
|
||||
TableCell,
|
||||
TableLayoutType,
|
||||
TableRow,
|
||||
TextRun,
|
||||
WidthType
|
||||
} from "docx";
|
||||
|
||||
// 餐食类型
|
||||
@@ -228,7 +229,7 @@ export default function RecipeTranslationPage() {
|
||||
orientation: "landscape",
|
||||
secondPageHeader: false,
|
||||
};
|
||||
const { untranslatedColor, orientation, secondPageHeader } = exportConfig;
|
||||
const {untranslatedColor, orientation, secondPageHeader} = exportConfig;
|
||||
|
||||
// 2. 收集所有需要翻译的内容(星期、餐食类型、菜品)
|
||||
const allNames: string[] = [];
|
||||
@@ -343,7 +344,7 @@ export default function RecipeTranslationPage() {
|
||||
const isLandscape = orientation === "landscape";
|
||||
const pageWidth = isLandscape ? 11906 : 16838;
|
||||
const pageHeight = isLandscape ? 16838 : 11906;
|
||||
|
||||
|
||||
// 构建表头行
|
||||
const buildHeaderRow = (): TableRow => {
|
||||
const headerCells: TableCell[] = [];
|
||||
@@ -374,102 +375,48 @@ export default function RecipeTranslationPage() {
|
||||
})
|
||||
);
|
||||
}
|
||||
return new TableRow({children: headerCells, tableHeader: true});
|
||||
return new TableRow({ children: headerCells, tableHeader: false });
|
||||
};
|
||||
|
||||
// 估算每页能放多少天(横向 A4 约 27cm 高度,减去标题和边距约 25cm,每行约 1cm)
|
||||
const daysPerPage = 5;
|
||||
|
||||
|
||||
// 构建 sections
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const sections: any[] = [];
|
||||
|
||||
if (secondPageHeader && dayRows.length > daysPerPage) {
|
||||
// 分页模式:每页有表头
|
||||
const pageCount = Math.ceil(dayRows.length / daysPerPage);
|
||||
|
||||
for (let page = 0; page < pageCount; page++) {
|
||||
const startIdx = page * daysPerPage;
|
||||
const endIdx = Math.min(startIdx + daysPerPage, dayRows.length);
|
||||
const pageRows = dayRows.slice(startIdx, endIdx);
|
||||
|
||||
sections.push({
|
||||
properties: {
|
||||
page: {
|
||||
size: {
|
||||
orientation: isLandscape ? PageOrientation.LANDSCAPE : PageOrientation.PORTRAIT,
|
||||
width: pageWidth,
|
||||
height: pageHeight,
|
||||
},
|
||||
margin: {
|
||||
top: 700,
|
||||
bottom: 700,
|
||||
left: 900,
|
||||
right: 900,
|
||||
},
|
||||
},
|
||||
|
||||
sections.push({
|
||||
properties: {
|
||||
page: {
|
||||
size: {
|
||||
orientation: isLandscape ? PageOrientation.LANDSCAPE : PageOrientation.PORTRAIT,
|
||||
width: pageWidth,
|
||||
height: pageHeight,
|
||||
},
|
||||
children: [
|
||||
...(page === 0 ? [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: t(data.title?.zh || "食谱") || data.title?.zh || "食谱",
|
||||
bold: true,
|
||||
size: 32,
|
||||
}),
|
||||
],
|
||||
alignment: AlignmentType.CENTER,
|
||||
}),
|
||||
new Paragraph({children: []}),
|
||||
] : []),
|
||||
new Table({
|
||||
rows: [buildHeaderRow(), ...pageRows],
|
||||
width: {size: 100, type: WidthType.PERCENTAGE},
|
||||
layout: TableLayoutType.FIXED,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 普通模式:单表格无分页表头
|
||||
sections.push({
|
||||
properties: {
|
||||
page: {
|
||||
size: {
|
||||
orientation: isLandscape ? PageOrientation.LANDSCAPE : PageOrientation.PORTRAIT,
|
||||
width: pageWidth,
|
||||
height: pageHeight,
|
||||
},
|
||||
margin: {
|
||||
top: 700,
|
||||
bottom: 700,
|
||||
left: 900,
|
||||
right: 900,
|
||||
},
|
||||
margin: {
|
||||
top: 700,
|
||||
bottom: 700,
|
||||
left: 900,
|
||||
right: 900,
|
||||
},
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: t(data.title?.zh || "食谱") || data.title?.zh || "食谱",
|
||||
bold: true,
|
||||
size: 32,
|
||||
}),
|
||||
],
|
||||
alignment: AlignmentType.CENTER,
|
||||
}),
|
||||
new Paragraph({children: []}),
|
||||
new Table({
|
||||
rows: [buildHeaderRow(), ...dayRows],
|
||||
width: {size: 100, type: WidthType.PERCENTAGE},
|
||||
layout: TableLayoutType.FIXED,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: `${fileName || data.title?.zh || "食谱翻译"}`,
|
||||
bold: true,
|
||||
size: 32,
|
||||
}),
|
||||
],
|
||||
alignment: AlignmentType.CENTER,
|
||||
}),
|
||||
new Paragraph({children: []}),
|
||||
new Table({
|
||||
rows: [buildHeaderRow(), ...dayRows],
|
||||
width: {size: 100, type: WidthType.PERCENTAGE},
|
||||
layout: TableLayoutType.FIXED
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const doc = new Document({
|
||||
sections,
|
||||
});
|
||||
@@ -755,7 +702,7 @@ export default function RecipeTranslationPage() {
|
||||
key={dish.id}
|
||||
className="flex flex-col gap-0.5 text-sm"
|
||||
>
|
||||
<span style={{ color: dish.name.en ? undefined : exportConfig.untranslatedColor }}>
|
||||
<span style={{color: dish.name.en ? undefined : exportConfig.untranslatedColor}}>
|
||||
{dish.name.zh}
|
||||
</span>
|
||||
{dish.name.en && (
|
||||
@@ -788,7 +735,7 @@ export default function RecipeTranslationPage() {
|
||||
key={dish.id}
|
||||
className="flex flex-col gap-0.5"
|
||||
>
|
||||
<span style={{ color: dish.name.en ? undefined : exportConfig.untranslatedColor }}>
|
||||
<span style={{color: dish.name.en ? undefined : exportConfig.untranslatedColor}}>
|
||||
{dish.name.zh}
|
||||
</span>
|
||||
{dish.name.en && (
|
||||
|
||||
Reference in New Issue
Block a user