@@ -43,6 +43,7 @@ import UnLogin from "@/assets/unLogin.png"
4343import { pluginTypeToName } from "../plugins/builtInData"
4444import MITMContext from "./Context/MITMContext"
4545import { grpcMITMClearPluginCache , grpcMITMRemoveHook , MITMRemoveHookRequest } from "./MITMHacker/utils"
46+ import { useI18nNamespaces } from "@/i18n/useI18nNamespaces"
4647
4748const { ipcRenderer} = window . require ( "electron" )
4849
@@ -80,6 +81,7 @@ export const MITMYakScriptLoader = React.memo((p: MITMYakScriptLoaderProps) => {
8081 */
8182 const [ mitmParamsDrawer , setMitmParamsDrawer ] = useState < boolean > ( false )
8283 const mitmParamsInitFormValueRef = useRef < CustomPluginExecuteFormValue > ( { } )
84+ const mitmParamsDefaultFormValueRef = useRef < CustomPluginExecuteFormValue > ( { } )
8385 const mitmParamsRequiredParamsRef = useRef < YakParamProps [ ] > ( [ ] )
8486 const mitmParamsGroupParamsRef = useRef < YakExtraParamProps [ ] > ( [ ] )
8587 const [ drawerWidth , setDrawerWidth ] = useState < number > ( 45 ) // 默认45vw
@@ -95,6 +97,7 @@ export const MITMYakScriptLoader = React.memo((p: MITMYakScriptLoaderProps) => {
9597 [ ele . Field ] : value
9698 }
9799 } )
100+ mitmParamsDefaultFormValueRef . current = { ...initFormValue }
98101 getRemoteValue ( "mitm_has_params_" + i . ScriptName ) . then ( ( res ) => {
99102 if ( res ) {
100103 try {
@@ -432,6 +435,7 @@ export const MITMYakScriptLoader = React.memo((p: MITMYakScriptLoaderProps) => {
432435 drawerWidth = { drawerWidth }
433436 onSetDrawerWidth = { setDrawerWidth }
434437 initFormValue = { mitmParamsInitFormValueRef . current }
438+ defaultFormValue = { mitmParamsDefaultFormValueRef . current }
435439 requiredParams = { mitmParamsRequiredParamsRef . current }
436440 groupParams = { mitmParamsGroupParamsRef . current }
437441 onSubmitYakScriptId = { onSubmitYakScriptId }
@@ -498,6 +502,7 @@ interface MitmHasParamsDrawer {
498502 i : YakScript
499503 drawerWidth : number
500504 initFormValue : CustomPluginExecuteFormValue
505+ defaultFormValue : CustomPluginExecuteFormValue
501506 requiredParams : YakParamProps [ ]
502507 groupParams : YakExtraParamProps [ ]
503508 onSubmitYakScriptId : ( id : number , params : YakExecutorParam [ ] ) => void
@@ -511,6 +516,7 @@ const MitmHasParamsDrawer = React.memo((props: MitmHasParamsDrawer) => {
511516 i,
512517 drawerWidth,
513518 initFormValue,
519+ defaultFormValue,
514520 requiredParams,
515521 groupParams,
516522 onSubmitYakScriptId,
@@ -525,6 +531,7 @@ const MitmHasParamsDrawer = React.memo((props: MitmHasParamsDrawer) => {
525531 } , [ mitmContent . mitmStore . version ] )
526532 const mitmHasParamsPluginFormRef = useRef < MitmHasParamsFormPropsRefProps > ( )
527533 const [ initWidth , setInitWidth ] = useState < number > ( drawerWidth )
534+ const { t, i18n} = useI18nNamespaces ( [ "mitm" ] )
528535
529536 useEffect ( ( ) => {
530537 return ( ) => {
@@ -562,6 +569,12 @@ const MitmHasParamsDrawer = React.memo((props: MitmHasParamsDrawer) => {
562569 < Tooltip title = { i . ScriptName } > { `${ i . ScriptName } ` } </ Tooltip >
563570 </ div >
564571 < Space >
572+ < YakitButton
573+ type = 'outline2'
574+ onClick = { ( ) => mitmHasParamsPluginFormRef . current ?. reset ( ) }
575+ >
576+ { t ( "YakScriptLoader.reset_parameters" ) }
577+ </ YakitButton >
565578 < YakitButton
566579 type = 'outline2'
567580 onClick = { ( ) => {
@@ -636,6 +649,7 @@ const MitmHasParamsDrawer = React.memo((props: MitmHasParamsDrawer) => {
636649 < MitmHasParamsForm
637650 ref = { mitmHasParamsPluginFormRef }
638651 initFormValue = { initFormValue }
652+ defaultFormValue = { defaultFormValue }
639653 requiredParams = { requiredParams }
640654 groupParams = { groupParams }
641655 />
@@ -646,26 +660,35 @@ const MitmHasParamsDrawer = React.memo((props: MitmHasParamsDrawer) => {
646660} )
647661interface MitmHasParamsFormPropsRefProps {
648662 onSubmit : ( ) => Promise < CustomPluginExecuteFormValue | undefined >
663+ reset : ( ) => void
649664}
650665interface MitmHasParamsFormProps {
651666 ref ?: ForwardedRef < MitmHasParamsFormPropsRefProps >
652667 initFormValue : CustomPluginExecuteFormValue
668+ defaultFormValue : CustomPluginExecuteFormValue
653669 requiredParams : YakParamProps [ ]
654670 groupParams : YakExtraParamProps [ ]
655671}
656672const MitmHasParamsForm = React . forwardRef ( ( props : MitmHasParamsFormProps , ref ) => {
657- const { initFormValue, requiredParams, groupParams} = props
673+ const { initFormValue, defaultFormValue , requiredParams, groupParams} = props
658674 const [ form ] = Form . useForm ( )
659675 const jsonSchemaListRef = useRef < {
660676 [ key : string ] : any
661677 } > ( { } )
678+ const [ resetCounter , setResetCounter ] = useState ( 0 )
679+ const [ currentJsonSchemaInitial , setCurrentJsonSchemaInitial ] = useState ( initFormValue )
662680
663681 useImperativeHandle (
664682 ref ,
665683 ( ) => ( {
666- onSubmit : handleFormSubmit
684+ onSubmit : handleFormSubmit ,
685+ reset : ( ) => {
686+ form . setFieldsValue ( defaultFormValue )
687+ setCurrentJsonSchemaInitial ( defaultFormValue )
688+ setResetCounter ( prev => prev + 1 )
689+ }
667690 } ) ,
668- [ form ]
691+ [ form , defaultFormValue ]
669692 )
670693
671694 const handleFormSubmit : ( ) => Promise < CustomPluginExecuteFormValue | undefined > = useMemoizedFn ( ( ) => {
@@ -700,11 +723,12 @@ const MitmHasParamsForm = React.forwardRef((props: MitmHasParamsFormProps, ref)
700723 initialValues = { initFormValue }
701724 >
702725 < ExecuteEnterNodeByPluginParams
726+ key = { resetCounter }
703727 paramsList = { requiredParams }
704728 pluginType = { "mitm" }
705729 isExecuting = { false }
706730 jsonSchemaListRef = { jsonSchemaListRef }
707- jsonSchemaInitial = { initFormValue }
731+ jsonSchemaInitial = { currentJsonSchemaInitial }
708732 />
709733 < ExtraParamsNodeByType extraParamsGroup = { groupParams } pluginType = { "mitm" } />
710734 </ Form >
0 commit comments