mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
[improvement]: search组件支持插槽功能 (#396)
This commit is contained in:
parent
41ec35fbb8
commit
de483916da
@ -1,7 +1,9 @@
|
|||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
inputValue: '',
|
inputValue: '',
|
||||||
focus: true
|
focus: true,
|
||||||
|
range: ['门店', '配送至'],
|
||||||
|
rangeIndex: 0
|
||||||
},
|
},
|
||||||
|
|
||||||
searchChange(e) {
|
searchChange(e) {
|
||||||
@ -16,5 +18,11 @@ Page({
|
|||||||
|
|
||||||
handleCancel() {
|
handleCancel() {
|
||||||
console.error('cancel')
|
console.error('cancel')
|
||||||
|
},
|
||||||
|
|
||||||
|
pickerChange(e) {
|
||||||
|
this.setData({
|
||||||
|
rangeIndex: e.detail.value
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
<zan-panel title='基本用法'>
|
<zan-panel title='基本用法'>
|
||||||
<zan-search
|
<zan-search
|
||||||
alignLeft="{{ true }}"
|
|
||||||
placeholder="搜索..."
|
placeholder="搜索..."
|
||||||
keyword="{{ inputValue }}"
|
keyword="{{ inputValue }}"
|
||||||
placeholder="搜索商品"
|
|
||||||
focus="{{ focus }}"
|
focus="{{ focus }}"
|
||||||
bindchange="searchChange"
|
bindchange="searchChange"
|
||||||
bindsearch="searchDone"
|
bindsearch="searchDone"
|
||||||
@ -14,21 +12,17 @@
|
|||||||
|
|
||||||
<zan-panel title='不可用'>
|
<zan-panel title='不可用'>
|
||||||
<zan-search
|
<zan-search
|
||||||
alignLeft="{{ true }}"
|
|
||||||
placeholder="搜索..."
|
placeholder="搜索..."
|
||||||
disabled="{{ true }}"
|
disabled="{{ true }}"
|
||||||
placeholder="搜索商品"
|
|
||||||
/>
|
/>
|
||||||
</zan-panel>
|
</zan-panel>
|
||||||
|
|
||||||
<zan-panel title='自定义样式'>
|
<zan-panel title='自定义样式'>
|
||||||
<zan-search
|
<zan-search
|
||||||
alignLeft="{{ true }}"
|
|
||||||
placeholder="搜索..."
|
placeholder="搜索..."
|
||||||
searchStyle="height: 88rpx; padding: 0 30rpx; background: {{ searchbg || '#F2F2F2' }};"
|
searchStyle="height: 88rpx; padding: 0 30rpx; background: {{ searchbg || '#F2F2F2' }};"
|
||||||
inputStyle="height: 56rpx; border-radius: 8rpx;"
|
inputStyle="height: 56rpx; border-radius: 8rpx;"
|
||||||
keyword="{{ inputValue }}"
|
keyword="{{ inputValue }}"
|
||||||
placeholder="搜索商品"
|
|
||||||
focus="{{ focus }}"
|
focus="{{ focus }}"
|
||||||
bindchange="searchChange"
|
bindchange="searchChange"
|
||||||
bindsearch="searchDone"
|
bindsearch="searchDone"
|
||||||
@ -37,10 +31,8 @@
|
|||||||
|
|
||||||
<zan-panel title='取消按钮'>
|
<zan-panel title='取消按钮'>
|
||||||
<zan-search
|
<zan-search
|
||||||
alignLeft="{{ true }}"
|
|
||||||
placeholder="搜索..."
|
placeholder="搜索..."
|
||||||
keyword="{{ inputValue }}"
|
keyword="{{ inputValue }}"
|
||||||
placeholder="搜索商品"
|
|
||||||
focus="{{ focus }}"
|
focus="{{ focus }}"
|
||||||
useCancel="{{ true }}"
|
useCancel="{{ true }}"
|
||||||
bindchange="searchChange"
|
bindchange="searchChange"
|
||||||
@ -48,4 +40,29 @@
|
|||||||
bindcancel="handleCancel"
|
bindcancel="handleCancel"
|
||||||
/>
|
/>
|
||||||
</zan-panel>
|
</zan-panel>
|
||||||
|
|
||||||
|
<zan-panel title="高级用法 自定义input插槽">
|
||||||
|
<zan-search
|
||||||
|
placeholder="搜索..."
|
||||||
|
keyword="{{ inputValue }}"
|
||||||
|
focus="{{ focus }}"
|
||||||
|
useCancel="{{ true }}"
|
||||||
|
bindchange="searchChange"
|
||||||
|
bindsearch="searchDone"
|
||||||
|
bindcancel="handleCancel"
|
||||||
|
>
|
||||||
|
<picker
|
||||||
|
slot="input"
|
||||||
|
mode="selector"
|
||||||
|
class="zan-search__selector"
|
||||||
|
bindchange="pickerChange"
|
||||||
|
style="width: 60px"
|
||||||
|
range="{{ range }}"
|
||||||
|
value="{{ rangeIndex }}"
|
||||||
|
wx:if="{{ range.length > 0}}"
|
||||||
|
>
|
||||||
|
<view class="picker">{{ range[rangeIndex] }}</view>
|
||||||
|
</picker>
|
||||||
|
</zan-search>
|
||||||
|
</zan-panel>
|
||||||
</doc-page>
|
</doc-page>
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
picker {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
padding-right: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.picker {
|
||||||
|
position: relative;
|
||||||
|
width: 110rpx;
|
||||||
|
height: 100%;
|
||||||
|
color: #666;
|
||||||
|
font-size: 28rpx;
|
||||||
|
margin-left: 20rpx;
|
||||||
|
}
|
||||||
|
.picker::after {
|
||||||
|
content: '';
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 50%;
|
||||||
|
margin-top: -6rpx;
|
||||||
|
border-top: 12rpx solid #333;
|
||||||
|
border-right: 8rpx solid transparent;
|
||||||
|
border-left: 8rpx solid transparent;
|
||||||
|
}
|
@ -39,6 +39,28 @@ searchDone(e) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 使用slot
|
||||||
|
|
||||||
|
```js
|
||||||
|
<zan-search
|
||||||
|
placeholder="搜索..."
|
||||||
|
useCancel
|
||||||
|
>
|
||||||
|
<picker
|
||||||
|
slot="input"
|
||||||
|
mode="selector"
|
||||||
|
range="{{ range }}"
|
||||||
|
value="{{ rangeIndex }}"
|
||||||
|
bindchange="pickerChange"
|
||||||
|
class="zan-search__selector"
|
||||||
|
style="width: 60px"
|
||||||
|
wx:if="{{ range.length > 0}}"
|
||||||
|
>
|
||||||
|
<view class="picker">{{ range[rangeIndex] }}</view>
|
||||||
|
</picker>
|
||||||
|
</zan-search>
|
||||||
|
```
|
||||||
|
|
||||||
### API
|
### API
|
||||||
|
|
||||||
#### 参数
|
#### 参数
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
Component({
|
Component({
|
||||||
externalClasses: ['search-class', 'input-class', 'cancel-class'],
|
externalClasses: ['search-class', 'input-class', 'cancel-class'],
|
||||||
|
options: {
|
||||||
|
multipleSlots: true // 在组件定义时的选项中启用多slot支持
|
||||||
|
},
|
||||||
properties: {
|
properties: {
|
||||||
cancelText: {
|
cancelText: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -32,33 +32,6 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.zan-search picker {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
height: 100%;
|
|
||||||
padding-right: 20rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.zan-search__form .picker {
|
|
||||||
position: relative;
|
|
||||||
width: 110rpx;
|
|
||||||
height: 100%;
|
|
||||||
color: #666;
|
|
||||||
font-size: 28rpx;
|
|
||||||
margin-left: 20rpx;
|
|
||||||
}
|
|
||||||
.zan-search__form .picker::after {
|
|
||||||
content: '';
|
|
||||||
width: 0;
|
|
||||||
height: 0;
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 50%;
|
|
||||||
margin-top: -6rpx;
|
|
||||||
border-top: 12rpx solid #333;
|
|
||||||
border-right: 8rpx solid transparent;
|
|
||||||
border-left: 8rpx solid transparent;
|
|
||||||
}
|
|
||||||
.zan-search__form input {
|
.zan-search__form input {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
style="{{ inputStyle }}"
|
style="{{ inputStyle }}"
|
||||||
>
|
>
|
||||||
<icon type="search" size="15" color="#a9a9a9" />
|
<icon type="search" size="15" color="#a9a9a9" />
|
||||||
|
<slot name="input"></slot>
|
||||||
<input
|
<input
|
||||||
class="zan-search__input"
|
class="zan-search__input"
|
||||||
placeholder="{{ placeholder }}"
|
placeholder="{{ placeholder }}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user