fourPayProject/51uni/homePages/Headline/Headline.vue
2025-03-31 10:23:28 +08:00

155 lines
2.8 KiB
Vue

<template>
<view class="content">
<view class="container">
<headers :titles="titles"><uni-icons type="arrow-left" color="#fff" size="22px"></uni-icons></headers>
<view class="box-" v-for="item in dataList">
<view class="img-box" @click="goDetail(item.id)">
<image :src="item.cover" mode="aspectFill"></image>
<view class="title-box">{{item.title}}</view>
</view>
<view class="bottom-box">{{item.describeStr}}</view>
</view>
<u-loadmore :status="status" v-if="show == true" />
</view>
</view>
</template>
<script>
import headers from '../../components/header/headers.vue'
import tabbar from '../../components/tabbar/tabbar.vue'
import request from '../../utils/request.js'
export default {
data() {
return {
titles: "今日头条",
msg: "1",
dataList: [],
show: false,
status: 'loading',
page: 1,
limit: 10,
totalPage: 0,
}
},
onShow() {
this.dataList = []
this.page = 1
this.getDataList()
},
onPullDownRefresh() {
this.page = 1,
this.limit = 10,
this.totalPage = 0,
this.dataList = [],
this.getDataList();
uni.stopPullDownRefresh()
},
onReachBottom() {
// 触底加载
if (this.page < this.totalPage) {
this.page++
this.getDataList()
} else {
uni.showToast({
title: '没有下一页数据',
icon: 'none'
})
}
},
components: {
headers,
tabbar
},
methods: {
goDetail(id) {
uni.navigateTo({
url: '/homePages/Headline/HeadDetail?id=' + id
})
},
getDataList() {
uni.showLoading({
title: '加载中'
});
request({
url: 'app/Headlines/list',
method: 'post',
data: {
limit: this.limit,
page: this.page
},
}).then(res => {
if (res.data) {
if (this.page != 1) {
this.dataList = this.dataList.concat(res.data)
} else {
this.dataList = res.data
}
this.totalPage = res.pages
}
}).finally(rrr => {
uni.hideLoading()
})
},
goback() {
uni.navigateBack()
}
}
}
</script>
<style scoped lang="scss">
.content {
background: #f4f5f6;
height: 100vh;
}
.container {
width: 100%;
background: #f4f5f6;
box-sizing: border-box;
padding-top: 88px;
}
.box- {
width: 95%;
margin: 10px auto;
border-radius: 8px;
background: #fff;
overflow: hidden;
}
.bottom-box {
box-sizing: border-box;
padding: 5px;
}
.img-box {
width: 100%;
height: 140px;
position: relative;
overflow: hidden;
image {
width: 100%;
height: 100%;
}
}
.title-box {
position: absolute;
width: 100%;
background-color: rgba(0, 0, 0, 0.6);
color: #fff;
height: 30px;
bottom: 0px;
display: flex;
align-items: center;
box-sizing: border-box;
padding: 0px 5px;
}
</style>