input-search.vue 2.32 KB
<template>
    <div class="input-search">
        <i class="icon icon-search-new"></i>
        <input ref="inpSearch" class="inp-search" type="text" dir="auto" placeholder="Search BLK" autocomplete="off" autocorrect="off" spellcheck="false" :value="value" @input="valueInput" @keyup.enter="enter">
        <button class="clear-input" type="button" @click="clear" v-show="value">
            <i class="icon icon-error-tip" v-show="!loading"></i>
            <i class="icon icon-loading" v-show="loading"></i>
        </button>
    </div>
</template>

<script>
export default {
    name: 'InputSearch',
    props: {
        value: String,
        loading: Boolean
    },
    data() {
        return {
            showClear: false
        };
    },
    methods: {
        clear() {
            this.$emit('input', '');
            this.$refs.inpSearch && this.$refs.inpSearch.focus();
        },
        enter() {
            this.$emit('enter', '');
        },
        focus() {
            if (this.$yoho.isAndroid) {
                setTimeout(() => {
                    this.$refs.inpSearch && this.$refs.inpSearch.focus(); // 延迟focus 防止影响进入动画流畅
                }, 200);
            }
        },
        valueInput(event) {
            this.$emit('input', event.target.value);
        }
    }
};
</script>

<style lang="scss">
.input-search {
    position: relative;
    display: flex;

    .icon-search-new {
        vertical-align: middle;
        display: inline-block;
        width: 60px;
        height: 100%;
        position: absolute;
        font-size: 28px;
        color: #b0b0b0;
        left: 0;
        top: 0;
        bottom: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .inp-search {
        padding: 0 60px;
        width: 100%;
        background-color: #eeeeee;
        border-radius: 8px;
        color: #000000;
        font-size: 28px;
    }
    .clear-input {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: none;
        background: none;

        .icon {
            color: #b0b0b0;
            font-size: 34px;
        }
    }
    .icon-loading {
        animation: loading 2s linear infinite;
    }

}
</style>