GterForumWeB/src/components/SearchBox.vue

209 lines
4.7 KiB
Vue
Raw Normal View History

2023-03-28 18:04:49 +08:00
<template>
<div>
<div class="header-search" @click="searchClick">
<div class="header-search-img"></div>
<div class="header-search-text">搜索</div>
</div>
<!-- 搜索弹窗 -->
<div class="search-window" :class="{'searchShow':searchWinShow == true}">
<!-- 搜索框 -->
<div class="search-input">
<form action="javascript:return true;" @submit.prevent>
<div class="search-icon"></div>
<input ref="searchInput" v-model="searchText" type="search" placeholder="请输入搜索关键词"/>
<div v-if="showClear" class="clear-text" @click="clearText"></div>
</form>
<div class="search-close" @click="searchClose">取消</div>
</div>
<!-- 历史搜索 -->
<div class="search-content">
<div class="search-text">历史搜索</div>
<div class="search-label">
<span>香港大学</span>
<span>香港大学</span>
</div>
</div>
<!-- 热门搜索 -->
<div class="search-content">
<div class="search-text">热门搜索</div>
<div class="search-label">
<span>Bocconi</span>
<span>Bocconi</span>
<span>Bocconi</span>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "SearchBox",
data() {
return {
searchWinShow: false,//显示搜索弹窗
searchText: '',
showClear: false, //显示清除按钮
}
},
methods: {
// 点击显示搜索弹窗
searchClick() {
this.searchWinShow = true
this.$refs.searchInput.blur();
},
// 点击隐藏搜索弹窗
searchClose(){
this.searchWinShow = false
},
// 搜索键盘、搜索
search(categoryId) {
this.$refs.searchInput.blur();
},
// 清空文本框
clearText() {
if(this.searchText.length > 0) {
this.searchText = ""
}
}
},
mounted() {
if(this.searchText.length > 0) {
this.showClear = true
}else{
this.showClear = false
}
}
}
</script>
<style lang="scss" scoped>
// 搜索弹窗
.search-window{
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
min-height: 100vh;
background-color: #f6f6f6;
z-index: 9;
&.searchShow{
display: block;
}
.search-input{
padding: 0.27rem 0.32rem 0.27rem;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
.search-icon{
position: absolute;
top: 0.43rem;
left: 0.3rem;
width: 0.32rem;
height: 0.32rem;
background-size: contain;
background-image: url('@/assets/img/icon/search.png');
}
form{
width: 90%;
position: relative;
}
input{
width: 100%;
box-sizing: border-box;
text-align: left;
font-size: 0.36rem;
height: 1.12rem;
line-height: 1.12rem;
border-radius: 0.56rem;
background-color: #ebebeb;
border: none;
color: #000;
display: block;
outline: 0;
padding-left: 0.8rem;
padding-right: 0.9rem;
text-decoration: none;
&[type="search"]{-webkit-appearance:none;}
&::-webkit-search-cancel-button {display: none;}
&:placeholder-shown{
color: #aaa;
}
}
.clear-text{
width: 0.4rem;
height: 0.4rem;
position: absolute;
top: 0.35rem;
right: 0.3rem;
background-size: contain;
background-image: url('/src/assets/img/icon/clear.png');
}
.search-close{
width: 10%;
font-size: 0.36rem;
text-align: right;
}
}
.search-content{
padding: 0.27rem 0.32rem 0.27rem;
display: flex;
flex-direction: column;
margin-top: 0.2rem;
.search-text{
color: #7F7F7F;
font-size: 0.32rem;
margin-bottom: 0.13rem;
}
.search-label{
display: flex;
flex-direction: row;
flex-wrap: wrap;
span{
padding: 0 0.2rem;
height: 0.96rem;
line-height: 0.96rem;
background-color: #fff;
border-radius: 0.16rem;
color: #333;
text-align: center;
font-size: 0.36rem;
margin: 0.2rem 0.16rem 0 0;
}
}
}
}
.header-search {
width: 2.4rem;
height: 0.8rem;
line-height: 0.8rem;
border-radius: 2.56rem;
background-color: rgba(235, 235, 235, 1);
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
margin-right: 0.35rem;
.header-search-img {
width: 0.4rem;
height: 0.4rem;
background-size: contain;
margin: 0 0.133333rem 0 0;
background-image: url("@/assets/img/icon/search.png");
}
.header-search-text {
text-align: left;
font-size: 0.32rem;
color: #aaaaaa;
display: block;
}
}
</style>