-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from meetqy/31-支持打印-整个页面打印有点浪费纸张-能打印古诗译文更多-就足够…
…用了正好1-2张a4纸 31 支持打印 整个页面打印有点浪费纸张 能打印古诗译文更多 就足够用了正好1 2张a4纸
- Loading branch information
Showing
12 changed files
with
140 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Root from "../root"; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<Root lang="zh-Hans" languageComponent={false}> | ||
{children} | ||
</Root> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
"use client"; | ||
|
||
import { useRef } from "react"; | ||
import { useReactToPrint } from "react-to-print"; | ||
|
||
import { Button } from "~/components/ui/button"; | ||
import { type Locale } from "~/dictionaries"; | ||
import { api } from "~/trpc/react"; | ||
import { cn } from "~/utils"; | ||
|
||
const Row = ({ | ||
text, | ||
right, | ||
className, | ||
}: { | ||
text: string; | ||
right?: boolean; | ||
className?: string; | ||
}) => { | ||
const num = 11; | ||
const left = Math.floor((num - text.length) / 2) + text.length; | ||
|
||
let data = text.padStart(left).padEnd(num).split(""); | ||
if (right) { | ||
data = text.padStart(num).split(""); | ||
} | ||
|
||
return ( | ||
<div className="grid w-full grid-cols-11 border-y"> | ||
{data.map((item, index) => ( | ||
<div | ||
key={index} | ||
className={cn( | ||
"flex aspect-square items-center justify-center border-r", | ||
index === 0 && "border-l", | ||
className, | ||
)} | ||
> | ||
{item} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default function PrintPage({ | ||
searchParams, | ||
}: { | ||
searchParams: { id: string; lang: Locale }; | ||
}) { | ||
const { data: poem } = api.poem.findById.useQuery({ | ||
id: Number(searchParams.id), | ||
lang: searchParams.lang, | ||
}); | ||
|
||
const componentRef = useRef<HTMLDivElement>(null); | ||
const handlePrint = useReactToPrint({ | ||
content: () => componentRef.current, | ||
}); | ||
|
||
if (!poem) return null; | ||
|
||
const title = poem.title; | ||
const author = `${poem.author.dynasty}·${poem.author.name}`; | ||
|
||
const content = poem.content | ||
.replaceAll("\n", "") | ||
.match(/[^。|!|?|,|;]+[。|!|?|,|;]+/g); | ||
|
||
if (!content) return null; | ||
|
||
let arr = [title, author, ...content]; | ||
arr = [...arr, ...(new Array(12).fill("") as string[])].slice(0, 12); | ||
|
||
return ( | ||
<div className="flex"> | ||
<aside className="fixed top-0 flex h-full w-72 flex-col space-y-4 bg-muted p-4"> | ||
<Button onClick={handlePrint}>打印</Button> | ||
</aside> | ||
<aside className="w-72"></aside> | ||
<div className="relative m-auto min-h-[1754px] w-[1240px] origin-top-left scale-75 border border-t-0"> | ||
<div | ||
className="w-full space-y-4 p-12 font-cursive text-5xl" | ||
ref={componentRef} | ||
> | ||
{arr.map((item, index) => ( | ||
<Row | ||
key={index} | ||
text={item} | ||
right={index === 1} | ||
className={cn(index === 1 && "text-neutral-500")} | ||
/> | ||
))} | ||
|
||
<p className="absolute bottom-0 left-0 flex w-full items-center justify-end p-4 text-2xl text-neutral-400"> | ||
aspoem.com | 现代化诗词学习网站 | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters