tj
2025-05-30 d9a780fa538cb7a83aefa04e75cb53185d690d7d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<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>