Skip to content

Commit 86dd39e

Browse files
author
xingyan
committed
feat(CategorySearch): 输入框筛选条件点确定时触发校验
1 parent 89fdcd7 commit 86dd39e

1 file changed

Lines changed: 43 additions & 39 deletions

File tree

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,50 @@
1-
import { defineComponent, toRefs, inject, reactive } from 'vue';
1+
import { defineComponent, inject, reactive, ref } from 'vue';
22
import type { SetupContext } from 'vue';
33
import { Button } from '../../../button';
44
import { typeMenuProps, categorySearchInjectionKey } from '../category-search-types';
55
import type { TypeMenuProps, CategorySearchInjection } from '../category-search-types';
66

77
export default defineComponent({
8-
name: 'DCategorySearchTextInput',
9-
props: typeMenuProps,
10-
emits: ['close'],
11-
setup(props: TypeMenuProps, ctx: SetupContext) {
12-
const { tag } = toRefs(props);
13-
const { getTextInputValue } = inject(categorySearchInjectionKey) as CategorySearchInjection;
14-
const formData = reactive({
15-
text: tag.value.value!.value,
16-
})
17-
const onConfirmClick = () => {
18-
getTextInputValue(tag.value, formData.text as string);
19-
ctx.emit('close');
20-
};
21-
const onCancelClick = () => {
22-
ctx.emit('close');
23-
};
8+
name: 'DCategorySearchTextInput',
9+
props: typeMenuProps,
10+
emits: ['close'],
11+
setup(props: TypeMenuProps, ctx: SetupContext) {
12+
const formEl = ref();
13+
const { getTextInputValue } = inject(categorySearchInjectionKey) as CategorySearchInjection;
14+
const formData = reactive({
15+
text: props.tag.value!.value,
16+
});
17+
const onConfirmClick = () => {
18+
formEl.value.validate((isValid: boolean) => {
19+
if (isValid) {
20+
getTextInputValue(props.tag, formData.text as string);
21+
ctx.emit('close');
22+
}
23+
});
24+
};
25+
const onCancelClick = () => {
26+
ctx.emit('close');
27+
};
2428

25-
return () => (
26-
<d-form data={formData} pop-position={['right']}>
27-
<d-form-item field='text' rules={tag.value.validateRules}>
28-
<d-input
29-
v-model={formData.text}
30-
autocomplete='off'
31-
autofocus
32-
maxlength={tag.value.maxLength}
33-
placeholder={tag.value.placeholder || ''}></d-input>
34-
</d-form-item>
35-
<div class='dp-dropdown-operation-area'>
36-
<Button variant='solid' onClick={onConfirmClick}>
37-
确定
38-
</Button>
39-
<Button variant='solid' color='secondary' onClick={onCancelClick}>
40-
取消
41-
</Button>
42-
</div>
43-
</d-form>
44-
);
45-
},
46-
});
29+
return () => (
30+
<d-form ref={formEl} data={formData} pop-position={['right']}>
31+
<d-form-item field="text" rules={props.tag.validateRules}>
32+
<d-input
33+
v-model={formData.text}
34+
autocomplete="off"
35+
autofocus
36+
maxlength={props.tag.maxLength}
37+
placeholder={props.tag.placeholder || ''}></d-input>
38+
</d-form-item>
39+
<div class="dp-dropdown-operation-area">
40+
<Button variant="solid" onClick={onConfirmClick}>
41+
确定
42+
</Button>
43+
<Button variant="solid" color="secondary" onClick={onCancelClick}>
44+
取消
45+
</Button>
46+
</div>
47+
</d-form>
48+
);
49+
},
50+
});

0 commit comments

Comments
 (0)