Skip to content

Commit 618d0fe

Browse files
committed
refactor: 移除不必要的 aspectRatioFixed 属性,简化打印配置逻辑
1 parent cbd46bd commit 618d0fe

6 files changed

Lines changed: 6 additions & 28 deletions

File tree

src/features/print/components/PrintPaper.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ export default function PrintPaper(props: PrintPaperProps) {
1212
<Box
1313
class="PrintPaper"
1414
sx={{
15-
width: paperConfig.contentAspectRatioFixed ? '100%' : '100vw',
16-
height: paperConfig.contentAspectRatioFixed ? undefined : '100vh',
17-
aspectRatio: paperConfig.contentAspectRatioFixed ? `${paperConfig.contentAspectRatio}` : undefined,
15+
width: '100%',
16+
aspectRatio: `${paperConfig.contentAspectRatio}`,
1817
}}
1918
>
2019
{props.children}

src/features/print/contexts/PrintPaperConfigContext.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { createContext, type JSX, splitProps, useContext } from 'solid-js';
22

33
export interface PrintPaperConfig {
4-
contentAspectRatioFixed: boolean;
54
contentAspectRatio: number;
65
}
76

87
const PrintPaperConfigContext = createContext<PrintPaperConfig>();
98

109
interface PrintPaperConfigProviderProps {
1110
children: JSX.Element;
12-
contentAspectRatioFixed: boolean;
1311
contentAspectRatio: number;
1412
}
1513
export function PrintPaperConfigProvider(props: PrintPaperConfigProviderProps) {
16-
const [value] = splitProps(props, ['contentAspectRatioFixed', 'contentAspectRatio']);
14+
const [value] = splitProps(props, ['contentAspectRatio']);
1715
return <PrintPaperConfigContext.Provider value={value}>{props.children}</PrintPaperConfigContext.Provider>;
1816
}
1917

src/pages/PrinterPage/actions/config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export interface ConfigActions {
1313
setMarginBottom: (value: number) => void;
1414
setOrientation: (value: 'landscape' | 'portrait') => void;
1515
setPaperSize: (size: ConfigStore['print']['size']) => void;
16-
toggleAspectRatio: () => void;
1716
};
1817
preview: {
1918
setColorMode: (mode: 'colorful' | 'gray') => void;
@@ -56,10 +55,6 @@ export function createConfigActions(setState: SetStoreFunction<ConfigStore>): Co
5655
setPaperSize: (size: ConfigStore['print']['size']) => {
5756
setState('print', 'size', size);
5857
},
59-
60-
toggleAspectRatio: () => {
61-
setState('print', 'aspectRatioFixed', (prev) => !prev);
62-
},
6358
},
6459

6560
preview: {

src/pages/PrinterPage/components/AdjustSheets.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ export default function AdjustSheets(props: AdjustSheetsProps) {
9999
configActions.preview.setColorMode(config.preview.colorMode === 'colorful' ? 'gray' : 'colorful');
100100
}
101101

102-
function handleAspectRatioFixedToggle() {
103-
configActions.print.toggleAspectRatio();
104-
}
105-
106102
function handlePageSizeChange(event: SelectChangeEvent<DataType.PageSize | 'custom'>, _child: JSX.Element) {
107103
if (event.target.value !== 'custom') {
108104
configActions.print.setPaperSize(event.target.value);
@@ -228,17 +224,9 @@ export default function AdjustSheets(props: AdjustSheetsProps) {
228224
</List>
229225
<Divider />
230226
{/* 打印配置 */}
231-
<List>
227+
{/* <List>
232228
<ListSubheader>打印</ListSubheader>
233-
234-
<ListSwitchItem
235-
checked={config.print.aspectRatioFixed}
236-
icon={<ArticleOutlinedIcon />}
237-
onClick={handleAspectRatioFixedToggle}
238-
summary="在打印时使用固定的比例,而非动态测量。FireFox 需要打开此项才能正确显示页面。"
239-
title="固定页面比例"
240-
/>
241-
</List>
229+
</List> */}
242230
<Divider />
243231
{/* 预览配置 */}
244232
<List>

src/pages/PrinterPage/stores/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createStore } from 'solid-js/store';
2-
import { maybeChrome } from '@/utils/platform';
2+
33
import type { PaperLayout, PreviewConfig, PrintConfig } from '../types/config';
44

55
export interface ConfigStore {
@@ -20,7 +20,6 @@ export function createConfigStore() {
2020
contentMarginBottom: 1,
2121
orientation: 'landscape',
2222
size: 'A4',
23-
aspectRatioFixed: !maybeChrome,
2423
},
2524
preview: {
2625
colorMode: 'gray',

src/pages/PrinterPage/types/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export interface PrintConfig {
1212
contentMarginBottom: number;
1313
orientation: 'landscape' | 'portrait';
1414
size: DataType.PageSize | [number, number];
15-
aspectRatioFixed: boolean;
1615
}
1716

1817
export interface PreviewConfig {

0 commit comments

Comments
 (0)