fix(product): 修复 scroll-view 兼容性和 prop 验证错误
- 移除 product-center 页面的 scroll-view 组件,改用原生 view - 删除冗余的 onScrollToLower 函数 - 将触底加载逻辑内联到 useReachBottom hook 中 - 为 product-detail 页面的 PlanFormContainer 添加条件渲染 - 避免 productDetail 为 null 时的 prop 类型检查错误 影响文件: - src/pages/product-center/index.vue - src/pages/product-detail/index.vue Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Showing
2 changed files
with
11 additions
and
21 deletions
| ... | @@ -43,12 +43,8 @@ | ... | @@ -43,12 +43,8 @@ |
| 43 | </view> | 43 | </view> |
| 44 | </view> | 44 | </view> |
| 45 | 45 | ||
| 46 | - <!-- 列表容器 --> | 46 | + <!-- 列表容器 - 使用原生滚动 --> |
| 47 | - <scroll-view | 47 | + <view class="flex-1 min-h-0 overflow-y-auto pb-[calc(160rpx+env(safe-area-inset-bottom))]"> |
| 48 | - class="flex-1 min-h-0 overflow-y-auto pb-[calc(160rpx+env(safe-area-inset-bottom))]" | ||
| 49 | - scroll-y | ||
| 50 | - @scrolltolower="onScrollToLower" | ||
| 51 | - > | ||
| 52 | <!-- 加载状态 --> | 48 | <!-- 加载状态 --> |
| 53 | <view v-if="loading && products.length === 0" class="flex justify-center items-center py-[100rpx]"> | 49 | <view v-if="loading && products.length === 0" class="flex justify-center items-center py-[100rpx]"> |
| 54 | <text class="text-gray-400 text-[28rpx]">加载中...</text> | 50 | <text class="text-gray-400 text-[28rpx]">加载中...</text> |
| ... | @@ -131,7 +127,7 @@ | ... | @@ -131,7 +127,7 @@ |
| 131 | <view v-if="!loading && products.length === 0"> | 127 | <view v-if="!loading && products.length === 0"> |
| 132 | <nut-empty description="暂无相关产品" image="empty" /> | 128 | <nut-empty description="暂无相关产品" image="empty" /> |
| 133 | </view> | 129 | </view> |
| 134 | - </scroll-view> | 130 | + </view> |
| 135 | 131 | ||
| 136 | <!-- 计划书表单容器 --> | 132 | <!-- 计划书表单容器 --> |
| 137 | <!-- 测试数据:后端接口和字段还没有准备好,使用 PlanFormContainer 进行的前端测试 --> | 133 | <!-- 测试数据:后端接口和字段还没有准备好,使用 PlanFormContainer 进行的前端测试 --> |
| ... | @@ -342,17 +338,6 @@ const onClear = () => { | ... | @@ -342,17 +338,6 @@ const onClear = () => { |
| 342 | } | 338 | } |
| 343 | 339 | ||
| 344 | /** | 340 | /** |
| 345 | - * 滚动到底部加载更多 | ||
| 346 | - * @description 触发上拉加载更多 | ||
| 347 | - */ | ||
| 348 | -const onScrollToLower = () => { | ||
| 349 | - if (!hasMore.value || loading.value) return | ||
| 350 | - | ||
| 351 | - page.value += 1 | ||
| 352 | - fetchProducts(true) | ||
| 353 | -} | ||
| 354 | - | ||
| 355 | -/** | ||
| 356 | * 使用产品列表点击处理器 | 341 | * 使用产品列表点击处理器 |
| 357 | * @description 配置为产品类型列表,点击时跳转到产品详情页 | 342 | * @description 配置为产品类型列表,点击时跳转到产品详情页 |
| 358 | */ | 343 | */ |
| ... | @@ -412,10 +397,13 @@ useLoad(() => { | ... | @@ -412,10 +397,13 @@ useLoad(() => { |
| 412 | }) | 397 | }) |
| 413 | 398 | ||
| 414 | /** | 399 | /** |
| 415 | - * 触底加载更多(备用方案) | 400 | + * 触底加载更多 |
| 416 | */ | 401 | */ |
| 417 | useReachBottom(() => { | 402 | useReachBottom(() => { |
| 418 | - onScrollToLower() | 403 | + if (!hasMore.value || loading.value) return |
| 404 | + | ||
| 405 | + page.value += 1 | ||
| 406 | + fetchProducts(true) | ||
| 419 | }) | 407 | }) |
| 420 | </script> | 408 | </script> |
| 421 | 409 | ... | ... |
| ... | @@ -112,19 +112,21 @@ | ... | @@ -112,19 +112,21 @@ |
| 112 | 112 | ||
| 113 | <!-- 计划书表单容器 --> | 113 | <!-- 计划书表单容器 --> |
| 114 | <!-- 测试数据:后端接口和字段还没有准备好,使用 PlanFormContainer 进行的前端测试 --> | 114 | <!-- 测试数据:后端接口和字段还没有准备好,使用 PlanFormContainer 进行的前端测试 --> |
| 115 | + <!-- 使用 v-if 条件渲染,避免 productDetail 为 null 时的 prop 类型检查错误 --> | ||
| 116 | + <view v-if="showPlanPopup && productDetail.id"> | ||
| 115 | <PlanFormContainer | 117 | <PlanFormContainer |
| 116 | v-model:visible="showPlanPopup" | 118 | v-model:visible="showPlanPopup" |
| 117 | :product="productDetail" | 119 | :product="productDetail" |
| 118 | @close="showPlanPopup = false" | 120 | @close="showPlanPopup = false" |
| 119 | @submit="handlePlanSubmit" | 121 | @submit="handlePlanSubmit" |
| 120 | /> | 122 | /> |
| 123 | + </view> | ||
| 121 | </div> | 124 | </div> |
| 122 | </template> | 125 | </template> |
| 123 | 126 | ||
| 124 | <script setup> | 127 | <script setup> |
| 125 | import { ref } from 'vue' | 128 | import { ref } from 'vue' |
| 126 | import NavHeader from '@/components/NavHeader.vue' | 129 | import NavHeader from '@/components/NavHeader.vue' |
| 127 | -import TabBar from '@/components/TabBar.vue' | ||
| 128 | import IconFont from '@/components/IconFont.vue' | 130 | import IconFont from '@/components/IconFont.vue' |
| 129 | import PlanFormContainer from '@/components/PlanFormContainer.vue' | 131 | import PlanFormContainer from '@/components/PlanFormContainer.vue' |
| 130 | import { useFileOperation } from '@/composables/useFileOperation' | 132 | import { useFileOperation } from '@/composables/useFileOperation' | ... | ... |
-
Please register or login to post a comment