This commit is contained in:
BianLzhaoMin 2025-06-15 16:13:33 +08:00
parent 02afa160c8
commit f789951d23
2 changed files with 64 additions and 21 deletions

View File

@ -109,33 +109,63 @@ const queryParams = ref({
pageSize: 5,
})
//
// const getTableList = async (isTap = false) => {
// console.log(queryParams.value)
// try {
// const { data: res } = await getPurchaseList(queryParams.value)
// console.log('res', res)
// //
// total.value = res.total
// //
// if (isTap) {
// //
// tableList.value = res.rows || []
// //
// queryParams.value.pageNum = 1
// } else {
// //
// if (res.rows && res.rows.length > 0) {
// tableList.value = [...tableList.value, ...res.rows]
// }
// }
// } catch (error) {
// console.error(':', error)
// //
// if (isTap) {
// tableList.value = []
// }
// }
// }
const getTableList = async (isTap = false) => {
console.log(queryParams.value)
try {
const { data: res } = await getPurchaseList(queryParams.value)
console.log('res列表数据', res)
//
total.value = res.total
//
if (isTap) {
//
tableList.value = res.rows || []
//
queryParams.value.pageNum = 1
} else {
//
if (res.rows && res.rows.length > 0) {
if (res.rows?.length) {
tableList.value = [...tableList.value, ...res.rows]
}
}
return res // 使
} catch (error) {
console.error('获取列表数据失败:', error)
//
if (isTap) {
tableList.value = []
}
if (isTap) tableList.value = []
throw error //
}
}
//
const scrollToPosition = (position) => {
const savedScrollTop = uni.getStorageSync('scrollTop') || 0
console.log('🚀 ~ scrollToPosition ~ savedScrollTop:', savedScrollTop)
scrollTop.value = 0
setTimeout(() => {
scrollTop.value = savedScrollTop
}, 1000)
}
//
const onScrollTolower = debounce(() => {
console.log('触底事件')
@ -193,24 +223,36 @@ const handleItem = (item) => {
})
return
}
uni.navigateTo({
uni.redirectTo({
url: `/pages/new-purchase/accept/acceptDetails?id=${item.id}&taskId=${item.taskId}&isFinished=${isFinished}`,
})
}
const scrollTop = ref(0)
onShow((options) => {
//
onShow(async (options) => {
const currentPage = uni.getStorageSync('currentPage')
if (currentPage && currentPage > 1) {
const promises = []
for (let i = 1; i <= currentPage; i++) {
queryParams.value.pageNum = i
promises.push(getTableList(true)) // isTap=true
}
Promise.all(promises).then(() => {
scrollToPosition()
})
} else {
getTableList(true)
const savedScrollTop = uni.getStorageSync('scrollTop') || 0
scrollTop.value = 0
setTimeout(() => {
scrollTop.value = savedScrollTop
}, 500)
scrollToPosition()
}
})
// scroll
const onScrollChange = (e) => {
console.log('🚀 ~ onScrollChange ~ e:', e)
uni.setStorageSync('scrollTop', e.detail.scrollTop)
uni.setStorageSync('currentPage', queryParams.value.pageNum)
}
</script>
@ -369,7 +411,7 @@ const onScrollChange = (e) => {
.scroll-container {
padding: 0 2rpx;
// height: 60vh;
.table-list-item {
margin: 24rpx 0;
padding: 32rpx;

View File

@ -307,6 +307,7 @@ const boxList = ref([
const onNavigateTo = (url) => {
uni.setStorageSync('scrollTop', null)
uni.setStorageSync('currentPage', 1)
uni.navigateTo({ url })
}
</script>