diff --git a/devui/input/src/input.tsx b/devui/input/src/input.tsx
index a2720754dc9072c696fb2efbac8ea04c269cbda9..0c3763e56f597e0a04a348ddb5b6efc07513510f 100644
--- a/devui/input/src/input.tsx
+++ b/devui/input/src/input.tsx
@@ -1,9 +1,18 @@
-import { defineComponent, computed, ref, watch, toRef } from 'vue';
+import { defineComponent, computed, ref, watch, nextTick, onMounted, toRefs } from 'vue';
import { inputProps, InputType } from './use-input';
import './input.scss'
export default defineComponent({
name: 'DInput',
+ directives: {
+ focus: {
+ mounted: function (el, binding) {
+ if (binding.value) {
+ el.focus()
+ }
+ }
+ }
+ },
props: inputProps,
emits: ['update:value', 'focus', 'blur', 'change', 'keydown'],
setup(props, ctx) {
@@ -23,7 +32,7 @@ export default defineComponent({
}, { immediate: true })
watch(() => props.value, value => {
- value && value.length > 0 ? showPwdIcon.value = true : showPwdIcon.value = false
+ (value && value.length > 0 && showPreviewIcon.value) ? showPwdIcon.value = true : showPwdIcon.value = false
})
const onInput = ($event: Event) => {
@@ -44,7 +53,6 @@ export default defineComponent({
onChangeInputType = () => {
inputType.value = inputType.value === 'password' ? 'text' : 'password'
}
-
return {
inputCls,
inputType,
@@ -66,6 +74,7 @@ export default defineComponent({
inputCls,
inputType,
maxLength,
+ autoFocus,
placeholder,
disabled,
onInput,
@@ -78,6 +87,7 @@ export default defineComponent({
return (
, keywords: Ref): KeydownReturnTypes => {
+export const keydownHandles = (ctx: SetupContext<(EmitProps)[]>, keywords: Ref, delay: number): KeydownReturnTypes => {
// 删除按钮显示
const onInputKeydown = ($event: KeyboardEvent) => {
switch ($event.key) {
@@ -24,15 +24,18 @@ export const keydownHandles = (ctx: SetupContext<(EmitProps)[]>, keywords: Ref {
if ($event.target instanceof HTMLInputElement) {
const value = $event.target.value
- ctx.emit('searchFn', value)
+ useEmitKeyword(value)
}
}
const onClickHandle = () => {
- console.log(keywords.value)
- ctx.emit('searchFn', keywords.value)
+ useEmitKeyword(keywords.value)
}
+ const useEmitKeyword = debounce((value: string) => {
+ ctx.emit('searchFn', value)
+ }, delay)
return {
onInputKeydown,
+ useEmitKeyword,
onClickHandle
}
}
diff --git a/devui/search/src/search-types.ts b/devui/search/src/search-types.ts
index 0f0d5071921804a4c9bfca0499a276da6b803f03..05a97d6fe7197f5ee298997a5aaf49da084e6b3b 100644
--- a/devui/search/src/search-types.ts
+++ b/devui/search/src/search-types.ts
@@ -69,4 +69,5 @@ export interface KeywordsReturnTypes {
export interface KeydownReturnTypes {
onInputKeydown: (e: KeyboardEvent) => void
onClickHandle: () => void
+ useEmitKeyword: (e: string) => void
}
\ No newline at end of file
diff --git a/devui/search/src/search.tsx b/devui/search/src/search.tsx
index 4cded6858dd716ea5ec005dbb5552a7429cb90af..6e7385279679701fde5bda0fd4d12f26cef8f43f 100644
--- a/devui/search/src/search.tsx
+++ b/devui/search/src/search.tsx
@@ -16,10 +16,13 @@ export default defineComponent({
const {keywords, clearIconShow, onClearHandle} = keywordsHandles(ctx, props)
// 键盘回车事件
- const { onInputKeydown, onClickHandle } = keydownHandles(ctx, keywords)
+ const { onInputKeydown, onClickHandle, useEmitKeyword } = keydownHandles(ctx, keywords, props.delay)
// 双向绑定
const onInputUpdate = (event: string) => {
+ if (props.isKeyupSearch) {
+ useEmitKeyword(event)
+ }
keywords.value = event
ctx.emit('update:modelValue', event)
}
@@ -35,6 +38,7 @@ export default defineComponent({
Default
-
+
Disabled
@@ -23,7 +23,6 @@
Error
-