From fa74612c99459a8b4e94121d2d3bfcc42915208b Mon Sep 17 00:00:00 2001
From: tj <1378534974@qq.com>
Date: 星期二, 27 五月 2025 16:08:20 +0800
Subject: [PATCH] loading,wechatLogin

---
 pages/home/home.vue |   67 +++++++++++++++++++++++++++++----
 1 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/pages/home/home.vue b/pages/home/home.vue
index a71e374..5288e11 100644
--- a/pages/home/home.vue
+++ b/pages/home/home.vue
@@ -43,7 +43,11 @@
       <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>
       <view style="height: 300rpx;"></view>
     </view>
 
@@ -53,7 +57,7 @@
 
 <script setup lang="ts">
 import { ref, computed, onMounted } from 'vue'
-import { onShow } from '@dcloudio/uni-app'
+import { onShow, onPullDownRefresh,onReachBottom } from '@dcloudio/uni-app'
 
 import HomeMain from './home-main.vue'
 import TripCard from './trip-card.vue'
@@ -67,6 +71,7 @@
 import { FilmWorks } from '@/types/index'
 import { formatRelativeTime } from '@/utils/time'
 import { FilmWorksCategory } from '@/enums/dict'
+
 
 // 主题
 const theme = ref('light')
@@ -135,22 +140,68 @@
   getCommunitys()
 });
 
-async function getContentSelected() {
-  tripCardList.value = await getFilmWorks(FilmWorksCategory.CONTENT_SELECTED, 20);
-  console.log('内容精选', tripCardList.value);
+
+onPullDownRefresh(async () => {
+  console.log('用户下拉刷新了')
+  // 内容精选
+  getContentSelected()
+  // 光影社区
+  communityPage.value=1
+  getCommunitys()
+  uni.stopPullDownRefresh() // 停止下拉刷新动画
+})
+
+onReachBottom(()=>{
+  console.log('用户触底了')
+  getCommunitys()
+})
+
+const getContentSelected = async () => {
+  tripCardList.value = await getFilmWorks(FilmWorksCategory.CONTENT_SELECTED, 20,1);
 }
 
-async function getCommunitys() {
-  communitys.value = await getFilmWorks(FilmWorksCategory.COMMUNITY, 10);
+
+const communityPage = ref(1)
+const communitySize = 10
+const communityStatus = ref('loading')
+
+
+const getCommunitys = async () => {
+  if (communityStatus.value==='nomore') return
+
+  communityStatus.value = 'loading'
+
+  const records = await getFilmWorks(FilmWorksCategory.COMMUNITY, communitySize, communityPage.value)
+
+  if (records && records.length > 0) {
+    // 使用 Set 进行去重
+    const existingIds = new Set(communitys.value.map(item => item.id))
+    const uniqueRecords = records.filter(item => !existingIds.has(item.id))
+
+    communitys.value = [...communitys.value, ...uniqueRecords]
+
+    // 如果返回的记录数少于请求的 size,说明没有更多数据
+    if (records.length < communitySize) {
+      communityStatus.value = 'noMore'
+    }
+
+    communityPage.value++
+  } else {
+    communityStatus.value = 'noMore'
+  }
+}
+const getCommunitys_bak = async () => {
+  communitys.value = await getFilmWorks(FilmWorksCategory.COMMUNITY, 10,1);
 }
 // 内容精选
-const getFilmWorks = async (type: String, pageSize: Number) => {
+const getFilmWorks = async (type: String, pageSize: Number,currentPage: Number) => {
   const {
     code, data
   } = await $http.request('get', '/api/filmWorks/list', {
     params: {
       classify: type,
       size: pageSize,
+      current: currentPage
     }
   })
   if (code == 0) {

--
Gitblit v1.9.3