新增新闻搜索
This commit is contained in:
parent
2764e33d03
commit
62dfc9109a
|
|
@ -116,7 +116,9 @@ const queryList = (pageNo, pageSize) => {
|
|||
|
||||
// 添加刷新数据方法
|
||||
const refresh = () => {
|
||||
console.log("refreshrefreshrefreshrefresh");
|
||||
if (paging.value) {
|
||||
console.log("refreshrefreshrefreshrefresh");
|
||||
paging.value.reload();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@
|
|||
<text>{{ publish_time }}</text>
|
||||
</view>
|
||||
<view class="news-details__time-right">
|
||||
<image :src="follow_image" mode="aspectFill" style="width:36rpx; height:36rpx;" @click="onFollow"></image>
|
||||
<image :src="follow_image" mode="aspectFill" style="width:36rpx; height:36rpx;"
|
||||
@click="onFollow"></image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="news-details__content">
|
||||
|
|
@ -79,7 +80,6 @@ export default {
|
|||
}
|
||||
},
|
||||
async onLoad(options) {
|
||||
console.log("optionsoptionsoptionsoptions", options);
|
||||
this.options = options;
|
||||
this.title = "";
|
||||
this.getNewsDetail(options.id, options.current);
|
||||
|
|
@ -87,6 +87,10 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
async onFollow() {
|
||||
if (!yds.userInfo.isAccountLogin()) {
|
||||
yds.showToast("请登录后在收藏!");
|
||||
return;
|
||||
}
|
||||
this.follow = !this.follow;
|
||||
if (this.follow) {
|
||||
await addFavorite(this.options.id);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<z-paging-swiper>
|
||||
<template #top>
|
||||
<view class="" style="width: 100%; height: 225.19rpx; background-color: white; position: relative;">
|
||||
|
||||
<view class="tab">
|
||||
<view class="tab-item" v-for="(item, i) in tabList" :key="i" :class="current == i ? 'act' : 'unact'"
|
||||
@click="tabChange(i)">
|
||||
|
|
@ -12,6 +13,15 @@
|
|||
</template>
|
||||
<swiper class="swiper" :current="current" @animationfinish="swiperAnimationfinish">
|
||||
<swiper-item class="swiper-item" v-for="(item, index) in tabList" :key="index">
|
||||
<view class="search-container">
|
||||
<view class="search">
|
||||
<text class="iconfont icon-search" style="margin-right: 10rpx; color: #999;"></text>
|
||||
<input type="text" v-model="searchKeywords[index]" placeholder="搜索" confirm-type="search"
|
||||
@confirm="() => onSearch(index)" />
|
||||
<text class="iconfont icon-close" v-if="searchKeywords[index]" @click="() => clearSearch(index)"
|
||||
style="margin-left: 10rpx; color: #999;"></text>
|
||||
</view>
|
||||
</view>
|
||||
<news-list-item @clickItem="onClickItem" :responseCallback="queryList" ref="listItem" :tabIndex="index"
|
||||
:currentIndex="current">
|
||||
</news-list-item>
|
||||
|
|
@ -28,18 +38,20 @@ import { navigateTo } from '@/common/system/router'
|
|||
const tabList = ref(["热榜", "精选", "关注"])
|
||||
const current = ref(1); // tabs组件的current值,表示当前活动的tab选项
|
||||
const listItem = ref(null);
|
||||
// 为每个标签页创建独立的搜索关键词
|
||||
const searchKeywords = ref(['', '', '']);
|
||||
|
||||
//加载数据
|
||||
const queryList = async (params) => {
|
||||
let { pageNo, pageSize, type } = params;
|
||||
console.log("type", type);
|
||||
if (type == 0) {
|
||||
const res = await getHotNewsList(pageNo, pageSize);
|
||||
const res = await getHotNewsList(pageNo, pageSize, searchKeywords.value[0]);
|
||||
return res;
|
||||
} else if (type == 1) {
|
||||
const res = await getFeaturedNewsList(pageNo, pageSize);
|
||||
const res = await getFeaturedNewsList(pageNo, pageSize, searchKeywords.value[1]);
|
||||
return res;
|
||||
} else if (type == 2) {
|
||||
const res = await getFollowNewsList(pageNo, pageSize);
|
||||
const res = await getFollowNewsList(pageNo, pageSize, searchKeywords.value[2]);
|
||||
return res;
|
||||
}
|
||||
return { list: [] };
|
||||
|
|
@ -58,7 +70,18 @@ const swiperAnimationfinish = (e) => {
|
|||
};
|
||||
// 如果要通知当前展示的z-paging刷新,请调用此方法
|
||||
const reloadCurrentList = () => {
|
||||
listItem.value[current.value].reset();
|
||||
listItem.value[current.value].refresh();
|
||||
};
|
||||
const onSearch = (index) => {
|
||||
// 实现搜索功能
|
||||
console.log('搜索关键词:', searchKeywords.value[index]);
|
||||
// 刷新当前列表
|
||||
reloadCurrentList();
|
||||
};
|
||||
const clearSearch = (index) => {
|
||||
searchKeywords.value[index] = '';
|
||||
// 清空搜索词后重新加载数据
|
||||
reloadCurrentList();
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
@ -67,14 +90,27 @@ const reloadCurrentList = () => {
|
|||
height: 100%;
|
||||
}
|
||||
|
||||
.search-container {
|
||||
padding: 20rpx;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.search {
|
||||
height: 50rpx;
|
||||
height: 70rpx;
|
||||
background-color: #F7F7F7;
|
||||
border-radius: 10rpx;
|
||||
border-radius: 35rpx;
|
||||
padding: 0 20rpx;
|
||||
margin: 0 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
|
||||
input {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.tab {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user