<template>
|
<view class="search-page">
|
<!-- 搜索框 -->
|
<view class="search-bar">
|
<up-search v-model="searchValue" :placeholder="searchPlaceHolder" show-action @search="onSearch"
|
@custom="onSearch" @click-icon="onSearch" />
|
</view>
|
<!-- 历史记录 -->
|
<view class="section" v-if="historyTags.length">
|
<view class="section-title">
|
<text>历史记录</text>
|
<view v-if="!showCloseBtn"> <up-icon name="trash" size="20" @click="onClearHistory"
|
class="delete-icon" /></view>
|
<view v-else class="action-group">
|
<text class="action-btn" @click="onDeleteAll">全部删除</text>
|
<text class="action-btn" @click="onClearHistory">完成</text>
|
</view>
|
</view>
|
<view class="tag-list">
|
<!-- <up-tag v-for="(item, index) in historyTags" :key="index" plain size="mini" class="tag" shape="circle"
|
borderColor="#E9E9E9" color="#333333" textSize="20rpx">{{ item }}
|
<up-icon name="close" size="10" @click="handleDeleteHistoryOne(item, index)" />
|
</up-tag> -->
|
<view v-for="(item, index) in historyTags" :key="index" @click.stop class="tag2">
|
<view class="tag-text">{{ item }}</view>
|
<up-icon v-if="showCloseBtn" name="close" size="10"
|
@click.stop="handleDeleteHistoryOne(item, index)" />
|
</view>
|
</view>
|
</view>
|
|
<!-- 猜你想搜 -->
|
<view class="section">
|
<view class="section-title">
|
<text>猜你想搜</text>
|
<view class="icon-list">
|
<up-icon name="reload" size="20" @click="onClearHistory" />
|
<up-icon name="more-dot-fill" size="20" @click="onClearHistory" />
|
</view>
|
</view>
|
<view class="suggest-list">
|
<view class="suggest-column">
|
<text v-for="(item, index) in guessList.filter((_, i) => i % 2 === 0)" :key="'left-' + index"
|
class="suggest">
|
{{ item }}
|
</text>
|
</view>
|
<view class="suggest-column">
|
<text v-for="(item, index) in guessList.filter((_, i) => i % 2 === 1)" :key="'right-' + index"
|
class="suggest">
|
{{ item }}
|
</text>
|
</view>
|
</view>
|
</view>
|
|
<!-- 热门榜单 -->
|
<view class="section">
|
<view class="section-title hot-title">
|
🔥 热点
|
</view>
|
<view class="hot-list">
|
<view v-for="(item, index) in hotList" :key="index" class="hot-item">
|
<view>
|
<text class="hot-index" :class="[
|
index === 0 ? 'gradient-red' :
|
index === 1 ? 'gradient-orange' :
|
index === 2 ? 'gradient-yellow' : ''
|
]">{{ index + 1 }}</text>
|
<text class="hot-text">{{ item.title }}</text>
|
<up-tag v-if="item.tag"
|
:type="item.tag === '热' ? 'error' : item.tag === '荐' ? 'warning' : 'primary'" size="mini"
|
class="tag" >
|
{{ item.tag }}
|
</up-tag>
|
</view>
|
<text class="hot-views">{{ item.views }}</text>
|
</view>
|
</view>
|
</view>
|
|
|
<up-modal v-model:show="showModal" title="" showCancelButton confirmText="确定" cancelText="取消" @confirm="onConfirm">
|
<template #default>
|
<text style="color: red;">删除全部搜索历史</text>
|
</template>
|
</up-modal>
|
|
|
</view>
|
</template>
|
|
<script setup lang="ts">
|
import { handleError, ref } from 'vue'
|
import { onShow, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
import { useGlobal } from '@/composables/useGlobal'
|
const { $http, $message, $storage } = useGlobal()
|
|
import { getSearchHistory, addSearchHistory, clearSearchHistory, removeSearchHistoryByIndex } from '@/sub-pages/utils/storageKeys'
|
const searchValue = ref('')
|
const searchPlaceHolder = ref('新疆本地小团')
|
const historyTags = ref<string[]>([])
|
const showModal = ref(false)
|
|
|
const guessList = [
|
'新疆本地小团', '旺旺就是朱旺旺离职',
|
'新疆北疆路线攻略', '职称评审'
|
]
|
|
const hotList = [
|
{ title: '在最穷的时候遇上了最想买的皮肤', tag: '热', views: '922.3万' },
|
{ title: '陈奕迅辟谣去世传闻后首露面', views: '716万' },
|
{ title: '你不认识我们但一定见过我们画的猫', tag: '荐', views: '683.1万' },
|
{ title: '迪丽热巴 蓝玫瑰油画妆', tag: '热', views: '664.9万' },
|
{ title: '起猛了看到小狗的朋友圈了', views: '653万' },
|
{ title: '藏海传让我来演', tag: '荐', views: '652.9万' },
|
{ title: '郑晓龙拍戏 眼泪往上擦', tag: '热', views: '648万' },
|
{ title: '我的小红书被小乔包围了', tag: '独家', views: '612.3万' },
|
{ title: '小米15周年新品发布会', views: '605.5万' },
|
{ title: '你可能不认识汪 but 一定看过汪', tag: '荐', views: '603.5万' }
|
]
|
|
const onSearch = () => {
|
// 这里判断,如果输入的内容是空的话,那么将searchPlaceHolder的值赋值给searchValue
|
if (!searchValue.value) {
|
searchValue.value = searchPlaceHolder.value
|
}
|
addSearchHistory(searchValue.value)
|
historyTags.value = getSearchHistory()
|
searchValue.value = ''
|
console.log('搜索内容:', searchValue.value)
|
// TODO 跳转到搜索页面
|
|
}
|
const showCloseBtn = ref(false) // 控制按钮显示
|
const onClearHistory = () => {
|
showCloseBtn.value = !showCloseBtn.value
|
}
|
|
const onDeleteAll = () => {
|
showModal.value = true
|
}
|
|
const onConfirm = ()=>{
|
clearSearchHistory()
|
historyTags.value = getSearchHistory()
|
showModal.value = false
|
}
|
|
/**
|
* 删除一个 historyTags 中的项目
|
* @param item 列表项目
|
* @param index
|
*/
|
const handleDeleteHistoryOne = (item: String, index: Number) => {
|
removeSearchHistoryByIndex(index)
|
historyTags.value = getSearchHistory()
|
onClearHistory()
|
}
|
|
|
onShow(() => {
|
historyTags.value = getSearchHistory()
|
});
|
</script>
|
|
<style lang="scss" scoped>
|
.search-page {
|
padding: 20rpx;
|
|
.search-bar {
|
margin-bottom: 20rpx;
|
}
|
|
.section {
|
margin-top: 30rpx;
|
|
.section-title {
|
font-size: 28rpx;
|
font-weight: bold;
|
margin-bottom: 16rpx;
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
|
.delete-icon {
|
color: #999;
|
}
|
|
.icon-list {
|
display: flex;
|
gap: 10rpx;
|
color: #999;
|
}
|
|
.action-group {
|
display: flex;
|
gap: 24rpx;
|
/* 控制两个按钮之间的间距 */
|
|
.action-btn {
|
color: #999;
|
font-size: 24rpx;
|
}
|
}
|
|
|
}
|
|
.hot-title {
|
color: #f43f3b;
|
}
|
|
.tag-list {
|
display: flex;
|
flex-wrap: wrap;
|
gap: 10rpx;
|
|
.tag {
|
padding: 6rpx;
|
display: flex;
|
}
|
|
.tag2 {
|
display: inline-flex;
|
align-items: center;
|
border: 1px solid #E9E9E9;
|
border-radius: 50rpx;
|
/* 模拟 shape="circle" */
|
padding: 4rpx 10rpx;
|
font-size: 20rpx;
|
/* textSize */
|
color: #333333;
|
/* color */
|
margin: 6rpx;
|
background-color: transparent;
|
/* plain 样式 */
|
}
|
|
.tag-text {
|
margin-right: 6rpx;
|
}
|
}
|
|
.suggest-list {
|
display: flex;
|
flex-direction: row;
|
justify-content: space-between;
|
padding: 0 20rpx;
|
|
.suggest-column {
|
display: flex;
|
flex-direction: column;
|
gap: 20rpx; // 每行间距
|
|
.suggest {
|
font-size: 28rpx;
|
color: #333;
|
}
|
}
|
}
|
|
.hot-list {
|
.hot-item {
|
display: flex;
|
align-items: center;
|
margin-bottom: 20rpx;
|
justify-content: space-between;
|
|
|
.hot-index {
|
font-size: 30rpx;
|
font-weight: bold;
|
width: 40rpx;
|
}
|
|
.hot-text {
|
font-weight: bold;
|
font-size: 26rpx;
|
margin-left: 10rpx;
|
max-width: 400rpx;
|
display: inline-block;
|
vertical-align: middle;
|
white-space: nowrap;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
}
|
|
.gradient-red {
|
background: linear-gradient(to right, #f43f5e, #fb7185);
|
-webkit-background-clip: text;
|
color: transparent;
|
}
|
|
.gradient-orange {
|
background: linear-gradient(to right, #f97316, #facc15);
|
-webkit-background-clip: text;
|
color: transparent;
|
}
|
|
.gradient-yellow {
|
background: linear-gradient(to right, #fcd34d, #fde68a);
|
-webkit-background-clip: text;
|
color: transparent;
|
}
|
|
.tag {
|
margin-left: 10rpx;
|
font-size: 22rpx;
|
}
|
|
.hot-views {
|
margin-left: 10rpx;
|
font-size: 24rpx;
|
color: #999;
|
}
|
}
|
}
|
}
|
}
|
</style>
|