Skip to content

Commit ebbc3f9

Browse files
committed
feat(print): 优化纸张尺寸显示并添加辅助信息
- 修正纸张尺寸的宽度和高度顺序 - 在选择菜单中添加纸张尺寸的厘米数辅助信息 - 优化选择菜单项的样式,使纸张尺寸信息显示在右侧
1 parent 6c7e7a0 commit ebbc3f9

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/features/print/utils/paperSize.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import type { DataType } from 'csstype';
33
export function pageSizeNameToCm(pageSize: DataType.PageSize): [number, number] {
44
switch (pageSize) {
55
case 'A3':
6-
return [29.7, 42.0];
6+
return [42.0, 29.7];
77
case 'A4':
8-
return [21.0, 29.7];
8+
return [29.7, 21.0];
99
case 'A5':
10-
return [14.8, 21.0];
10+
return [21.0, 14.8];
1111
case 'B4':
12-
return [25.0, 35.3];
12+
return [35.3, 25.0];
1313
case 'B5':
14-
return [17.6, 25.0];
14+
return [25.0, 17.6];
1515
case 'letter':
16-
return [21.59, 27.94];
16+
return [27.94, 21.59];
1717
case 'legal':
18-
return [21.59, 35.56];
18+
return [35.56, 21.59];
1919
default:
2020
throw new Error(`Unknown page size: ${pageSize}`);
2121
}

src/pages/PrinterPage/components/AdjustSheets/index.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
// SwipeableDrawer,
2222
// type SwipeableDrawerProps,
2323
Toolbar,
24+
Typography,
2425
} from '@suid/material';
2526
import type { DrawerProps } from '@suid/material/Drawer';
2627
import type { SelectChangeEvent } from '@suid/material/Select';
@@ -30,7 +31,7 @@ import { type Accessor, createMemo, For, type JSX, Show } from 'solid-js';
3031
import ListSwitchItem from '@/components/list/ListSwitchItem';
3132
import ToolbarTitle from '@/components/toolbar/ToolbarTitle';
3233
import { useInsets } from '@/features/insets/contexts/InsetsContext';
33-
import { getAvailablePageSizes } from '@/features/print/utils/paperSize';
34+
import { getAvailablePageSizes, pageSizeNameToCm } from '@/features/print/utils/paperSize';
3435
import { type SyncStateOptions, syncState } from '@/hooks/syncState';
3536
import { usePreferredDarkMode } from '@/hooks/usePreferredDarkMode';
3637
import { maybeAndroid } from '@/utils/platform';
@@ -209,7 +210,26 @@ export default function AdjustSheets(props: AdjustSheetsProps) {
209210
value={typeof config.print.size === 'string' ? config.print.size : 'custom'}
210211
onChange={handlePageSizeChange}
211212
>
212-
<For each={getAvailablePageSizes()}>{(size) => <MenuItem value={size}>{size}</MenuItem>}</For>
213+
<For each={getAvailablePageSizes()}>
214+
{(size) => {
215+
const [widthCm, heightCm] = pageSizeNameToCm(size);
216+
return (
217+
<MenuItem value={size} sx={{ alignItems: 'baseline' }}>
218+
<span>{size}</span>
219+
<Typography
220+
variant="body2"
221+
color="textSecondary"
222+
component="span"
223+
sx={{
224+
marginLeft: 0.5,
225+
}}
226+
>
227+
{`(${widthCm}cm x ${heightCm}cm)`}
228+
</Typography>
229+
</MenuItem>
230+
);
231+
}}
232+
</For>
213233
</Select>
214234
<FormHelperText id="adjust-panel__size__helper">
215235
您可能需要在“打印”窗口中同时更改“纸张尺寸”才能正确打印。

0 commit comments

Comments
 (0)