@@ -77,6 +77,7 @@ export const PuzzleEditor: React.FC<PuzzleEditorProps> = ({ onBackToMenu, onBack
7777 const [ importPreviewImage , setImportPreviewImage ] = useState < string | null > ( null ) ;
7878 const [ importPreviewShape , setImportPreviewShape ] = useState < string > ( '' ) ;
7979 const [ importPreviewGrid , setImportPreviewGrid ] = useState < string > ( '' ) ;
80+ const [ importPreviewAspectRatio , setImportPreviewAspectRatio ] = useState < string > ( '' ) ;
8081
8182 // 监听分享代码输入,实时解析图片
8283 const handleImportCodeChange = ( val : string ) => {
@@ -106,10 +107,17 @@ export const PuzzleEditor: React.FC<PuzzleEditorProps> = ({ onBackToMenu, onBack
106107 } else {
107108 setImportPreviewGrid ( '' ) ;
108109 }
110+ // 裁剪比例
111+ if ( data . aspectRatio ) {
112+ setImportPreviewAspectRatio ( data . aspectRatio ) ;
113+ } else {
114+ setImportPreviewAspectRatio ( '' ) ;
115+ }
109116 } catch {
110117 setImportPreviewImage ( null ) ;
111118 setImportPreviewShape ( '' ) ;
112119 setImportPreviewGrid ( '' ) ;
120+ setImportPreviewAspectRatio ( '' ) ;
113121 }
114122 } ;
115123
@@ -245,15 +253,22 @@ export const PuzzleEditor: React.FC<PuzzleEditorProps> = ({ onBackToMenu, onBack
245253 }
246254 // 生成唯一id
247255 const id = Date . now ( ) . toString ( ) ;
256+ // 确保保存完整的配置信息,包括裁剪比例
248257 const newPuzzle = {
249258 id,
250259 name : customPuzzleConfig . name ,
251- data : customPuzzleConfig ,
260+ data : {
261+ ...customPuzzleConfig ,
262+ // 明确包含裁剪比例信息
263+ aspectRatio : customPuzzleConfig . aspectRatio || '1:1' ,
264+ // 包含裁剪后的图片数据
265+ croppedImageData : customPuzzleConfig . croppedImageData
266+ } ,
252267 date : new Date ( ) . toLocaleString ( ) ,
253268 } ;
254269 puzzles . push ( newPuzzle ) ;
255270 localStorage . setItem ( 'savedPuzzles' , JSON . stringify ( puzzles ) ) ;
256- setShowSavedPage ( { highlightId : id } ) ;
271+ setShowSavedPage ( { highlightId : id } ) ;
257272 } , [ customPuzzleConfig ] ) ;
258273
259274 // 分享弹窗相关状态
@@ -352,6 +367,7 @@ export const PuzzleEditor: React.FC<PuzzleEditorProps> = ({ onBackToMenu, onBack
352367 gridSize,
353368 pieceShape,
354369 name : customPuzzleConfig . name || '自定义拼图' ,
370+ aspectRatio : customPuzzleConfig . aspectRatio ,
355371 } ) ;
356372 if ( typeof onStartGame === 'function' ) {
357373 onStartGame ( puzzleConfig ) ;
@@ -475,11 +491,13 @@ export const PuzzleEditor: React.FC<PuzzleEditorProps> = ({ onBackToMenu, onBack
475491 { importPreviewImage && (
476492 < img src = { importPreviewImage } alt = "预览" style = { { maxWidth : 180 , maxHeight : 120 , borderRadius : 4 , boxShadow : '0 1px 6px #0001' , marginBottom : ( importPreviewShape || importPreviewGrid ) ? 6 : 0 } } />
477493 ) }
478- { ( importPreviewShape || importPreviewGrid ) && (
494+ { ( importPreviewShape || importPreviewGrid || importPreviewAspectRatio ) && (
479495 < div style = { { fontSize : 13 , color : '#333' , marginBottom : 2 } } >
480496 { importPreviewShape && < span > 形状:{ importPreviewShape } </ span > }
481497 { importPreviewShape && importPreviewGrid && < span style = { { margin : '0 6px' } } > |</ span > }
482498 { importPreviewGrid && < span > 块数:{ importPreviewGrid } </ span > }
499+ { ( importPreviewShape || importPreviewGrid ) && importPreviewAspectRatio && < span style = { { margin : '0 6px' } } > |</ span > }
500+ { importPreviewAspectRatio && < span > 比例:{ importPreviewAspectRatio } </ span > }
483501 </ div >
484502 ) }
485503 </ div >
@@ -515,8 +533,8 @@ export const PuzzleEditor: React.FC<PuzzleEditorProps> = ({ onBackToMenu, onBack
515533 < button onClick = { ( ) => { setImportDialogOpen ( false ) ; setImportError ( '' ) ; setImportCode ( '' ) ; setImportPreviewImage ( null ) ; } } style = { { padding : '6px 16px' , fontSize : 14 , cursor : 'pointer' } } > 取消</ button >
516534 </ div >
517535 < div style = { { fontSize : 12 , color : '#888' , marginTop : 8 } } >
518- 分享代码可由好友生成,包含图片、形状、难度、块数等信息 。
519- </ div >
536+ 分享代码可由好友生成,包含图片、形状、难度、块数、裁剪比例等信息 。
537+ </ div >
520538 </ div >
521539 </ div >
522540 ) }
@@ -585,7 +603,8 @@ export const PuzzleEditor: React.FC<PuzzleEditorProps> = ({ onBackToMenu, onBack
585603 selectedShape = { tempPieceShape }
586604 onDifficultyChange = { handleTempDifficultyChange }
587605 onShapeChange = { handleTempPieceShapeChange }
588- // 新增:自定义行列同步(已移除无用 prop)
606+ // 新增:自定义行列同步
607+ onCustomGridChange = { handleTempCustomGrid }
589608 // 新增:重新剪裁功能
590609 onRecrop = { ( ) => setCurrentStep ( 'crop' ) }
591610 hasUploadedImage = { ! ! uploadedImage }
@@ -755,14 +774,25 @@ export const PuzzleEditor: React.FC<PuzzleEditorProps> = ({ onBackToMenu, onBack
755774 showPuzzleGrid = { true }
756775 gridSize = {
757776 currentStep === 'settings'
758- ? ( tempDifficulty === 'easy' ? '3x3' : tempDifficulty === 'medium' ? '4x4' : tempDifficulty === 'hard' ? '5x5' : '6x6' )
759- : ( customPuzzleConfig . difficulty === 'easy' ? '3x3' : customPuzzleConfig . difficulty === 'medium' ? '4x4' : customPuzzleConfig . difficulty === 'hard' ? '5x5' : '6x6' )
777+ ? ( tempDifficulty === 'easy' ? '3x3'
778+ : tempDifficulty === 'medium' ? '4x4'
779+ : tempDifficulty === 'hard' ? '5x5'
780+ : tempDifficulty === 'expert' ? '6x6'
781+ : tempDifficulty === 'custom' ? `${ tempCustomRows } x${ tempCustomCols } `
782+ : '4x4' )
783+ : ( customPuzzleConfig . difficulty === 'easy' ? '3x3'
784+ : customPuzzleConfig . difficulty === 'medium' ? '4x4'
785+ : customPuzzleConfig . difficulty === 'hard' ? '5x5'
786+ : customPuzzleConfig . difficulty === 'expert' ? '6x6'
787+ : customPuzzleConfig . difficulty === 'custom' ? `${ customPuzzleConfig . customRows || 3 } x${ customPuzzleConfig . customCols || 3 } `
788+ : '4x4' )
760789 }
761790 pieceShape = {
762791 currentStep === 'settings'
763792 ? tempPieceShape
764793 : customPuzzleConfig . pieceShape
765794 }
795+ aspectRatio = { customPuzzleConfig . aspectRatio }
766796 />
767797 { /* 分享代码弹窗 */ }
768798 { shareDialogOpen && (
0 commit comments