talk_appAmin/pages/search/index.vue

239 lines
5.5 KiB
Vue
Raw Normal View History

2024-05-09 12:19:48 +08:00
<template>
2024-05-28 10:34:28 +08:00
<view class="">
<!-- <u-navbar leftText=" " title="搜索" :placeholder="true" :safeAreaInsetTop="true" :bgColor="bgColor">
</u-navbar> -->
<view class="bgc"></view>
<!-- 搜索栏 -->
<view class="sousuoBox1 flex alignCenter justifyBetween">
<view class="sousuoBox flex alignCenter justifyBetween">
<view class="souBOx flex alignCenter justifyBetween" >
<image src="../static/images/icon/tu2-2.png" class="img3"></image>
<!-- <view class="shuruText">在食堂捡到一张饭卡</view> -->
<input v-model="keyword" @input="toContent" @confirm="onSearch" class="shuruText" :placeholder="placeholderText" type="text">
2024-05-07 21:28:47 +08:00
</view>
2024-05-28 10:34:28 +08:00
<image @click.stop="toScanCode" src="../static/images/icon/tu2-3.png" class="img4"></image>
2024-05-09 12:19:48 +08:00
</view>
2024-05-28 10:34:28 +08:00
<view class="category-dropdown flex alignCenter">
<text class="text1 flex alignCenter" @click="onSearch"></text>
<!-- <image src="../static/images/icon/tu2-1.png" class="img5 flex alignCenter"></image> -->
2024-05-09 12:19:48 +08:00
</view>
</view>
2024-05-28 10:34:28 +08:00
<!-- 搜索历史 -->
<view class="history" v-if="!noHistortOpen">
<view class="history-top">
<view class="history-title">搜索历史</view>
<image src="../static/images/icon/tu3-4.png" class="history-icon" @click="clearHistory"></image>
</view>
<view class="history-center">
<view v-for="(item, index) in historyList" :key="index" class="history-item">
<text @click="clickHistory(index)" class="history-item-text">{{ item }}</text>
</view>
</view>
</view>
<!-- 无内容 -->
<view v-else>
2024-05-09 12:19:48 +08:00
<view class="noContent">
2024-05-28 10:34:28 +08:00
<image src="../static/images/icon/tu4-9.png" class="img6"></image>
2024-05-09 12:19:48 +08:00
<view class="noContentText">没有找到相关内容奥,换个词试试吧!</view>
</view>
</view>
</view>
</template>
2024-05-28 10:34:28 +08:00
<script>
export default {
data() {
return {
keyword: '',
placeholderText: '在食堂捡到一张饭卡',
bgColor: 'rgba(170, 0, 0, 0)',
noHistortOpen: false,
historyList: ['钥匙丢了 111', '外卖丢了', 'U盘丢了', '我丢了', '丢']
}
},
onLoad() {
// 从缓存中读取历史记录
var hisList = JSON.parse(uni.getStorageSync('kw'));
if (hisList.length != 0) {
this.historyList=JSON.parse(uni.getStorageSync('kw'))
}
},
methods: {
clickHistory(index) {
console.log('触发')
this.keyword = this.historyList[index]
},
toContent() {
this.noHistortOpen = false
},
toScanCode() {
// 允许从相机和相册扫码
uni.scanCode({
success: function (res) {
console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result);
}
});
},
onSearch() {
console.log('搜索 ' + this.keyword)
//把搜索的关键字保存到historyList中
if (this.keyword == '') {
console.log('空的')
this.keyword = this.placeholderText;
}
this.saveHistory()
if(this.keyword == '在食堂捡到一张饭卡') {
this.noHistortOpen = true
}
},
// 保存历史记录
saveHistory(){
console.log('保存历史')
// if(this.historyList.indexOf(this.keyword)==-1){
this.historyList.unshift(this.keyword)
// 把用户输入的内容保存到历史记录当中
uni.setStorageSync('kw',JSON.stringify(this.historyList||'[]'))
// }
},
// 清空历史记录
clearHistory(){
this.historyList=[]
uni.setStorageSync('kw','[]')
// if(his.length==0){
// this.his=!this.his
// }
}
}
}
2024-05-09 12:19:48 +08:00
</script>
2024-05-07 21:28:47 +08:00
2024-05-28 10:34:28 +08:00
<style>
.bgc{
2024-05-09 12:19:48 +08:00
width: 750rpx;
2024-05-28 10:34:28 +08:00
height: 108rpx;
background: #FAF9FA;
2024-05-09 12:19:48 +08:00
position: fixed;
top: 0rpx;
left: 0rpx;
2024-05-28 10:34:28 +08:00
z-index: -1;
2024-05-09 12:19:48 +08:00
}
2024-05-28 10:34:28 +08:00
.sousuoBox1{
margin: 16rpx 32rpx;
2024-05-09 12:19:48 +08:00
width: auto;
2024-05-28 10:34:28 +08:00
}
.sousuoBox{
width: 580rpx;
2024-05-09 12:19:48 +08:00
height: 60rpx;
border: #B3D7FF solid 2rpx;
border-radius: 30rpx 30rpx 30rpx 30rpx;
2024-05-28 10:34:28 +08:00
background: #ffffff80;
}
.souBOx{
margin-left: 32rpx;
}
.img3{
width: 36rpx;
height: 36rpx;
}
.img4{
width: 36rpx;
height: 36rpx;
margin-right: 16rpx;
2024-05-09 12:19:48 +08:00
}
2024-05-28 10:34:28 +08:00
.category-dropdown {
margin-left: 42rpx;
}
.text1{
font-weight: 400;
width: 62rpx;
/* height: 32rpx; */
font-size: 30rpx;
text-align: left;
color: #1B1B1B;
}
.img5{
width: 26rpx;
height: 26rpx;
}
.shuruText{
font-weight: 400;
font-size: 28rpx;
text-align: left;
margin-left: 18rpx;
color: #333333;
flex-grow: 1; /* 让输入框占据剩余空间 */
width: 380rpx;
}
.history {
margin-top: 44rpx;
padding: 0 32rpx;
2024-05-09 12:19:48 +08:00
}
2024-05-28 10:34:28 +08:00
.history-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20rpx;
}
2024-05-09 12:19:48 +08:00
2024-05-28 10:34:28 +08:00
.history-title {
font-weight: 400;
width: 140rpx;
/* height: 36rpx; */
/* line-height: 36rpx; */
font-size: 34rpx;
text-align: left;
color: #1B1B1B;
}
2024-05-09 12:19:48 +08:00
2024-05-28 10:34:28 +08:00
.history-icon {
width: 42rpx;
height: 42rpx;
}
2024-05-09 12:19:48 +08:00
2024-05-28 10:34:28 +08:00
.history-center {
2024-05-09 12:19:48 +08:00
2024-05-28 10:34:28 +08:00
}
2024-05-09 12:19:48 +08:00
2024-05-28 10:34:28 +08:00
.history-item {
display: inline-block; /* 将 history-item 设置为行内块元素 */
margin: 10rpx 12rpx;
2024-05-09 12:19:48 +08:00
}
2024-05-28 10:34:28 +08:00
.history-item-text {
font-weight: 400;
/* width: 140rpx; */
/* height: 58rpx; */
/* line-height: 58rpx; */
/* width: 180rpx; */
font-size: 28rpx;
text-align: left;
color: #666666;
border-radius: 30rpx; /* 调整圆角 */
background: #f6f6f6;
display: flex; /* 使用 Flex 布局 */
align-items: center; /* 垂直居中 */
padding: 14rpx 20rpx; /* 添加内边距 */
}
2024-05-09 12:19:48 +08:00
2024-05-28 10:34:28 +08:00
.img6{
2024-05-09 12:19:48 +08:00
width: 326rpx;
height: 280rpx;
}
2024-05-28 10:34:28 +08:00
.noContent {
margin-top: 150rpx;
display: flex;
flex-direction: column;
align-items: center;
2024-05-09 12:19:48 +08:00
}
2024-05-28 10:34:28 +08:00
.noContentText{
font-weight: 400;
width: 490rpx;
height: 30rpx;
font-size: 30rpx;
text-align: center;
color: #333333;
}
2024-05-07 21:28:47 +08:00
</style>