| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <template>
- <view class="container">
- <!-- 分段器区域 -->
- <common-controlTag :tagList="tagList" rangekey="name" type="between" @change="handleChange"></common-controlTag>
- <!-- 列表区域 -->
- <view class="list">
- <!-- 每一条新闻区域 -->
- <view class="list_box" v-for="item in dataList" :key="item.id" @click="clickItem(item)">
- <image class="img" src="@/static/images/10.png" mode="aspectFill"></image>
- <view class="box_info">
- <view class="info_title">{{ item.theme }}</view>
- <view class="">{{ dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss') }}</view>
- </view>
- </view>
- </view>
- <!-- 没有数据时展示的页面 -->
- <noData v-if="!dataList.length"></noData>
- </view>
- </template>
- <script setup>
- import { onLoad, onReachBottom } from '@dcloudio/uni-app'
- import { ref } from 'vue'
- import { getCategoryNewss, getNewsByCategoryId } from '@/api/index.js'
- import dayjs from 'dayjs'
- // 分段器数组
- const tagList = ref([])
- // 分段器当前索引
- const currentIndex = ref(0)
- // 当前页
- const currentPage = ref(1)
- // 每页多少条
- const pageCount = ref(6)
- // 总条数
- const total = ref(0)
- // 列表数据
- const dataList = ref([])
- onLoad(() => {
- // 获取新闻分类列表数据
- getCategory()
- })
- // 页面触底触发的回调
- onReachBottom(() => {
- if (total.value > dataList.value.length) {
- currentPage.value++
- getData()
- } else {
- uni.showToast({
- title: '没有更多数据了~~',
- icon: 'none'
- })
- }
- })
- // 获取新闻分类列表数据
- const getCategory = async () => {
- const res = await getCategoryNewss()
- // console.log(res)
- tagList.value = res.data
- // 获取新闻分页数据
- getData()
- }
- // 获取新闻分页数据
- const getData = async () => {
- let data = {
- currentPage: currentPage.value,
- pageCount: pageCount.value,
- categoryId: tagList.value[currentIndex.value].id
- }
- const res = await getNewsByCategoryId(data)
- // console.log(res)
- dataList.value = [...dataList.value, ...res.data.list]
- total.value = res.data.totalCount
- }
- // 分段器切换时的回调
- const handleChange = (e) => {
- if (currentIndex.value != e) {
- currentIndex.value = e
- currentPage.value = 1
- dataList.value = []
- getData()
- }
- }
- // 点击每一条新闻的回调
- const clickItem = (item) => {
- // console.log(item)
- let info = encodeURIComponent(JSON.stringify(item))
- uni.navigateTo({
- url: `/pages/news_detail/news_detail?info=${info}`
- })
- }
- </script>
- <style lang="scss" scoped>
- .container {
- padding: 20rpx 18rpx;
- min-height: 100vh;
- .list {
- margin-top: 20rpx;
- .list_box {
- display: flex;
- padding: 30rpx;
- margin-bottom: 20rpx;
- width: 714rpx;
- height: 234rpx;
- border-radius: 28rpx;
- box-shadow: 0 4rpx 34rpx rgba(211, 211, 211, 0.32);
- .img {
- margin-right: 24rpx;
- width: 249rpx;
- height: 168rpx;
- }
- .box_info {
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- flex: 1;
- font-size: 24rpx;
- color: #808080;
- .info_title {
- color: #000;
- font-size: 28rpx;
- font-weight: bold;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- overflow: hidden;
- }
- }
- }
- }
- }
- </style>
|