33 <div class =" form-check form-check-inline" >
44 <input
55 @input =" emitModelChange('matchBy', ($event.target as HTMLInputElement).value as 'regex')"
6- :id =" inputID('Regex')" value =" regex"
7- :checked =" modelValue.subParam.matchBy === 'regex'"
8- :name =" inputName" type =" radio" class =" form-check-input" />
9- <label :for =" inputID('Regex')" class =" form-check-label" >正则</label >
6+ v-bind =" inputAttrs('regex')" />
7+ <label :for =" inputID('regex')" class =" form-check-label" >正则</label >
108 </div >
119 <div class =" form-check form-check-inline" >
1210 <input
1311 @input =" emitModelChange('matchBy', ($event.target as HTMLInputElement).value as 'implicit')"
14- :id =" inputID('Implicit')" value =" implicit"
15- :checked =" modelValue.subParam.matchBy === 'implicit'"
16- :name =" inputName" type =" radio" class =" form-check-input" />
17- <label :for =" inputID('Implicit')" class =" form-check-label" >模糊</label >
12+ v-bind =" inputAttrs('implicit')" />
13+ <label :for =" inputID('implicit')" class =" form-check-label" >模糊</label >
1814 </div >
1915 <div class =" form-check form-check-inline" >
2016 <input
2117 @input =" emitModelChange('matchBy', ($event.target as HTMLInputElement).value as 'explicit')"
22- :id =" inputID('Explicit')" value =" explicit"
23- :checked =" modelValue.subParam.matchBy === 'explicit'"
24- :name =" inputName" type =" radio" class =" form-check-input" />
25- <label :for =" inputID('Explicit')" class =" form-check-label" >精确</label >
18+ v-bind =" inputAttrs('explicit')" />
19+ <label :for =" inputID('explicit')" class =" form-check-label" >精确</label >
2620 </div >
2721 <div class =" form-check form-check-inline" >
2822 <input
2923 @input =" emitModelChange('spaceSplit', ($event.target as HTMLInputElement).checked)"
30- :id =" inputID('SpaceSplit')"
31- :checked =" modelValue.subParam.spaceSplit"
32- :disabled =" modelValue.subParam.matchBy === 'regex'"
33- type =" checkbox" class =" form-check-input" />
34- <label :for =" inputID('SpaceSplit')" class =" form-check-label" >空格分隔</label >
24+ v-bind =" inputAttrs('spaceSplit')" />
25+ <label :for =" inputID('spaceSplit')" class =" form-check-label" >空格分隔</label >
3526 </div >
3627</div >
3728</template >
@@ -58,7 +49,6 @@ defineEmits({
5849 && _ .isBoolean (p .subParam .spaceSplit )
5950});
6051const modelValue = defineModel <KnownTextParams >({ required: true });
61-
6252const emitModelChange = (
6353 name : keyof NamelessParamText [' subParam' ],
6454 value : ObjValues <NamelessParamText [' subParam' ]>
@@ -68,10 +58,26 @@ const emitModelChange = (
6858 subParam: { ... modelValue .value .subParam , [name ]: value }
6959 } as KnownTextParams ;
7060};
71- const inputID = (type : ' Explicit' | ' Implicit' | ' Regex' | ' SpaceSplit' ) =>
72- ` param${_ .upperFirst (modelValue .value .name )}${type }-${paramIndex } ` ;
73- const inputName = computed (() =>
74- ` param${_ .upperFirst (modelValue .value .name )}-${paramIndex } ` );
61+
62+ type InputType = KnownTextParams [' subParam' ][' matchBy' ] | ' spaceSplit' ;
63+ const inputID = (type : InputType ) =>
64+ ` param${_ .upperFirst (modelValue .value .name )}${_ .upperFirst (type )}-${paramIndex } ` ;
65+ const inputAttrs = (type : InputType ) => ({
66+ id: inputID (type ),
67+ class: ' form-check-input' ,
68+ ... type === ' spaceSplit'
69+ ? {
70+ type: ' checkbox' ,
71+ checked: modelValue .value .subParam .spaceSplit ,
72+ disabled: modelValue .value .subParam .matchBy === ' regex'
73+ }
74+ : {
75+ type: ' radio' ,
76+ checked: modelValue .value .subParam .matchBy === type ,
77+ name: ` param${_ .upperFirst (modelValue .value .name )}-${paramIndex } ` ,
78+ value: type
79+ }
80+ });
7581 </script >
7682
7783<style scoped>
0 commit comments