From f3ea52bf97e61f6917ccaab904817d74d9d4860c Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期四, 17 七月 2025 09:55:36 +0800
Subject: [PATCH] init

---
 pages/home/home.vue |  138 ++++++++++++++++++++++++++++++++--------------
 1 files changed, 96 insertions(+), 42 deletions(-)

diff --git a/pages/home/home.vue b/pages/home/home.vue
index a71e374..80ed122 100644
--- a/pages/home/home.vue
+++ b/pages/home/home.vue
@@ -23,7 +23,7 @@
       </view>
 
       <view class="trip-card-swiper">
-        <swiper :current="currentPage" @change="onSwiperChange" circular style="min-height: 1450rpx;">
+        <swiper :current="currentPage" @change="onSwiperChange" circular style="min-height: 1850rpx;">
           <swiper-item v-for="(group, pageIndex) in pagedTripCards" :key="pageIndex">
             <TripCard v-for="(item, index) in group" :key="index" :tag="item.tag" :title="item.coverTitle"
               :subtitle="item.coverAlt" :score="item.collectCount" :imageUrl="item.coverUrl"
@@ -32,18 +32,18 @@
         </swiper>
       </view>
 
-      <SectionTitle title="全球影视地标" optitle="查看全部" goUrl="/pages/home/home-more" />
-      <GlobalGeo />
+<!--      <SectionTitle title="全球影视地标" optitle="查看全部" goUrl="/pages/home/home-more" />-->
+<!--      <GlobalGeo />-->
 
-      <SectionTitle title="场景博物馆" optitle="查看全部" goUrl="/pages/home/home-more" />
+      <SectionTitle title="场景博物馆" optitle="查看全部" goUrl="/sub-pages/hot-spot/index" />
       <SceneMuseumCard v-for="(item, index) in cardList" :key="index" :image="item.image" :title="item.title"
         :subtitle="item.subtitle" :readTime="item.readTime" />
 
-      <SectionTitle title="光影社区" optitle="加入社区" goUrl="/pages/home/home-more" />
-      <Community v-for="(item, index) in communitys" :key="index" :avatar="item.avatar" :nickname="item.nickname"
+      <SectionTitle title="光影天地" optitle="加入光影" goUrl="/sub-pages/community/index" />
+      <Community v-for="(item, index) in communitys" :key="index"  :detailUrl="`${detailUrl}?id=${item.id}`"  :avatar="item.avatar" :nickname="item.nickname"
         :time="formatRelativeTime(item.createTime)" :image="item.coverUrl" :content="item.coverAlt"
         :likeCount="item.likeCount" :commentCount="item.commentCount" />
-
+      <up-loadmore :status="communityStatus" :line="true" />
       <view style="height: 300rpx;"></view>
     </view>
 
@@ -53,7 +53,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'
@@ -62,11 +62,11 @@
 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'
 import { FilmWorksCategory } from '@/enums/dict'
+
 
 // 主题
 const theme = ref('light')
@@ -79,44 +79,35 @@
 
 
 // 旅行卡片数据
-const detailUrl = '/api/filmworks/list'
+const detailUrl = '/sub-pages/film-list/film-detail'
 const tripCardList = ref<FilmWorks[]>([])
 
 // 分页后的数组,每页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([
-  {
-    image: 'https://ai-public.mastergo.com/ai/img_res/6a226f9e9652c51cd535c3490535dfeb.jpg',
-    title: '《盗梦空间》巴黎咖啡馆',
-    subtitle: '拷素诺兰如何创造这个标志性场景',
-    readTime: '12分钟阅读',
-  },
-  {
-    image: 'https://img.yzcdn.cn/vant/cat.jpeg',
-    title: '《星际穿越》玉米田',
-    subtitle: '诺兰如何还原地球末日场景',
-    readTime: '8分钟阅读',
-  },
-  {
-    image: 'https://img.yzcdn.cn/vant/cat.jpeg',
-    title: '《星球大战》塔图因星球',
-    subtitle: '经典科幻电影中的沙漠设定',
-    readTime: '10分钟阅读',
-  },
-])
+// 场景博物馆卡片数据
+const cardList = ref<Array<{
+  image: string
+  title: string
+  subtitle: string
+  readTime: string
+}>>([])
 
-// 社区帖子数据
+// 数据
 const communitys = ref<FilmWorks[]>([])
 
 
@@ -131,26 +122,90 @@
   // 内容精选
   getContentSelected()
 
-  // 光影社区
+  // 光影
   getCommunitys()
+
+  // 场景博物馆
+  getSceneMuseumData()
 });
 
-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 getSceneMuseumData = async () => {
+  try {
+    const { code, data } = await $http.request('get', '/api/filmLocation/getTop3')
+    if (code === 0 && data) {
+      cardList.value = data.map(item => ({
+        image: item.locationUrl,
+        title: item.locationName,
+        subtitle: item.address,
+        readTime: `${item.locationWeight}热度`
+      }))
+    }
+  } catch (error) {
+    console.error('获取场景博物馆数据失败:', error)
+    $message.showToast('获取场景博物馆数据失败')
+  }
 }
 // 内容精选
-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,
+      status: 'published',
+      current: currentPage
     }
   })
   if (code == 0) {
@@ -159,7 +214,6 @@
     $message.showToast('系统异常,无法获取数据')
     return null;
   }
-
 }
 
 // 下一页

--
Gitblit v1.9.3