| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <template>
- <view class="search-container">
- <view class="search-header">
- <u-search placeholder="搜索感兴趣的直播/视频" v-model="keyword" :show-action="true" action-text="搜索" @custom="onSearch" @search="onSearch"></u-search>
- </view>
-
- <view class="content-box">
- <view class="section" v-if="historyList.length > 0 && !isSearching">
- <view class="section-header">
- <text class="title">历史搜索</text>
- <u-icon name="trash" size="20" color="#999" @click="clearHistory"></u-icon>
- </view>
- <view class="tag-wrap">
- <view class="tag-item" v-for="(item, index) in historyList" :key="index" @click="onTagClick(item)">{{item}}</view>
- </view>
- </view>
-
- <view class="section" v-if="!isSearching">
- <view class="section-header">
- <text class="title">热门搜索</text>
- </view>
- <view class="tag-wrap">
- <view class="tag-item hot" v-for="(item, index) in hotList" :key="index" @click="onTagClick(item)">{{item}}</view>
- </view>
- </view>
-
- <view class="result-list" v-if="isSearching">
- <view class="result-item" v-for="(item, index) in resultList" :key="index" @click="goDetail(item)">
- <view class="left-icon">
- <u-icon name="play-circle-fill" color="#2583EB" size="24"></u-icon>
- </view>
- <view class="info">
- <text class="name">{{item.title}}</text>
- <text class="desc">{{item.desc}}</text>
- </view>
- </view>
- <u-empty v-if="resultList.length === 0" mode="search" text="暂无搜索结果"></u-empty>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- keyword: '',
- historyList: ['中医养生', '瑜伽入门', '糖尿病饮食'],
- hotList: ['高血压调理', '春季护肝', '八段锦教学', '名医讲座'],
- resultList: [],
- isSearching: false
- }
- },
- methods: {
- onSearch(val) {
- if (!val) return;
- this.keyword = val;
- this.isSearching = true;
- this.saveHistory(val);
-
- // Mock search logic
- setTimeout(() => {
- this.resultList = [
- { id: 1, title: val + ' - 相关直播回放', desc: '张医生讲解核心要点', type: 'video' },
- { id: 2, title: val + ' - 进阶课程', desc: '系统性学习方案', type: 'course' },
- { id: 3, title: '如何做好' + val, desc: '日常生活中需要注意的事项', type: 'article' }
- ];
- }, 500);
- },
- onTagClick(text) {
- this.keyword = text;
- this.onSearch(text);
- },
- clearHistory() {
- this.historyList = [];
- },
- saveHistory(val) {
- if (!this.historyList.includes(val)) {
- this.historyList.unshift(val);
- if (this.historyList.length > 10) this.historyList.pop();
- }
- },
- goDetail(item) {
- uni.navigateTo({
- url: '/pages/course/video/liveDetail?id=' + item.id
- });
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .search-container {
- min-height: 100vh;
- background-color: #fff;
- }
-
- .search-header {
- padding: 20rpx 30rpx;
- background-color: #fff;
- border-bottom: 1rpx solid #f5f5f5;
- }
-
- .content-box {
- padding: 30rpx;
- }
-
- .section {
- margin-bottom: 40rpx;
-
- .section-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20rpx;
-
- .title {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- }
- }
-
- .tag-wrap {
- display: flex;
- flex-wrap: wrap;
-
- .tag-item {
- padding: 10rpx 24rpx;
- background-color: #f5f7fa;
- border-radius: 30rpx;
- font-size: 26rpx;
- color: #666;
- margin-right: 20rpx;
- margin-bottom: 20rpx;
-
- &.hot {
- color: #2583EB;
- background-color: rgba(37, 131, 235, 0.1);
- }
- }
- }
- }
-
- .result-list {
- .result-item {
- display: flex;
- padding: 20rpx 0;
- border-bottom: 1rpx solid #f9f9f9;
-
- .left-icon {
- margin-right: 20rpx;
- display: flex;
- align-items: center;
- }
-
- .info {
- flex: 1;
- display: flex;
- flex-direction: column;
-
- .name {
- font-size: 30rpx;
- color: #333;
- margin-bottom: 8rpx;
- }
-
- .desc {
- font-size: 24rpx;
- color: #999;
- }
- }
- }
- }
- </style>
|