luyj-tree-search.vue
3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
<view>
<view class='filterBox' :style="{'background-color' : backgroundColor}">
<view class='filter-input'
:style="{'background-color' :inputBackgroundColor ,'border-radius':radius + 'rpx'}">
<!-- 左侧搜索图标 -->
<text :style="{'color':iconColor}" class="iconfont icon-sousuo filterImg"></text>
<!-- 输入框内容 -->
<input class="text" type='text' v-model="inputVal" confirm-type="搜索" :placeholder='placeholder'
:placeholder-style="placeholderStyle" :maxlength="maxlength" @input="handleInput"
@focus="handleFocus" @blur="handleBlur" @confirm='handleFllter'></input>
<!-- 清除按钮 -->
<view v-if="clearable" class="padding-left-sm" @click="clears">
<text :style="{'color':iconColor}" class="iconfont icon-clear filterImg"></text>
</view>
</view>
</view>
</view>
</template>
<script>
/**
* 无限级树的搜索框组件
* @description 无限级树的搜索框组件
* @property {String} backgroundColor 背景色(默认#FFFFFF)
* @property {String} inputBackgroundColor 输入框背景色(默认#EEEFF0)
* @property {Number} radius 输入框圆角,单位rpx(默认40)
* @property {String} placeholder 输入框为空时占位符(默认'搜索')
* @property {String} placeholderStyle placehoder的样式
* @property {Number} maxlength 最大输入长度 ,设置为 -1 的时候不限制最大长度(默认值140)
* @property {String} iconColor 图标颜色(默认#B8B8B8)
* @property {Boolean} clearable 是否显示清除按钮 是否显示清除按钮(默认true)
* @event {Function()} input 输入框内容编号时触发
* @event {Function()} focus 输入框获得焦点时触发
* @event {Function()} blur 输入框失去焦点时触发
* @event {Function()} confirm 提交输入框内容是触发
* @event {Function()} clear 清空输入框内容时触发
*/
export default {
name: 'luyj-tree-search',
props: {
// 背景色
backgroundColor: {
type: String,
default: '#FFFFFF'
},
// 输入框背景颜色
inputBackgroundColor: {
type: String,
default: '#EEEFF0'
},
// 输入框圆角
radius: {
type: Number,
default: 40
},
// 输入框为空时占位符
placeholder: {
type: String,
default: '搜索'
},
// placeholder的样式
placeholderStyle: {
type: String,
default: ''
},
// 最大输入长度 ,设置为 -1 的时候不限制最大长度
maxlength: {
type: Number,
default: 140
},
// 图标的颜色
iconColor: {
type: String,
default: '#B8B8B8'
},
// 是否显示清除按钮
clearable: {
type: Boolean,
default: true
}
},
data() {
return {
inputVal: "", // 输入内容
};
},
components: {
test: function() {
return 120;
}
},
methods: {
/** 输入框变化时方法
* @param {Object} e
*/
handleInput: function(e) {
this.$emit("input", e)
},
/** 输入框聚焦时触发
* @param {Object} e
*/
handleFocus: function(e) {
this.$emit("focus", e)
},
/** 输入框失去焦点时触发
* @param {Object} e
*/
handleBlur: function(e) {
this.$emit("blur", e)
},
/** 提交内容时触发
* @param {Object} e
*/
handleFllter: function(e) {
this.$emit("confirm", e)
},
/**
* 清空输入框内容
*/
clears: function() {
this.inputVal = "";
this.$emit("clear", this.inputVal)
}
},
}
</script>
<style lang="scss" scoped>
.filterBox {
padding: 15rpx 32rpx;
.filter-input {
height: 80rpx;
display: flex;
align-items: center;
padding-left: 40rpx;
.filterImg {
width: 32rpx;
height: 32rpx;
margin-right: 20rpx;
margin-bottom: 5rpx;
}
.filterImgs {
width: 32rpx;
height: 32rpx;
}
.text {
width: 100%;
font-size: 32rpx;
color: #000;
}
}
}
// 添加左侧padding(用于扩大图标范围)
.padding-left-sm {
padding-left: 20rpx;
}
@import url("icon.css");
</style>