上传文件至 '新闻小程序/pages/home'

改进新闻详情页的跳转(新增:判断对应板块新闻应该查找那个数据库集合)
This commit is contained in:
link_1999 2022-04-07 18:52:18 +08:00
parent ee7f33c4c9
commit afcb73a2a4
3 changed files with 47 additions and 12 deletions

View File

@ -1,6 +1,8 @@
// pages/home/home.js
let newsType = 'neidi-news'
Page({
data: {
navState: 0,//导航状态
//存放轮播图数据的列表
lunboList: [],
msgList: [
@ -26,12 +28,32 @@ Page({
// 获取新闻列表数据
this.getList()
},
// 点击事件-去往详情页
gotoDetail(event) {
// console.log('用户点击的新闻id', event.currentTarget.dataset.id)
wx.navigateTo({
url: '/pages/news-detail/news-detail?id=' + event.currentTarget.dataset.id,
navSwitch(e) {
let index = e.currentTarget.dataset.index
this.setData({
navState: index,
})
if (index == 0) {
wx.navigateTo({
url: '/pages/home/home',
})
}else if (index == 1) {
wx.navigateTo({
url: '/pages/xg/xg',
})
}else if (index == 2) {
wx.navigateTo({
url: '/pages/tw/tw',
})
}else if (index == 3) {
wx.navigateTo({
url: '/pages/gj/gj',
})
}else if (index == 4) {
wx.navigateTo({
url: '/pages/junshi/junshi',
})
}
},
// 获取新闻列表数据
getList(page) {
@ -62,6 +84,14 @@ Page({
console.log('新闻列表请求失败', res)
})
},
// 点击事件-去往详情页
gotoDetail(event) {
// console.log('用户点击的新闻id', event.currentTarget.dataset.id)
wx.navigateTo({
url: '/pages/news-detail/news-detail?id=' + event.currentTarget.dataset.id + '&newsType=' + newsType,
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/

View File

@ -8,13 +8,14 @@
</block>
</swiper>
</view>
<!-- 新闻板块导航栏 -->
<scroll-view class="types" scroll-x="true">
<view class="type-item">内地新闻</view>
<view class="type-item">香港新闻</view>
<view class="type-item">台湾新闻</view>
<view class="type-item">国际新闻</view>
<view class="type-item">军事新闻</view>
<view class="type-item" bindtap="navSwitch" data-index="0"><view class="{{navState==0 ? 'item_sel_style' : ''}}">内地新闻</view></view>
<view class="type-item" bindtap="navSwitch" data-index="1"><view class="{{navState==1 ? 'item_sel_style' : ''}}">香港新闻</view></view>
<view class="type-item" bindtap="navSwitch" data-index="2"><view class="{{navState==2 ? 'item_sel_style' : ''}}">两岸新闻</view></view>
<view class="type-item" bindtap="navSwitch" data-index="3"><view class="{{navState==3 ? 'item_sel_style' : ''}}">国际新闻</view></view>
<view class="type-item" bindtap="navSwitch" data-index="4"><view class="{{navState==4 ? 'item_sel_style' : ''}}">军事新闻</view></view>
</scroll-view>
<!-- 顶部轮播图 -->

View File

@ -33,11 +33,11 @@ swiper image {
/* 新闻板块导航栏 */
.types {
width: 100%;
height: auto;
height: 34px;
white-space: nowrap;
border-bottom: 1px solid;
border-bottom-color: black;
background-color: rgba(153, 151, 151, 0.151);
background-color: snow;
}
.type-item {
font-size: 18px;
@ -45,6 +45,10 @@ swiper image {
display: inline-block;
margin: 10rpx 20rpx;
}
.item_sel_style {
background-color: #2b4b6b;
color: snow;
}
/* 新闻列表 */