@@ -771,6 +771,13 @@ peer = (public-key = ${targetTunnel.public_key || ''}, allowed-ips = ${serverAll
771771 const generatePeerQrcode = useCallback ( async ( peerIndex , tunnel = null ) => {
772772 try {
773773 const config = generateDetailPeerConfig ( peerIndex , tunnel ) ;
774+
775+ // 检查配置是否为有效的 WireGuard 配置格式
776+ if ( ! config . includes ( '[Interface]' ) || ! config . includes ( '[Peer]' ) ) {
777+ console . error ( '配置无效,缺少必要的配置内容:' , config ) ;
778+ return null ;
779+ }
780+
774781 // 后端已返回完整的 Data URL,直接使用
775782 const dataUrl = await invoke ( 'generate_qrcode' , { content : config } ) ;
776783 return dataUrl ;
@@ -1380,12 +1387,25 @@ peer = (public-key = ${targetTunnel.public_key || ''}, allowed-ips = ${serverAll
13801387 < div className = "form-row" >
13811388 < div className = "form-group" >
13821389 < label > 监听端口</ label >
1383- < input
1384- type = "number"
1385- value = { config . listenPort }
1386- onChange = { ( e ) => setConfig ( { ...config , listenPort : e . target . value } ) }
1387- placeholder = "留空自动分配"
1388- />
1390+ < div className = "input-with-button" >
1391+ < input
1392+ type = "number"
1393+ value = { config . listenPort }
1394+ onChange = { ( e ) => setConfig ( { ...config , listenPort : e . target . value } ) }
1395+ placeholder = "请输入监听端口"
1396+ />
1397+ < button
1398+ onClick = { ( ) => {
1399+ const randomPort = Math . floor ( Math . random ( ) * ( 50000 - 40000 + 1 ) ) + 40000 ;
1400+ setConfig ( { ...config , listenPort : randomPort . toString ( ) } ) ;
1401+ } }
1402+ className = "btn-inline"
1403+ type = "button"
1404+ title = "生成 40000-50000 范围内的随机端口"
1405+ >
1406+ 随机生成
1407+ </ button >
1408+ </ div >
13891409 </ div >
13901410 < div className = "form-group" >
13911411 < label > MTU</ label >
0 commit comments