weex 搜索控件-自码

自码搜索控件(包含右侧按钮是否展示),供参考和扩展

 

searchBar.vue :

<template>
    <div style="backgroundColor: #f8f8f8;padding: 10px;'">
        <div class="mainDiv">
            <div class="searchDiv"  @click="inputClick">

                <image class="search_image" src="mipmap://search_icon.png"></image>

                <div v-if="disabled" class="textDiv" style="width: 625px" >
                    <text class="textView">搜索</text>
                </div>

                <input v-else class="input" :style="{ width: isShowRightButton?550+'px':625+'px'}"
                       type="text" placeholder="搜索" @input="inputValueFun"/>

            </div>
            <text v-if="isShowRightButton" class="searchButton" @click="searchEvent" >{{rightButtonText}}</text>
        </div>
    </div>
</template>

<script>
    export default {
        name: "searchBar",
        props: {
            inputValue:{
                type: String,
                default: ''
            },
            isShowRightButton:{
                type: Boolean,
                default: true
            },
            disabled:{
                type: Boolean,
                default: false
            },
            rightButtonText:{
                type: String,
                default: '搜索'
            },
        },
        methods: {

            /**
             * 输入内容的监听
             * */
            inputValueFun(inputValue){
                this.inputValue = inputValue.value;
                this.$emit('inputValue', this.inputValue);
            },
            /**
             * 点击搜索按钮
             */
            searchEvent(){
                this.$emit('inputRightButtonClick', this.inputValue);
            },

            /**
             * 点击输入框
             * @param e
             */
            inputClick(e){
                if(this.disabled){
                    this.$emit('inputClick', this.inputValue);
                }
            }
        }
    }
</script>

<style scoped>
    .mainDiv {
        flex-direction: row;
        align-items: center;
    }

    .searchDiv {
        height: 60px;
        flex-direction: row;
        border-radius: 40px;
        margin: 10px;
        align-items: center;
        background-color: #fff;
        border-width: 1px;
        border-color: #999;
        padding: 10px;
    }
    .input {
        width: 520px;
        font-size: 30px;
        height: 60px;
        align-items: center;
        color: #333;
        outline-color: #FFFFFF;
        placeholder-color:#999;
        lines:1;
    }
    .textDiv {
        width: 520px;
        height: 60px;
    }
    .textView {
        line-height:60px;
        font-size: 30px;
        align-items: center;
        text-align: left;
        justify-content: left;
        color: #999;
    }
    .search_image {
        align-items: center;
        width: 28px;
        height: 28px;
        margin-right: 10px;
        margin-left:25px ;
    }

    .searchButton{
        height: 60px;
        font-size: 30px;
        align-items: center;
        text-align: center;
        padding: 10px;
    }
</style>

使用:

<template>
    <div>
        <searchBar :disabled="inputIsEnable" :isShowRightButton="this.isShowRightButton" @inputValue="inputValueFun" @inputClick="inputClick" @inputRightButtonClick="searchRightButtonClick"></searchBar>

    </div>
</template>

<script>
    import {Utils} from 'weex-ui'
    import searchBar from '../../components/searchBar.vue';

    export default {
        name: "organization_structure",
        components: {searchBar},
         data() {
            return {
                isShowRightButton:false,
                inputValue:'',
                inputIsEnable:true
            }
        },
        created() {
            this.tabPageHeight = Utils.env.getPageHeight();
        },
 
        methods: {

            /**
             * 点击搜索框
             * */
            searchInputClicked() {
                this.inputIsEnable = false;
                console.log('点击搜索框 ==== '+value)
            },
            /**
             * 点击搜索框右侧按钮
             * */
            searchRightButtonClick(value) {
                console.log('点击搜索框右侧按钮 ==== '+value)
            },
            /**
             * 搜索框内容
             * */
            inputValueFun(inputValue){
                this.inputValue =inputValue;
                console.log('搜索框内容 ==== '+inputValue)
            },

            /**
             * 搜索框部分点击,设置input可以输入(因为weex的input组件不支持点击,所以用div代替)
             * */
            inputClick(){
                this.inputIsEnable =false;
            },

        }

    }
</script>

<style scoped>

</style>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

漠天515

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值