123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <template>
- <scroll-view style="height:100%" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="triggered"
- @scrolltolower="scrolltolower" @refresherrefresh="onRefresh" refresher-default-style="black">
- <view class="infoBox" v-for="item in infoList" :key="item" @click="goDetail(item)">
- <view class="title">{{item.title}}</view>
- <view class="info">
- <view class="leftBox">
- <view class="content">
- {{item.content}}
- </view>
- <view class="attentionSituation">
- <view class="collectCount">
- <i class="custom-icon custom-icon-collected"></i>
- 2145
- </view>
- <!-- <view class="commentCount">
- <i class="custom-icon custom-icon-comment"></i>
- 543
- </view> -->
- <view class="time">
- {{item.updateTime ? formatDate(Date.parse(item.updateTime)): ""}}
- </view>
- </view>
- </view>
- <!-- <image src="@/static/1.png" alt="图片走丢啦" /> -->
- </view>
- </view>
- </scroll-view>
- </template>
- <script>
- import { getInfoList } from '@/api/info.js'
- import { formatDate } from '@/utils/util.js'
- export default {
- data() {
- return {
- loadingStatus: 'loadmore', // 上拉loading
- triggered: false, // 下拉是否激活
- infoList: [],
- total: 0,
- pageNum: 1,
- pageSize: 10,
- isRequesting: false, // 是否正在请求,如果是则返回,用于节流
- infoParams: {
- pageNum: 1,
- pageSize: 10,
- checkStatus: '5', // 已发布的数据
- },
- };
- },
- methods: {
- // 上拉加载
- scrolltolower() {
- if (this.infoList.length < this.total) {
- this.pageNum += 1;
- // 继续请求下一页,记得保留原先数组
- this.getList();
- } else {
- uni.showToast({
- title: "没有更多了",
- icon: "none",
- duration: 2000,
- });
- return;
- }
- },
- // 自定义下拉刷新被触发
- onRefresh() {
- // 开启下拉自定义样式
- this.triggered = true;
- // 重新调用
- this.getList();
- // 1秒之后复位
- setTimeout(() => {
- this.triggered = false;
- }, 1000);
- },
- getList(params={}) {
- this.isRequesting = true
- getInfoList({
- ...this.infoParams,
- ...params
- }).then(res => {
- // console.log("res:", res)
- this.infoList = [...this.infoList, ...res.rows]
- // console.log('infoList', this.infoList)
- this.total = res.total
- this.loadingStatus = this.infoList.length >= this.total ? 'nomore' : 'loading'
- }).finally(() => this.isRequesting = false)
- },
- // 点击资讯跳转详情
- goDetail(val) {
- console.log('跳转')
- uni.navigateTo({
- url: '/pages/index/detail'
- });
- },
- }
- }
- </script>
- <style lang="scss">
- .infoBox {
- width: 96%;
- background-color: #fff;
- padding: 20rpx;
- height: 260rpx;
- margin: 0 auto;
- margin-top: 20rpx;
- border-radius: 24rpx;
- box-shadow: 0 0 10rpx 6rpx rgba(0, 0, 0, 0.1);
- color: #666;
- .title {
- font-size: 32rpx;
- font-weight: 600;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- height: 26%;
- }
- .info {
- width: 100%;
- height: 74%;
- display: flex;
- // align-items: center;
- image {
- width: 160rpx;
- height: 160rpx;
- border-radius: 10rpx;
- }
- .leftBox {
- flex: 1;
- // width: 66%;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- .content {
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 3;
- -webkit-box-orient: vertical;
- }
- .attentionSituation {
- font-size: 24rpx;
- display: flex;
- align-items: center;
- .collectCount,
- .commentCount {
- display: flex;
- align-items: center;
- }
- .custom-icon {
- margin-right: 10rpx;
- &::before {
- background: -webkit-linear-gradient(left, #f84a1a, #ffa53e);
- -webkit-background-clip: text;
- -webkit-text-fill-color: transparent;
- font-weight: bold;
- }
- }
- .commentCount {
- margin: 0 30rpx;
- }
- .time {
- color: #aaa;
- }
- }
- }
- }
- }
- </style>
|