fix: 移动端列表页首次加载pageNum从1开始

**问题:**
- van-list组件的@load事件在挂载时自动触发
- 导致onLoad先执行pageNum++,首次请求时pageNum变成2

**修复:**
- 在onMounted中主动加载第一页数据
- onLoad只处理加载更多逻辑
- 统一所有列表页:customer, project, expense, requirement, receivable
This commit is contained in:
zhangjf 2026-02-23 13:43:43 +08:00
parent 9b545b3f00
commit ff9f4d05ad
5 changed files with 42 additions and 10 deletions

View File

@ -41,7 +41,7 @@
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import { getCustomerList } from '@/api'
const searchText = ref('')
@ -84,6 +84,8 @@ const loadData = async () => {
}
const onLoad = () => {
if (loading.value) return
loading.value = true
pageNum.value++
loadData()
}
@ -98,8 +100,14 @@ const handleSearch = () => {
pageNum.value = 1
finished.value = false
list.value = []
loading.value = true
loadData()
}
onMounted(() => {
loading.value = true
loadData()
})
</script>
<style scoped>

View File

@ -52,7 +52,7 @@
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import { getExpenseList } from '@/api'
const searchText = ref('')
@ -107,6 +107,8 @@ const loadData = async () => {
}
const onLoad = () => {
if (loading.value) return
loading.value = true
pageNum.value++
loadData()
}
@ -121,8 +123,14 @@ const handleSearch = () => {
pageNum.value = 1
finished.value = false
list.value = []
loading.value = true
loadData()
}
onMounted(() => {
loading.value = true
loadData()
})
</script>
<style scoped>

View File

@ -47,7 +47,7 @@
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { getProjectList } from '@/api'
@ -111,6 +111,8 @@ const loadData = async () => {
}
const onLoad = () => {
if (loading.value) return
loading.value = true
pageNum.value++
loadData()
}
@ -125,12 +127,18 @@ const handleSearch = () => {
pageNum.value = 1
finished.value = false
list.value = []
loading.value = true
loadData()
}
const goDetail = (item: any) => {
router.push(`/project/${item.projectId}`)
}
onMounted(() => {
loading.value = true
loadData()
})
</script>
<style scoped>

View File

@ -106,12 +106,10 @@ const loadData = async () => {
}
const onLoad = () => {
if (pageNum.value === 1 && list.value.length === 0) {
loadData()
} else {
pageNum.value++
loadData()
}
if (loading.value) return
loading.value = true
pageNum.value++
loadData()
}
const onRefresh = () => {
@ -126,10 +124,12 @@ const handleSearch = () => {
pageNum.value = 1
finished.value = false
list.value = []
loading.value = true
loadData()
}
onMounted(() => {
loading.value = true
loadData()
})
</script>

View File

@ -52,7 +52,7 @@
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import { getRequirementList } from '@/api'
const searchText = ref('')
@ -125,6 +125,8 @@ const loadData = async () => {
}
const onLoad = () => {
if (loading.value) return
loading.value = true
pageNum.value++
loadData()
}
@ -139,8 +141,14 @@ const handleSearch = () => {
pageNum.value = 1
finished.value = false
list.value = []
loading.value = true
loadData()
}
onMounted(() => {
loading.value = true
loadData()
})
</script>
<style scoped>