From d9a780fa538cb7a83aefa04e75cb53185d690d7d Mon Sep 17 00:00:00 2001
From: tj <1378534974@qq.com>
Date: 星期五, 30 五月 2025 16:39:07 +0800
Subject: [PATCH] 微封装

---
 pages/home/home.vue |   35 ++++++++++++++---------------------
 1 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/pages/home/home.vue b/pages/home/home.vue
index 5288e11..a4f2ad9 100644
--- a/pages/home/home.vue
+++ b/pages/home/home.vue
@@ -43,11 +43,7 @@
       <Community v-for="(item, index) in communitys" :key="index" :avatar="item.avatar" :nickname="item.nickname"
         :time="formatRelativeTime(item.createTime)" :image="item.coverUrl" :content="item.coverAlt"
         :likeCount="item.likeCount" :commentCount="item.commentCount" />
-      <view class="more">
-        <!-- <view v-if="loadingCommunity">加载中...</view>
-        <view v-if="noMoreCommunity">没有更多了</view> -->
-        <up-loadmore :status="communityStatus" />
-      </view>
+      <up-loadmore :status="communityStatus" :line="true" />
       <view style="height: 300rpx;"></view>
     </view>
 
@@ -57,7 +53,7 @@
 
 <script setup lang="ts">
 import { ref, computed, onMounted } from 'vue'
-import { onShow, onPullDownRefresh,onReachBottom } from '@dcloudio/uni-app'
+import { onShow, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
 
 import HomeMain from './home-main.vue'
 import TripCard from './trip-card.vue'
@@ -66,7 +62,6 @@
 import Community from './community.vue'
 import { SwiperChangeEvent } from '@dcloudio/uni-app'
 import { useGlobal } from '@/composables/useGlobal'
-import { number } from 'uview-plus/libs/function/test'
 const { $http, $message, $store } = useGlobal()
 import { FilmWorks } from '@/types/index'
 import { formatRelativeTime } from '@/utils/time'
@@ -90,14 +85,18 @@
 // 分页后的数组,每页3条
 const pagedTripCards = computed(() => {
   const pages: FilmWorks[][] = []
-  for (let i = 0; i < tripCardList.value.length; i += pageSize) {
-    pages.push(tripCardList.value.slice(i, i + pageSize))
+  const list = tripCardList.value || [] // 安全兜底
+  for (let i = 0; i < list.length; i += pageSize) {
+    pages.push(list.slice(i, i + pageSize))
   }
   return pages
 })
 
 // 总页数
-const totalPages = computed(() => Math.ceil(tripCardList.value.length / pageSize))
+const totalPages = computed(() => {
+  const list = tripCardList.value || [] // 安全兜底
+  return Math.ceil(list.length / pageSize)
+})
 
 // 场景博物馆卡片数据
 const cardList = ref([
@@ -146,28 +145,26 @@
   // 内容精选
   getContentSelected()
   // 光影社区
-  communityPage.value=1
+  communityPage.value = 1
   getCommunitys()
   uni.stopPullDownRefresh() // 停止下拉刷新动画
 })
 
-onReachBottom(()=>{
+onReachBottom(() => {
   console.log('用户触底了')
   getCommunitys()
 })
 
 const getContentSelected = async () => {
-  tripCardList.value = await getFilmWorks(FilmWorksCategory.CONTENT_SELECTED, 20,1);
+  tripCardList.value = await getFilmWorks(FilmWorksCategory.CONTENT_SELECTED, 20, 1);
 }
 
 
 const communityPage = ref(1)
 const communitySize = 10
 const communityStatus = ref('loading')
-
-
 const getCommunitys = async () => {
-  if (communityStatus.value==='nomore') return
+  if (communityStatus.value === 'nomore') return
 
   communityStatus.value = 'loading'
 
@@ -190,11 +187,8 @@
     communityStatus.value = 'noMore'
   }
 }
-const getCommunitys_bak = async () => {
-  communitys.value = await getFilmWorks(FilmWorksCategory.COMMUNITY, 10,1);
-}
 // 内容精选
-const getFilmWorks = async (type: String, pageSize: Number,currentPage: Number) => {
+const getFilmWorks = async (type: String, pageSize: Number, currentPage: Number) => {
   const {
     code, data
   } = await $http.request('get', '/api/filmWorks/list', {
@@ -210,7 +204,6 @@
     $message.showToast('系统异常,无法获取数据')
     return null;
   }
-
 }
 
 // 下一页

--
Gitblit v1.9.3