页面滚动缓存

This commit is contained in:
bb_pan 2025-09-02 11:24:09 +08:00
parent 572fc475dc
commit c1da903faf
5 changed files with 86 additions and 27 deletions

View File

@ -1,12 +1,12 @@
<template>
<uni-nav-bar
status-bar
leftIcon="left"
title="退料任务"
backgroundColor="#dcf4ff"
:border="false"
fixed
@clickLeft="leftClick"
status-bar
leftIcon="left"
title="退料任务"
backgroundColor="#dcf4ff"
:border="false"
fixed
@clickLeft="leftClick"
/>
<!-- 退料任务 -->
<view class="page-container">
@ -58,7 +58,13 @@
<view class="addBtn" @click="goAdd()">新增</view>
</uni-col>
</uni-row>
<scroll-view scroll-y @scrolltolower="onScrollTolower" class="scroll-container">
<scroll-view
scroll-y
:scroll-top="scrollTop"
@scroll="onScroll"
@scrolltolower="onScrollTolower"
class="scroll-container"
>
<div
class="table-list-item"
v-for="(item, index) in tableList"
@ -178,6 +184,8 @@ import { ref, computed } from 'vue'
import { getBackList, submitBackApply, backApplyRemove } from '../../services/back.js'
import { onShow } from '@dcloudio/uni-app'
import { debounce } from 'lodash-es'
const scrollTop = ref(0)
const total = ref(0) //
const active = ref(1) // tap
const tableList = ref([]) //
@ -335,6 +343,10 @@ const getTableList = async (isTap = false) => {
console.log('queryParams.value查询参数', queryParams.value)
const res = await getBackList(queryParams.value)
console.log('res列表数据', res)
setTimeout(() => {
scrollTop.value = uni.getStorageSync('scrollTop') || 0
console.log('🚀 ~ scrollTop.value:', scrollTop.value)
}, 400)
total.value = res.data.total
if (isTap) {
tableList.value = res.data.rows
@ -348,10 +360,10 @@ const getTableList = async (isTap = false) => {
const unique = []
const seen = new Set()
for (const item of merged) {
if (!seen.has(item.taskId)) {
seen.add(item.taskId)
unique.push(item)
}
if (!seen.has(item.taskId)) {
seen.add(item.taskId)
unique.push(item)
}
}
console.log('🚀 ~ getTableList ~ unique:', unique)
tableList.value = unique
@ -371,9 +383,20 @@ const onScrollTolower = debounce(() => {
getTableList()
}
})
let timer = null
const onScroll = (e) => {
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
uni.setStorageSync('scrollTop', e.detail.scrollTop)
uni.setStorageSync('queryParams', JSON.stringify(queryParams.value))
}, 500)
}
//tab
const changeTab = (index) => {
active.value = index
uni.setStorageSync('scrollTop', 0)
uni.setStorageSync('activeTab', index)
if (index == 1) {
queryParams.value.appTaskStatus = 0
} else if (index == 2) {
@ -413,6 +436,10 @@ const leftClick = () => {
onShow(() => {
tableList.value = []
total.value = 0
if (uni.getStorageSync('queryParams')) {
queryParams.value = JSON.parse(uni.getStorageSync('queryParams'))
}
active.value = uni.getStorageSync('activeTab') || 1
getTableList(true)
})

View File

@ -214,7 +214,7 @@ const getTableList = async (isTap = false, isSearch = false) => {
setTimeout(() => {
scrollTop.value = uni.getStorageSync('scrollTop') || 0
console.log('🚀 ~ scrollTop.value:', scrollTop.value)
}, 300)
}, 400)
console.log('res列表数据', res)
total.value = res.data.total
if (isTap) {
@ -255,6 +255,7 @@ onShow(() => {
if (uni.getStorageSync('queryParams')) {
queryParams.value = JSON.parse(uni.getStorageSync('queryParams'))
}
active.value = uni.getStorageSync('activeTab') || 0
getTableList()
})
@ -285,8 +286,8 @@ const onScroll = (e) => {
// tap
const changeTab = (index) => {
uni.removeStorageSync('scrollTop')
uni.removeStorageSync('queryParams')
uni.setStorageSync('scrollTop', 0)
uni.setStorageSync('activeTab', index)
active.value = index
console.log('index', index)
if (index == 2) {

View File

@ -104,7 +104,7 @@
</view>
</scroll-view>
<scroll-view scroll-y @scrolltolower="onScrollTolower" class="scroll-container" v-else>
<scroll-view scroll-y :scroll-top="scrollTop" @scroll="onScroll" @scrolltolower="onScrollTolower" class="scroll-container" v-else>
<view
class="table-list-item"
:key="index"
@ -192,6 +192,7 @@ import { onLoad, onShow } from '@dcloudio/uni-app'
import { debounce } from 'lodash-es'
import { onBackPress } from '@dcloudio/uni-app'
const scrollTop = ref(0)
const opts = ref(null)
const total = ref(0) //
const active = ref(1) // tap
@ -270,6 +271,10 @@ const getTableList = async (isTap = false, isSearch = false) => {
} else {
res = await getPickingOutboundListAPI(queryParams.value)
}
setTimeout(() => {
scrollTop.value = uni.getStorageSync('scrollTop') || 0
console.log('🚀 ~ scrollTop.value:', scrollTop.value)
}, 400)
console.log('res列表数据', res)
total.value = res.data.total
if (isTap) {
@ -311,6 +316,9 @@ onShow(() => {
queryParams.value.pageNum = 1
tableList.value = []
total.value = 0
if (uni.getStorageSync('queryParams')) {
queryParams.value = JSON.parse(uni.getStorageSync('queryParams'))
}
if (opts.value) {
getTableList()
} else {
@ -327,6 +335,15 @@ const onScrollTolower = debounce(() => {
}
}, 500)
let timer = null
const onScroll = (e) => {
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
uni.setStorageSync('scrollTop', e.detail.scrollTop)
uni.setStorageSync('queryParams', JSON.stringify(queryParams.value))
}, 500)
}
// tap
const changeTab = (index) => {
active.value = index

View File

@ -57,7 +57,7 @@
</uni-col>
</uni-row>
<scroll-view scroll-y @scrolltolower="onScrollTolower" class="scroll-container">
<scroll-view scroll-y :scroll-top="scrollTop" @scroll="onScroll" @scrolltolower="onScrollTolower" class="scroll-container">
<view
class="table-list-item"
:key="index"
@ -157,6 +157,7 @@ import { getRepairedList } from '@/services/repair/testedInBound.js'
import { onShow, onLoad } from '@dcloudio/uni-app'
import { debounce } from 'lodash-es'
const scrollTop = ref(0)
const total = ref(0) //
const active = ref(1) // tap
const tableList = ref([]) //
@ -242,6 +243,10 @@ const getTableList = async (isTap = false) => {
mask: true
})
const res = await getRepairedList(queryParams.value)
setTimeout(() => {
scrollTop.value = uni.getStorageSync('scrollTop') || 0
console.log('🚀 ~ scrollTop.value:', scrollTop.value)
}, 400)
total.value = res.data.total
if (isTap) {
tableList.value = res.data.rows
@ -271,30 +276,38 @@ const getTableList = async (isTap = false) => {
}
//
onLoad(() => {
// tableList.value = []
// total.value = 0
onShow(() => {
tableList.value = []
total.value = 0
if (uni.getStorageSync('queryParams')) {
queryParams.value = JSON.parse(uni.getStorageSync('queryParams'))
}
active.value = uni.getStorageSync('activeTab') || 1
getTableList()
})
// onShow(() => {
// tableList.value = []
// total.value = 0
// getTableList()
// })
//
const onScrollTolower = debounce(() => {
console.log('触底事件')
if (total.value > tableList.value.length) {
queryParams.value.pageSize += 5
queryParams.value.pageSize += 10
getTableList()
}
}, 500)
let timer = null
const onScroll = (e) => {
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
uni.setStorageSync('scrollTop', e.detail.scrollTop)
uni.setStorageSync('queryParams', JSON.stringify(queryParams.value))
}, 500)
}
// tap
const changeTab = (index) => {
active.value = index
uni.setStorageSync('scrollTop', 0)
uni.setStorageSync('activeTab', index)
if (index == 1) {
queryParams.value.appTaskStatus = 0 //
queryParams.value.pageNum = 1

View File

@ -153,6 +153,7 @@ import { onShow,onLoad } from '@dcloudio/uni-app'
const urlPermissions = ref([])
onShow((options) => {
urlPermissions.value = uni.getStorageSync('urlPermissions')
uni.removeStorageSync('activeTab')
uni.removeStorageSync('scrollTop')
uni.removeStorageSync('queryParams')
})