Commit 75ec1e33 authored by 王博文's avatar 王博文

修复右侧文字提示不生效

parent 6b9cfd96
<template>
<view class="u-search">
<view class="u-content" :style="{
<view
class="u-content"
:style="{
backgroundColor: bgColor,
borderRadius: shape == 'round' ? '100rpx' : '10rpx',
border: borderStyle,
height: height + 'rpx'
}">
}"
>
<view class="u-icon-wrap">
<u-icon class="u-clear-icon" :size="30" name="search" color="#909399"></u-icon>
</view>
<input confirm-type="search" @blur="blur" :value="value" @confirm="search" @input="inputChange" :disabled="disabled" @focus="getFocus" :focus="focus"
placeholder-class="u-placeholder-class" :placeholder="placeholder" class="u-input" type="text" :style="{
<input
confirm-type="search"
@blur="blur"
:value="value"
@confirm="search"
@input="inputChange"
:disabled="disabled"
@focus="getFocus"
:focus="focus"
placeholder-class="u-placeholder-class"
:placeholder="placeholder"
class="u-input"
type="text"
:style="{
textAlign: inputAlign
}" />
}"
/>
<view class="u-close-wrap" v-if="keyword && clearabled && focused" @touchstart="clear">
<u-icon class="u-clear-icon" name="close" :size="16" color="#fff" @touchstart="clear"></u-icon>
</view>
</view>
<view :style="[actionStyle]" class="u-action" :class="[showActionBtn || show ? 'u-action-active' : '']" @tap="custom">
{{actiontext}}
</view>
<view
:style="[actionStyle]"
class="u-action"
:class="[showActionBtn || show ? 'u-action-active' : '']"
@tap="custom"
>{{actionText}}</view>
</view>
</template>
<script>
export default {
export default {
props: {
// 搜索框形状,round-圆形,square-方形
shape: {
type: String,
default: 'round'
default: "round"
},
// 搜索框背景色,默认值#f2f2f2
bgColor: {
type: String,
default: '#f2f2f2'
default: "#f2f2f2"
},
// 占位提示文字
placeholder: {
type: String,
default: '请输入关键字'
default: "请输入关键字"
},
// 是否启用清除控件
clearabled: {
......@@ -60,18 +79,18 @@
actionStyle: {
type: Object,
default() {
return {}
return {};
}
},
// 取消按钮文字
actiontext: {
actionText: {
type: String,
default: '搜索'
default: "搜索"
},
// 输入框内容对齐方式,可选值为 left|center|right
inputAlign: {
type: String,
default: 'left'
default: "left"
},
// 是否启用输入框
disabled: {
......@@ -86,12 +105,12 @@
// 边框颜色,只要配置了颜色,才会有边框
borderColor: {
type: String,
default: 'none'
default: "none"
},
// 输入框的初始化内容
value: {
type: String,
default: ''
default: ""
},
// 搜索框高度,单位rpx
height: {
......@@ -101,21 +120,21 @@
},
data() {
return {
keyword: '',
keyword: "",
showClear: false, // 是否显示右边的清除图标
show: false,
// 标记input当前状态是否处于聚焦中,如果是,才会显示右侧的清除控件
focused: this.focus,
focused: this.focus
// 绑定输入框的值
// inputValue: this.value
}
};
},
watch: {
keyword(nVal) {
// 双向绑定值,让v-model绑定的值双向变化
this.$emit('input', nVal)
this.$emit("input", nVal);
// 触发change事件,事件效果和v-model双向绑定的效果一样,让用户多一个选择
this.$emit('change', nVal)
this.$emit("change", nVal);
},
value: {
immediate: true,
......@@ -131,8 +150,8 @@
},
// 样式,根据用户传入的颜色值生成,如果不传入,默认为none
borderStyle() {
if(this.borderColor) return `1px solid ${this.borderColor}`;
else return 'none';
if (this.borderColor) return `1px solid ${this.borderColor}`;
else return "none";
}
},
methods: {
......@@ -143,17 +162,17 @@
// 清空输入
// 也可以作为用户通过this.$refs形式调用清空输入框内容
clear() {
this.keyword = '';
this.keyword = "";
},
// 确定搜索
search() {
this.$emit('search', this.keyword);
this.$emit("search", this.keyword);
// 收起键盘
uni.hideKeyboard();
},
// 点击右边自定义按钮的事件
custom() {
this.$emit('custom', this.keyword);
this.$emit("custom", this.keyword);
// 收起键盘
uni.hideKeyboard();
},
......@@ -169,37 +188,37 @@
this.show = false;
}
}
}
};
</script>
<style lang="scss" scoped>
.u-search {
.u-search {
display: flex;
align-items: center;
flex: 1;
}
}
.u-content {
.u-content {
display: flex;
align-items: center;
padding: 0 18rpx;
flex: 1;
}
}
.u-clear-icon {
.u-clear-icon {
display: flex;
align-items: center;
}
}
.u-input {
.u-input {
flex: 1;
font-size: 28rpx;
line-height: 1;
margin: 0 10rpx;
color: $u-tips-color;
}
}
.u-close-wrap {
.u-close-wrap {
width: 34rpx;
height: 34rpx;
display: flex;
......@@ -207,13 +226,13 @@
justify-content: center;
background-color: rgb(200, 203, 204);
border-radius: 50%;
}
}
.u-placeholder-class {
.u-placeholder-class {
color: $u-tips-color;
}
}
.u-action {
.u-action {
font-size: 28rpx;
color: $u-main-color;
width: 0;
......@@ -221,10 +240,10 @@
transition: all 0.3s;
white-space: nowrap;
text-align: center;
}
}
.u-action-active {
.u-action-active {
width: 80rpx;
margin-left: 10rpx;
}
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment