Skip to content

Commit 9f0574d

Browse files
committed
* reuse common attrs on <input> with inputAttrs() and inline inputName() into it @ <PostQueryFormWidgetInputTextMatchParam>
+ script `lint` to run eslint & stylelint @ package.json @ fe
1 parent b768159 commit 9f0574d

2 files changed

Lines changed: 30 additions & 23 deletions

File tree

fe/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"dev": "NODE_OPTIONS=--stack-trace-limit=100 nuxt dev",
99
"generate": "nuxt generate",
1010
"preview": "nuxt preview",
11-
"postinstall": "nuxt prepare"
11+
"postinstall": "nuxt prepare",
12+
"lint": "eslint; stylelint '**/*.vue'; stylelint '**/*.css'"
1213
},
1314
"dependencies": {
1415
"@ant-design-vue/nuxt": "^1.4.6",

fe/src/components/post/queryForm/widget/InputTextMatchParam.vue

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,26 @@
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
});
6051
const modelValue = defineModel<KnownTextParams>({ required: true });
61-
6252
const 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

Comments
 (0)