Skip to content

Commit d8b7201

Browse files
committed
fix: searchbar
1 parent d700de5 commit d8b7201

File tree

6 files changed

+36
-11
lines changed

6 files changed

+36
-11
lines changed

src/components/searchbar/searchbar.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ Component({
2020
value: '',
2121
observer: 'valueChange'
2222
},
23-
search: {
24-
// 返回Promise的函数
25-
type: null, // type: Function 等价 null
26-
value: null
23+
handler: {
24+
// properties 第一层不能放 function
25+
type: Object,
26+
value: {
27+
search: null, // 返回Promise的函数
28+
}
2729
},
2830
throttle: {
2931
// 500ms内只会调用一次search函数
@@ -109,12 +111,12 @@ Component({
109111
if (Date.now() - this.lastSearch < this.data.throttle) {
110112
return
111113
}
112-
if (typeof this.data.search !== 'function') {
114+
if (typeof this.data.handler.search !== 'function') {
113115
return
114116
}
115117
this.lastSearch = Date.now()
116118
this.timerId = setTimeout(() => {
117-
this.data
119+
this.data.handler
118120
.search(this.data.value)
119121
.then((json) => {
120122
this.setData({

src/components/searchbar/searchbar.wxml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
></text>
3030
</view>
3131
<label id="searchText" class="weui-search-bar__label" bindtap="showInput">
32-
<icon class="weui-icon-search" type="search" size="12"></icon>
32+
<!-- <icon class="weui-icon-search" type="search" size="12"></icon> -->
33+
<view class="weui-icon-search"></view>
3334
<text aria-hidden class="weui-search-bar__text">{{placeholder}}</text>
3435
</label>
3536
</view>

src/components/skyline-patch.wxss

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ root-portal-content { position: absolute; }
229229

230230
/* weui-badge */
231231
.weui-badge {
232+
display: flex;
232233
min-width: 8px;
233234
padding: 1.8px 4.8px;
234235
}
@@ -512,6 +513,25 @@ root-portal {
512513
line-height: 1.14rem;
513514
display: block;
514515
}
515-
.weui-icon-clear {
516+
.weui-search-bar .weui-search-bar__box .weui-icon-clear {
517+
display: flex;
518+
}
519+
.weui-search-bar__box .weui-icon-clear {
520+
width: 1.6rem;
521+
height: 1.6rem;
522+
background-color: var(--weui-FG-2);
523+
margin-left: 16px;
524+
mask-repeat: no-repeat;
525+
mask-size: 18px;
516526
mask-image: url(data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M13.06%2012l3.006-3.005-1.06-1.06L12%2010.938%208.995%207.934l-1.06%201.06L10.938%2012l-3.005%203.005%201.06%201.06L12%2013.062l3.005%203.005%201.06-1.06L13.062%2012zM12%2022C6.477%2022%202%2017.523%202%2012S6.477%202%2012%202s10%204.477%2010%2010-4.477%2010-10%2010z%22%2F%3E%3C%2Fsvg%3E);
527+
}
528+
.weui-search-bar__box .weui-icon-clear::after {
529+
width: 30px;
530+
}
531+
.weui-search-bar .weui-icon-search, .weui-search-bar__label .weui-icon-search{
532+
width: 1.6rem;
533+
height: 1.6rem;
534+
background-color: var(--weui-FG-2);
535+
mask-repeat: no-repeat;
536+
mask-image: url(data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M16.31%2015.561l4.114%204.115-.848.848-4.123-4.123a7%207%200%2011.857-.84zM16.8%2011a5.8%205.8%200%2010-11.6%200%205.8%205.8%200%200011.6%200z%22%20fill-rule%3D%22evenodd%22%2F%3E%3C%2Fsvg%3E);
517537
}

src/example/badge/badge.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<mp-cell>
2121
<view slot="title" style="position: relative;margin-right: 10px;">
2222
<image src="../images/pic_160.png" style="width: 50px; height: 50px; display: block"/>
23-
<mp-badge aria-label="未读" content="99+" style="position: absolute;top: -.4em;right: -.4em;"/>
23+
<mp-badge aria-label="未读" content="99+" style="position: absolute;top: -0.4rem;right: -0.4rem;"/>
2424
</view>
2525
<view>联系人名称</view>
2626
<view style="font-size: 13px;color: #888888;">摘要信息</view>

src/example/searchbar/searchbar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ CustomPage({
88
},
99
onLoad() {
1010
this.setData({
11-
search: this.search.bind(this)
11+
handler: {
12+
search: this.search.bind(this)
13+
}
1214
})
1315
},
1416
search: function (value) {

src/example/searchbar/searchbar.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<view class="page__desc">搜索栏</view>
77
</view>
88
<view class="page__bd">
9-
<mp-searchbar bindselectresult="selectResult" search="{{search}}"></mp-searchbar>
9+
<mp-searchbar bindselectresult="selectResult" handler="{{handler}}"></mp-searchbar>
1010
</view>
1111
</scroll-view>
1212
</view>

0 commit comments

Comments
 (0)