提交 e48fcada 编写于 作者: D DCloud_LXH

feat(H5): H5导航栏搜索框增加清除按钮

上级 b7e19952
此差异已折叠。
<template> <template>
<uni-page-head :uni-page-head-type="type"> <uni-page-head :uni-page-head-type="type">
<div <div
:style="{transitionDuration:duration,transitionTimingFunction:timingFunc,backgroundColor:bgColor,color:textColor}" :style="{transitionDuration:duration,transitionTimingFunction:timingFunc,backgroundColor:bgColor,color:textColor}"
:class="headClass" :class="headClass"
class="uni-page-head" class="uni-page-head"
> >
<div class="uni-page-head-hd"> <div class="uni-page-head-hd">
<div <div
v-show="backButton" v-show="backButton"
class="uni-page-head-btn" class="uni-page-head-btn"
@click="_back" @click="_back"
> >
<i <i
:style="{color:color,fontSize:'27px'}" :style="{color:color,fontSize:'27px'}"
class="uni-btn-icon" class="uni-btn-icon"
>&#xe601;</i> >&#xe601;</i>
</div> </div>
<template v-for="(btn,index) in btns"> <template v-for="(btn,index) in btns">
<div <div
v-if="btn.float === 'left'" v-if="btn.float === 'left'"
:key="index" :key="index"
:style="{backgroundColor: type==='transparent'?btn.background:'transparent',width:btn.width}" :style="{backgroundColor: type==='transparent'?btn.background:'transparent',width:btn.width}"
:badge-text="btn.badgeText" :badge-text="btn.badgeText"
:class="{'uni-page-head-btn-red-dot':btn.redDot||btn.badgeText,'uni-page-head-btn-select':btn.select}" :class="{'uni-page-head-btn-red-dot':btn.redDot||btn.badgeText,'uni-page-head-btn-select':btn.select}"
class="uni-page-head-btn" class="uni-page-head-btn"
> >
<i <i
:style="_formatBtnStyle(btn)" :style="_formatBtnStyle(btn)"
class="uni-btn-icon" class="uni-btn-icon"
@click="_onBtnClick(index)" @click="_onBtnClick(index)"
v-html="_formatBtnFontText(btn)" v-html="_formatBtnFontText(btn)"
/> />
</div> </div>
</template> </template>
</div> </div>
<div <div
v-if="!searchInput" v-if="!searchInput"
class="uni-page-head-bd" class="uni-page-head-bd"
> >
<div <div
:style="{fontSize:titleSize,opacity:type==='transparent'?0:1}" :style="{fontSize:titleSize,opacity:type==='transparent'?0:1}"
class="uni-page-head__title" class="uni-page-head__title"
> >
<i <i
v-if="loading" v-if="loading"
class="uni-loading" class="uni-loading"
/> />
<img <img
v-if="titleImage!==''" v-if="titleImage!==''"
:src="titleImage" :src="titleImage"
class="uni-page-head__title_image" class="uni-page-head__title_image"
> >
<template v-else> <template v-else>
{{ titleText }} {{ titleText }}
</template> </template>
</div> </div>
</div> </div>
<div <div
v-if="searchInput" v-if="searchInput"
:style="{'border-radius':searchInput.borderRadius,'background-color':searchInput.backgroundColor}" :style="{'border-radius':searchInput.borderRadius,'background-color':searchInput.backgroundColor}"
class="uni-page-head-search" class="uni-page-head-search"
> >
<div <div
:style="{color:searchInput.placeholderColor}" :style="{color:searchInput.placeholderColor}"
:class="[`uni-page-head-search-placeholder-${focus || text ? 'left' : searchInput.align}`]" :class="[`uni-page-head-search-placeholder-${focus || showPlaceholder ? 'left' : searchInput.align}`]"
class="uni-page-head-search-placeholder" class="uni-page-head-search-placeholder"
v-text="text || composing ? '' : searchInput.placeholder" v-text="showPlaceholder || composing ? '' : searchInput.placeholder"
/> />
<v-uni-input <v-uni-input
ref="input" ref="input"
v-model="text" v-model="text"
:focus="searchInput.autoFocus" :focus="searchInput.autoFocus"
:disabled="searchInput.disabled" :disabled="searchInput.disabled"
:style="{color:searchInput.color}" :style="{color:searchInput.color}"
:placeholder-style="`color:${searchInput.placeholderColor}`" :placeholder-style="`color:${searchInput.placeholderColor}`"
class="uni-page-head-search-input" class="uni-page-head-search-input"
confirm-type="search" confirm-type="search"
@focus="_focus" @focus="_focus"
@blur="_blur" @blur="_blur"
@update:value="_input" @update:value="_input"
/> />
<i
v-if="text"
class="uni-icon-clear"
@click="_clearInput"
>&#xea0f;</i>
</div> </div>
<div class="uni-page-head-ft"> <div class="uni-page-head-ft">
<template v-for="(btn,index) in btns"> <template v-for="(btn,index) in btns">
<div <div
v-if="btn.float !== 'left'" v-if="btn.float !== 'left'"
:key="index" :key="index"
:style="{backgroundColor: type==='transparent'?btn.background:'transparent',width:btn.width}" :style="{backgroundColor: type==='transparent'?btn.background:'transparent',width:btn.width}"
:badge-text="btn.badgeText" :badge-text="btn.badgeText"
:class="{'uni-page-head-btn-red-dot':btn.redDot||btn.badgeText,'uni-page-head-btn-select':btn.select}" :class="{'uni-page-head-btn-red-dot':btn.redDot||btn.badgeText,'uni-page-head-btn-select':btn.select}"
class="uni-page-head-btn" class="uni-page-head-btn"
> >
<i <i
:style="_formatBtnStyle(btn)" :style="_formatBtnStyle(btn)"
class="uni-btn-icon" class="uni-btn-icon"
@click="_onBtnClick(index)" @click="_onBtnClick(index)"
v-html="_formatBtnFontText(btn)" v-html="_formatBtnFontText(btn)"
/> />
</div> </div>
</template> </template>
</div> </div>
</div> </div>
<div <div
v-if="type!=='transparent'&&type!=='float'" v-if="type!=='transparent'&&type!=='float'"
:class="{'uni-placeholder-titlePenetrate': titlePenetrate}" :class="{'uni-placeholder-titlePenetrate': titlePenetrate}"
class="uni-placeholder" class="uni-placeholder"
/> />
</uni-page-head> </uni-page-head>
</template> </template>
...@@ -346,6 +351,11 @@ ...@@ -346,6 +351,11 @@
uni-page-head .uni-page-head-shadow-yellow::after { uni-page-head .uni-page-head-shadow-yellow::after {
background-image: url("https://cdn.dcloud.net.cn/img/shadow-yellow.png"); background-image: url("https://cdn.dcloud.net.cn/img/shadow-yellow.png");
} }
uni-page-head .uni-icon-clear {
align-self: center;
padding-right: 5px;
}
</style> </style>
<script> <script>
import appendCss from 'uni-platform/helpers/append-css' import appendCss from 'uni-platform/helpers/append-css'
...@@ -441,7 +451,8 @@ export default { ...@@ -441,7 +451,8 @@ export default {
return { return {
focus: false, focus: false,
text: '', text: '',
composing: false composing: false,
showPlaceholder: false
} }
}, },
computed: { computed: {
...@@ -496,6 +507,9 @@ export default { ...@@ -496,6 +507,9 @@ export default {
input.$watch('composing', val => { input.$watch('composing', val => {
this.composing = val this.composing = val
}) })
input.$watch('valueSync', val => {
this.showPlaceholder = !!val
})
if (this.searchInput.disabled) { if (this.searchInput.disabled) {
input.$el.addEventListener('click', () => { input.$el.addEventListener('click', () => {
UniServiceJSBridge.emit('onNavigationBarSearchInputClicked', '') UniServiceJSBridge.emit('onNavigationBarSearchInputClicked', '')
...@@ -567,7 +581,11 @@ export default { ...@@ -567,7 +581,11 @@ export default {
UniServiceJSBridge.emit('onNavigationBarSearchInputChanged', { UniServiceJSBridge.emit('onNavigationBarSearchInputChanged', {
text text
}) })
},
_clearInput () {
this.text = ''
this._input(this.text)
} }
} }
} }
</script> </script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册