buddhism/components/search-box/search-box.vue

107 lines
2.0 KiB
Vue
Raw Normal View History

2025-07-31 17:13:56 +08:00
<template>
2025-09-17 14:57:31 +08:00
<view :style="{ width: width }" class="searchBox">
<image :src="searchIcon" class="search-icon" mode="aspectFit"></image>
2025-07-31 17:13:56 +08:00
<input
:placeholder="placeholder"
2025-09-17 14:57:31 +08:00
:value="value"
class="search-input"
confirm-type="search"
2025-07-31 17:13:56 +08:00
placeholder-class="search-placeholder"
@confirm="onSearch"
2025-09-17 14:57:31 +08:00
@input="onInput"
2025-07-31 17:13:56 +08:00
/>
<view class="search-btn" @click="onSearch">{{ btnText }}</view>
</view>
</template>
<script>
2025-09-17 14:57:31 +08:00
import CommonEnum from "@/enum/common.js";
export default {
name: "SearchBox",
props: {
value: {
type: String,
default: "",
2025-07-31 17:13:56 +08:00
},
2025-09-17 14:57:31 +08:00
width: {
type: String,
default: "690rpx",
2025-07-31 17:13:56 +08:00
},
2025-09-17 14:57:31 +08:00
placeholder: {
type: String,
default: "请输入高僧姓名",
},
btnText: {
type: String,
default: "搜索",
},
// 建议传递 CommonEnum.SEARCH 作为默认图标
searchIcon: {
type: String,
default: () => CommonEnum.SEARCH,
},
},
methods: {
onInput(e) {
// 只更新输入值,不触发搜索
this.$emit("input", e.detail.value);
},
onSearch() {
// 只在点击搜索按钮或按回车时触发搜索
if (this.value) {
this.$emit("search", this.value);
}
},
},
};
2025-07-31 17:13:56 +08:00
</script>
<style lang="scss" scoped>
2025-09-17 14:57:31 +08:00
.searchBox {
display: flex;
align-items: center;
height: 70rpx;
background: #fffbf5;
border-radius: 10rpx;
border: 1rpx solid #c7a26d;
margin-top: 20rpx;
margin-bottom: 20rpx;
padding: 0 12rpx;
}
.search-icon {
width: 32rpx;
height: 32rpx;
margin: 0 28rpx;
}
.search-input {
flex: 1;
font-size: 28rpx;
color: #333;
background: transparent;
border: none;
outline: none;
height: 100%;
}
.search-placeholder {
color: #bfa16b;
font-size: 28rpx;
}
.search-btn {
background: #bfa16b;
color: #fff;
font-size: 26rpx;
border-radius: 6rpx;
padding: 0 24rpx;
height: 48rpx;
display: flex;
align-items: center;
justify-content: center;
margin-left: 16rpx;
}
2025-08-14 11:22:53 +08:00
</style>