@@ -1485,6 +1485,24 @@ const ParamOverrideEditorModal = ({ visible, value, onSave, onCancel }) => {
14851485 ) ;
14861486 } ;
14871487
1488+ const formatSelectedOperationValueAsJson = useCallback ( ( ) => {
1489+ if ( ! selectedOperation ) return ;
1490+ const raw = String ( selectedOperation . value_text || '' ) . trim ( ) ;
1491+ if ( ! raw ) return ;
1492+ if ( ! verifyJSON ( raw ) ) {
1493+ showError ( t ( '当前值不是合法 JSON,无法格式化' ) ) ;
1494+ return ;
1495+ }
1496+ try {
1497+ updateOperation ( selectedOperation . id , {
1498+ value_text : JSON . stringify ( JSON . parse ( raw ) , null , 2 ) ,
1499+ } ) ;
1500+ showSuccess ( t ( 'JSON 已格式化' ) ) ;
1501+ } catch ( error ) {
1502+ showError ( t ( '当前值不是合法 JSON,无法格式化' ) ) ;
1503+ }
1504+ } , [ selectedOperation , t , updateOperation ] ) ;
1505+
14881506 const updateReturnErrorDraft = ( operationId , draftPatch = { } ) => {
14891507 const current = operations . find ( ( item ) => item . id === operationId ) ;
14901508 if ( ! current ) return ;
@@ -2608,9 +2626,20 @@ const ParamOverrideEditorModal = ({ visible, value, onSave, onCancel }) => {
26082626 </ div >
26092627 ) : (
26102628 < div className = 'mt-2' >
2611- < Text type = 'tertiary' size = 'small' >
2612- { t ( getModeValueLabel ( mode ) ) }
2613- </ Text >
2629+ < div className = 'flex items-center justify-between gap-2' >
2630+ < Text type = 'tertiary' size = 'small' >
2631+ { t ( getModeValueLabel ( mode ) ) }
2632+ </ Text >
2633+ { mode === 'set_header' ? (
2634+ < Button
2635+ size = 'small'
2636+ type = 'tertiary'
2637+ onClick = { formatSelectedOperationValueAsJson }
2638+ >
2639+ { t ( '格式化 JSON' ) }
2640+ </ Button >
2641+ ) : null }
2642+ </ div >
26142643 < TextArea
26152644 value = { selectedOperation . value_text }
26162645 autosize = { { minRows : 1 , maxRows : 4 } }
0 commit comments