@@ -53,31 +53,42 @@ const UnblockWebRestrictionsConfigForm: React.FC<{
5353 < Input />
5454 </ Form . Item >
5555 < Form . Item
56- label = { '测试需要匹配的 URL' }
57- name = { 'tempUrl' }
58- rules = { [
59- {
60- type : 'url' ,
61- message : '测试需要匹配的 URL 必须是个 URL 啊喂 (#`O′)' ,
62- } ,
63- ( form ) => ( {
64- async validator ( rule , _ ) {
65- const values = form . getFieldsValue ( ) as Pick <
66- BlockConfig ,
67- 'type' | 'url'
68- > & { tempUrl : string }
69- if ( ! values . tempUrl ) {
70- throw new Error ( '测试需要匹配的 URL 不能为空' )
71- }
72- if ( ! match ( new URL ( values . tempUrl ) , values ) ) {
73- throw new Error ( '测试需要匹配的 URL 未能匹配!' )
74- }
75- } ,
76- } ) ,
77- ] }
78- dependencies = { [ 'type' , 'url' ] }
56+ shouldUpdate = { ( prevValues , currentValues ) =>
57+ prevValues . type !== currentValues . type
58+ }
7959 >
80- < Input />
60+ { ( { getFieldValue } ) => {
61+ return getFieldValue ( 'type' ) === 'regex' ? (
62+ < Form . Item
63+ label = { '测试需要匹配的 URL' }
64+ name = { 'tempUrl' }
65+ rules = { [
66+ {
67+ required : true ,
68+ type : 'url' ,
69+ message : '测试需要匹配的 URL 必须是个 URL 啊喂 (#`O′)' ,
70+ } ,
71+ ( form ) => ( {
72+ async validator ( rule , _ ) {
73+ const values = form . getFieldsValue ( ) as Pick <
74+ BlockConfig ,
75+ 'type' | 'url'
76+ > & { tempUrl : string }
77+ if ( ! values . tempUrl ) {
78+ throw new Error ( '测试需要匹配的 URL 不能为空' )
79+ }
80+ if ( ! match ( new URL ( values . tempUrl ) , values ) ) {
81+ throw new Error ( '测试需要匹配的 URL 未能匹配!' )
82+ }
83+ } ,
84+ } ) ,
85+ ] }
86+ dependencies = { [ 'type' , 'url' ] }
87+ >
88+ < Input />
89+ </ Form . Item >
90+ ) : null
91+ } }
8192 </ Form . Item >
8293 < Form . Item >
8394 < Space >
0 commit comments