|
@@ -1,42 +1,42 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <view class="nut-searchbar">
|
|
|
|
|
- <view v-if="hasLeftOut" class="search-icon left-search-icon">
|
|
|
|
|
|
|
+ <view class="nut-searchbar" :style="searchbarStyle">
|
|
|
|
|
+ <view v-if="$slots.leftout" class="nut-searchbar__search-icon nut-searchbar__left-search-icon">
|
|
|
<slot name="leftout"></slot>
|
|
<slot name="leftout"></slot>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="search-input">
|
|
|
|
|
- <view v-if="hasLeftIn" class="search-icon iptleft-search-icon">
|
|
|
|
|
|
|
+ <view class="nut-searchbar__search-input" :style="inputSearchbarStyle">
|
|
|
|
|
+ <view v-if="$slots.leftin" class="nut-searchbar__search-icon nut-searchbar__iptleft-search-icon">
|
|
|
<slot name="leftin"></slot>
|
|
<slot name="leftin"></slot>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="input-inner">
|
|
|
|
|
- <input
|
|
|
|
|
- class="input-bar"
|
|
|
|
|
- :type="text"
|
|
|
|
|
- :maxlength="maxLength"
|
|
|
|
|
- :placeholder="placeholder"
|
|
|
|
|
- :value="modelValue"
|
|
|
|
|
- @input="valueChange"
|
|
|
|
|
- @focus="valueFocus"
|
|
|
|
|
- @blur="valueBlur"
|
|
|
|
|
- @keypress="searchAction"
|
|
|
|
|
- />
|
|
|
|
|
- <view @click="handleClear" class="input-clear" v-if="clearable" v-show="modelValue.length > 0">
|
|
|
|
|
|
|
+ <view class="nut-searchbar__input-inner">
|
|
|
|
|
+ <form action="#" @submit.prevent="handleSubmit">
|
|
|
|
|
+ <input
|
|
|
|
|
+ class="nut-searchbar__input-bar"
|
|
|
|
|
+ :type="inputType"
|
|
|
|
|
+ :maxlength="maxLength"
|
|
|
|
|
+ :placeholder="placeholder"
|
|
|
|
|
+ :value="modelValue"
|
|
|
|
|
+ @input="valueChange"
|
|
|
|
|
+ @focus="valueFocus"
|
|
|
|
|
+ @blur="valueBlur"
|
|
|
|
|
+ />
|
|
|
|
|
+ </form>
|
|
|
|
|
+ <view @click="handleClear" class="nut-searchbar__input-clear" v-if="clearable" v-show="modelValue.length > 0">
|
|
|
<nut-icon name="mask-close" size="12px"></nut-icon>
|
|
<nut-icon name="mask-close" size="12px"></nut-icon>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
- <view v-if="hasRightIn" class="search-icon iptright-sarch-icon">
|
|
|
|
|
|
|
+ <view v-if="$slots.rightin" class="nut-searchbar__search-icon nut-searchbar__iptright-sarch-icon">
|
|
|
<slot name="rightin"></slot>
|
|
<slot name="rightin"></slot>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
- <view v-if="hasRightOut" class="search-icon right-search-icon">
|
|
|
|
|
|
|
+ <view v-if="$slots.rightout" class="nut-searchbar__search-icon nut-searchbar__right-search-icon">
|
|
|
<slot name="rightout"></slot>
|
|
<slot name="rightout"></slot>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
|
-import { toRefs, reactive } from 'vue';
|
|
|
|
|
|
|
+import { toRefs, reactive, computed } from 'vue';
|
|
|
import { createComponent } from '../../utils/create';
|
|
import { createComponent } from '../../utils/create';
|
|
|
-import Icon from '../icon/index.vue';
|
|
|
|
|
const { create } = createComponent('searchbar');
|
|
const { create } = createComponent('searchbar');
|
|
|
interface Events {
|
|
interface Events {
|
|
|
eventName: 'change' | 'focus' | 'blur' | 'clear' | 'update:modelValue';
|
|
eventName: 'change' | 'focus' | 'blur' | 'clear' | 'update:modelValue';
|
|
@@ -48,6 +48,10 @@ export default create({
|
|
|
type: [String, Number],
|
|
type: [String, Number],
|
|
|
default: ''
|
|
default: ''
|
|
|
},
|
|
},
|
|
|
|
|
+ inputType: {
|
|
|
|
|
+ type: String,
|
|
|
|
|
+ default: 'text'
|
|
|
|
|
+ },
|
|
|
maxLength: {
|
|
maxLength: {
|
|
|
type: [String, Number],
|
|
type: [String, Number],
|
|
|
default: '9999'
|
|
default: '9999'
|
|
@@ -60,36 +64,34 @@ export default create({
|
|
|
type: Boolean,
|
|
type: Boolean,
|
|
|
default: true
|
|
default: true
|
|
|
},
|
|
},
|
|
|
- hasLeftIn: {
|
|
|
|
|
- type: Boolean,
|
|
|
|
|
- default: false
|
|
|
|
|
- },
|
|
|
|
|
- hasLeftOut: {
|
|
|
|
|
- type: Boolean,
|
|
|
|
|
- default: false
|
|
|
|
|
- },
|
|
|
|
|
- hasRightIn: {
|
|
|
|
|
- type: Boolean,
|
|
|
|
|
- default: false
|
|
|
|
|
|
|
+ background: {
|
|
|
|
|
+ type: String,
|
|
|
|
|
+ default: ''
|
|
|
},
|
|
},
|
|
|
- hasRightOut: {
|
|
|
|
|
- type: Boolean,
|
|
|
|
|
- default: false
|
|
|
|
|
|
|
+ inputBackground: {
|
|
|
|
|
+ type: String,
|
|
|
|
|
+ default: ''
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- components: {
|
|
|
|
|
- [Icon.name]: Icon
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
emits: ['change', 'update:modelValue', 'blur', 'focus', 'clear', 'search'],
|
|
emits: ['change', 'update:modelValue', 'blur', 'focus', 'clear', 'search'],
|
|
|
|
|
|
|
|
setup(props, { emit }) {
|
|
setup(props, { emit }) {
|
|
|
- const {} = toRefs(props);
|
|
|
|
|
-
|
|
|
|
|
const state = reactive({
|
|
const state = reactive({
|
|
|
active: false
|
|
active: false
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ const searchbarStyle = computed(() => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ background: props.background
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+ const inputSearchbarStyle = computed(() => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ background: props.inputBackground
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
const valueChange = (event: Event) => {
|
|
const valueChange = (event: Event) => {
|
|
|
const input = event.target as HTMLInputElement;
|
|
const input = event.target as HTMLInputElement;
|
|
|
let val = input.value;
|
|
let val = input.value;
|
|
@@ -108,15 +110,6 @@ export default create({
|
|
|
emit('focus', value, event);
|
|
emit('focus', value, event);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const searchAction = (event: any) => {
|
|
|
|
|
- if (event.keyCode == 13) {
|
|
|
|
|
- const input = event.target as HTMLInputElement;
|
|
|
|
|
- let value = input.value;
|
|
|
|
|
- state.active = true;
|
|
|
|
|
- emit('search', value, event);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
const valueBlur = (event: Event) => {
|
|
const valueBlur = (event: Event) => {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
state.active = false;
|
|
state.active = false;
|
|
@@ -136,13 +129,19 @@ export default create({
|
|
|
emit('clear', '');
|
|
emit('clear', '');
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ const handleSubmit = () => {
|
|
|
|
|
+ emit('search', props.modelValue);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
...toRefs(state),
|
|
...toRefs(state),
|
|
|
valueChange,
|
|
valueChange,
|
|
|
valueFocus,
|
|
valueFocus,
|
|
|
valueBlur,
|
|
valueBlur,
|
|
|
handleClear,
|
|
handleClear,
|
|
|
- searchAction
|
|
|
|
|
|
|
+ handleSubmit,
|
|
|
|
|
+ searchbarStyle,
|
|
|
|
|
+ inputSearchbarStyle
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|