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

View File

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

View File

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

View File

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

View File

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