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

新增:首页新闻列表可见新闻图片,并完善了样式。
This commit is contained in:
link_1999 2022-04-06 20:21:47 +08:00
parent d8a983aaeb
commit 9cff70c1ef
3 changed files with 88 additions and 21 deletions

View File

@ -7,8 +7,9 @@ Page({
{ title: "上海今日全市进行抗原检测 明日全市进行核酸检测" },
{ title: "苏州发现奥密克戎新变异株 与全球已知毒株均不同源" },
{ title: "美工作组抵华 参与东航事故调查" },
{ title: "上海昨日新增本土确诊425例、无症状8581例" },
],
list: [],
news_list: [],
},
onLoad: function (options) {
// 获取轮播图数据
@ -37,14 +38,14 @@ Page({
wx.showLoading({
title: '加载中...',
})
let len = this.data.list.length
let len = this.data.news_list.length
console.log('当前list长度', len)
wx.cloud.database().collection('neidi-news')
.skip(len)
.get()
.then(res => {
wx.hideLoading()
// console.log('请求成功', res)
console.log('新闻列表请求成功:', res)
let datalist = res.data
if (datalist.length <= 0) {
wx.showToast({
@ -53,11 +54,12 @@ Page({
})
}
this.setData({
list: this.data.list.concat(res.data)
news_list: this.data.news_list.concat(res.data),
news_image: res.data.news_img,
})
})
.catch(res => {
console.log('请求失败', res)
console.log('新闻列表请求失败', res)
})
},
/**

View File

@ -1,6 +1,6 @@
<!-- 轮播公告 -->
<view class="swiper-view">
<swiper class="swiper_container" vertical="true" autoplay="true" circular="true" interval="5000">
<swiper class="swiper_container" vertical="true" autoplay="true" circular="true" interval="3000">
<block wx:for="{{msgList}}" wx:key="index">
<swiper-item>
<view class="swiper-title">{{item.title}}</view>
@ -8,6 +8,15 @@
</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>
</scroll-view>
<!-- 顶部轮播图 -->
<view class="lunbotuBlock">
<swiper indicator-dots indicator-color="gray" indicator-active-color="white" circular autoplay interval="5000">
@ -17,12 +26,25 @@
</swiper>
</view>
<!-- 新闻列表 -->
<block>
<view wx:for="{{list}}" class="newsItem" bindtap="gotoDetail" data-id="{{item._id}}" wx:key="index">
<view wx:if="{{news_image}}" data-id="{{item._id}}">
<image src="{{news_image}}"></image>
<view class="news-list">
<!-- 每篇新闻框 -->
<view class="newsItem" wx:for="{{news_list}}" wx:key="_id">
<!-- 标题框(图片和文字) -->
<view class="pic-words">
<view wx:if="{{item.news_img}}">
<image class="news_image" src="{{item.news_img}}"></image>
</view>
<view class="news_title">{{item.news_title}}</view>
<view class="news_date">{{item.news_date}}----------{{item.news_author}}</view>
<view class="news_title .title-words" bindtap="gotoDetail" data-id="{{item._id}}">{{item.news_title}}</view>
</view>
<!-- 发布单位与发布时间 -->
<view class="publish">
<view class="publisher">{{item.news_author}}</view>
<view class="create-time">{{item.news_date}}</view>
</view>
</view>
</view>
</block>

View File

@ -30,19 +30,62 @@ swiper image {
align-items: center;
color: white
}
/* 新闻板块导航栏 */
.types {
width: 100%;
height: auto;
white-space: nowrap;
border-bottom: 1px solid;
border-bottom-color: black;
background-color: rgba(153, 151, 151, 0.151);
}
.type-item {
font-size: 18px;
width: rpx;
display: inline-block;
margin: 10rpx 20rpx;
}
/* 新闻列表 */
.news-list {
background-color: rgba(128, 128, 128, 0.137);
}
.newsItem {
border: 1px solid black;
margin: 20rpx;
height: 150rpx;
background-color: white;
padding: 30rpx 30rpx 30rpx 30rpx;
}
/* 新闻图片 */
.news_image {
width: 250rpx;
height: 175rpx;
}
/* 新闻标题 */
.news_title {
font-size: larger;
font-size: 20px;
margin-left: 15rpx;
}
.news_date {
font-size: small;
/* 发布单位 */
.publish {
display: flex;
flex-direction: row;
font-size: 14px;
color: grey;
margin-top: 10rpx;
border-bottom: 1px solid;
border-bottom-color: rgb(163, 147, 147);
}
/* 发布时间 */
.create-time {
margin-left: 30rpx;
margin-bottom: 20rpx;
}
/* 标题图文框 */
.pic-words {
display: flex;
flex-direction: row;
}
/* 标题 */
.title-words {
width: 500rpx;
}