优化全局下拉刷新
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
<template>
|
||||
<view class="contentStyle">
|
||||
<view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
|
||||
<uni-nav-bar title="巡检记录" backgroundColor="transparent" :border="false" left-icon="left" @click-left="goBack" />
|
||||
<view class="content-wrap">
|
||||
<!-- 时间选择器 -->
|
||||
<view class="timebox">
|
||||
@@ -18,7 +16,7 @@
|
||||
</view>
|
||||
</view>
|
||||
<!-- 巡检列表 -->
|
||||
<scroll-view scroll-y class="scroll-view">
|
||||
<view class="scroll-view">
|
||||
<view class="list-container" v-if="listData.length > 0">
|
||||
<view class="card-item" v-for="(item, index) in listData" :key="index" @click="goToInspectionDetail(item)">
|
||||
<view class="card-head">
|
||||
@@ -35,7 +33,7 @@
|
||||
<uni-icons type="info" size="30" color="#ccc"></uni-icons>
|
||||
<text class="empty-text">暂无数据</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
@@ -111,14 +109,11 @@
|
||||
// ---------- 日期变更(使用 moment) ----------
|
||||
const handleChangeTime = (e) => {
|
||||
if (e) {
|
||||
// e 格式为 YYYY-MM-DD,用 moment 解析并格式化为 MM-DD
|
||||
showDate.value = moment(e).format('MM-DD')
|
||||
datetime.value = e
|
||||
} else {
|
||||
// 用户清空日期,可根据业务设置默认值或置空
|
||||
showDate.value = '选择日期'
|
||||
datetime.value = ''
|
||||
// 如果希望清空时不请求,可 return,否则也重置列表
|
||||
}
|
||||
// 重置分页并刷新
|
||||
pageNum.value = 1
|
||||
@@ -140,11 +135,6 @@
|
||||
fetchList(true)
|
||||
})
|
||||
|
||||
// ---------- 返回 ----------
|
||||
const goBack = () => {
|
||||
uni.navigateBack()
|
||||
}
|
||||
|
||||
// ---------- 页面返回拦截 ----------
|
||||
onBackPress(() => {
|
||||
const pages = getCurrentPages()
|
||||
@@ -165,9 +155,9 @@
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.contentStyle {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
// display: flex;
|
||||
// flex-direction: column;
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(to left bottom, #e2efff 0%, #f9f9f9 50%);
|
||||
}
|
||||
|
||||
@@ -180,11 +170,6 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.status-bar {
|
||||
width: 100%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.timebox {
|
||||
width: 188rpx;
|
||||
height: 48rpx;
|
||||
@@ -249,10 +234,10 @@
|
||||
}
|
||||
}
|
||||
//滚动容器 App重点:高度自适应 \*/
|
||||
.scroll-view {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
}
|
||||
// .scroll-view {
|
||||
// flex: 1;
|
||||
// height: 0;
|
||||
// }
|
||||
.list-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -1,20 +1,8 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
|
||||
<!-- 滚动区域 -->
|
||||
<pull-refresh-scroll
|
||||
custom-class="scroll-box"
|
||||
:refreshing="refreshing"
|
||||
:loading-more="loadingMore"
|
||||
:no-more-data="noMoreData"
|
||||
:empty="revenueList.length === 0 && !loading"
|
||||
empty-text="暂无通知"
|
||||
no-more-text="没有更多通知了"
|
||||
@refresh="onRefresh"
|
||||
@load-more="loadMore"
|
||||
>
|
||||
<view class="list-wrap">
|
||||
<!-- 列表 -->
|
||||
<!-- 列表 -->
|
||||
<view class="list-wrap">
|
||||
<view
|
||||
v-for="revenue in revenueList"
|
||||
:key="revenue.noticeId"
|
||||
@@ -30,18 +18,16 @@
|
||||
<uni-icons type="right" size="13" color="#007AFF"/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</pull-refresh-scroll>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { onLoad ,onShow,onUnload} from '@dcloudio/uni-app'
|
||||
import { onLoad, onShow, onUnload, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||
import { getRevenueList } from '../api/apiSub.js'
|
||||
|
||||
const revenueList = ref([])
|
||||
const refreshing = ref(false)
|
||||
const loadingMore = ref(false)
|
||||
const noMoreData = ref(false)
|
||||
const loading = ref(false)
|
||||
@@ -73,8 +59,8 @@ const loadRevenue = async (isRefresh = false) => {
|
||||
} catch (e) {}
|
||||
finally {
|
||||
loading.value = false
|
||||
refreshing.value = false
|
||||
loadingMore.value = false
|
||||
uni.stopPullDownRefresh()
|
||||
}
|
||||
}
|
||||
// 更新单条已读状态
|
||||
@@ -93,10 +79,13 @@ onShow(() =>{
|
||||
loadRevenue(true)
|
||||
})
|
||||
|
||||
const onRefresh = () => {
|
||||
refreshing.value = true
|
||||
onPullDownRefresh(() => {
|
||||
loadRevenue(true)
|
||||
}
|
||||
})
|
||||
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
const loadMore = () => {
|
||||
if (noMoreData.value || loadingMore.value) return
|
||||
@@ -123,21 +112,7 @@ page {
|
||||
background: #f9f9f9;
|
||||
}
|
||||
.page {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.status_bar {
|
||||
width: 100%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.scroll-box {
|
||||
flex: 1;
|
||||
height: 0; /* 让滚动区域生效 */
|
||||
min-height: 100vh;
|
||||
}
|
||||
.list-wrap {
|
||||
padding: 50rpx 40rpx;
|
||||
|
||||
Reference in New Issue
Block a user