From 8dd9360a0e4cfd22ea9e261bec3821eff3f57fe8 Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期二, 12 八月 2025 10:10:07 +0800
Subject: [PATCH] add:分享功能
---
pages/home/home.vue | 275 ++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 224 insertions(+), 51 deletions(-)
diff --git a/pages/home/home.vue b/pages/home/home.vue
index 5288e11..3665161 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: 1650rpx;">
<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,22 +32,44 @@
</swiper>
</view>
- <SectionTitle title="全球影视地标" optitle="查看全部" goUrl="/pages/home/home-more" />
- <GlobalGeo />
+ <SectionTitle title="全球影视地标" optitle="查看全部" goUrl="/sub-pages/hot-city/index" />
+<!-- <GlobalGeo />-->
+ <view class="continent-section">
+ <view class="continent-item all" @click="navigateToAll">全部</view>
+ <view class="continents-container">
+ <view class="continent-row" v-for="(row, index) in continentRows" :key="index">
+ <view
+ class="continent-item continent"
+ v-for="(continent, colIndex) in row"
+ :key="colIndex"
+ @click="navigateToDetail(continent)"
+ >
+ {{ continent.name }}
+ </view>
+ <!-- 添加占位元素保持布局 -->
+ <view
+ v-for="n in (3 - row.length)"
+ :key="'placeholder'+n"
+ class="continent-placeholder"
+ ></view>
+ </view>
+ </view>
+ <view class="continent-item separator"></view>
+ <view class="continent-item nearby" @click="navigateToNearby">
+ <view>附</view>
+ <view>近</view>
+ </view>
+ </view>
- <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" />
- <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,16 +79,14 @@
<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'
-import GlobalGeo from './global-geo.vue'
import SceneMuseumCard from './scene-museum-card.vue'
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'
@@ -76,6 +96,52 @@
// 主题
const theme = ref('light')
+const continents = ref([])
+
+const getContinents = async () => {
+ try {
+ const {code, data} = await $http.request('get', '/api/code/value?type=CONTINENT_TYPE')
+ if (code == 0 && data) {
+ continents.value = data.map(item => (
+ {
+ id: item.id,
+ name: item.label
+ })
+ )
+ }
+
+ } catch (error) {
+ console.log('获取洲数据失败', error)
+ $message.showToast('获取洲数据失败')
+ }
+
+}
+
+const continentRows = computed(() => {
+ const rows = [];
+ const continentsList = [...continents.value];
+
+ // 将洲分成三行
+ for (let i = 0; i < 3; i++) {
+ const start = i * 3;
+ const end = start + 3;
+ rows.push(continentsList.slice(start, end));
+ }
+
+ return rows;
+});
+
+const navigateToDetail = (continent) => {
+ //跳转到具体页面
+ uni.navigateTo({
+ url: `/sub-pages/hot-city/index?continentId=${continent.id}`
+ })
+}
+const navigateToNearby = () => {
+ //附近功能跳转
+ $message.showToast('附近功能未开放!');
+}
+
// 当前页数
const currentPage = ref(0)
@@ -84,44 +150,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[]>([])
@@ -129,6 +186,7 @@
onMounted(() => {
const localTheme = uni.getStorageSync('theme') || 'light'
theme.value = localTheme
+ getContinents()
})
onShow(() => {
@@ -136,8 +194,11 @@
// 内容精选
getContentSelected()
- // 光影社区
+ // 光影
getCommunitys()
+
+ // 场景博物馆
+ getSceneMuseumData()
});
@@ -145,29 +206,27 @@
console.log('用户下拉刷新了')
// 内容精选
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,17 +249,34 @@
communityStatus.value = 'noMore'
}
}
-const getCommunitys_bak = async () => {
- communitys.value = await getFilmWorks(FilmWorksCategory.COMMUNITY, 10,1);
+
+
+// 获取场景博物馆数据
+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,currentPage: 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
}
})
@@ -210,7 +286,6 @@
$message.showToast('系统异常,无法获取数据')
return null;
}
-
}
// 下一页
@@ -231,6 +306,28 @@
const onSwiperChange = (e: SwiperChangeEvent) => {
currentPage.value = e.detail.current
}
+
+// 小程序分享配置
+defineExpose({
+ onShareAppMessage() {
+ return {
+ title: '影视地标推荐',
+ path: '/pages/home/home',
+ imageUrl: '', // 可以设置默认分享图片
+ desc: '发现全球影视拍摄地,探索电影背后的故事'
+ }
+ },
+ // 分享到朋友圈
+ onShareTimeline() {
+ return {
+ title: '影视地标推荐',
+ query: '',
+ imageUrl: '', // 可以设置默认分享图片
+ desc: '发现全球影视拍摄地,探索电影背后的故事'
+ }
+ }
+})
+
</script>
<style scoped>
@@ -252,6 +349,82 @@
margin-top: 20rpx;
margin-bottom: 20rpx;
}
+
+.continent-section {
+ display: flex;
+ align-items: stretch;
+ border-top: 1px dashed #ccc;
+ border-bottom: 1px dashed #ccc;
+ padding: 10rpx 0;
+ height: 220rpx; /* 固定高度容纳三行 */
+}
+
+.all, .nearby {
+ flex-shrink: 0;
+ width: 15%;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ font-size: 30rpx;
+ font-weight: bold;
+}
+
+.continents-container {
+ flex: 1;
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+}
+
+.continent-row {
+ display: flex;
+ justify-content: flex-start; /* 改为左对齐 */
+ height: 33.33%; /* 每行高度占三分之一 */
+ padding: 5rpx 0;
+}
+
+.continent {
+ flex: 0 0 30%; /* 固定宽度30% */
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ text-align: center;
+ font-size: 28rpx;
+ padding: 5rpx 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ margin-right: 5%; /* 元素间间距 */
+}
+
+/* 最后一个元素不需要右边距 */
+.continent:last-child {
+ margin-right: 0;
+}
+
+.continent-placeholder {
+ flex: 0 0 30%; /* 占位元素宽度 */
+ margin-right: 5%; /* 保持与正常元素相同的间距 */
+}
+
+/* 最后一个占位元素不需要右边距 */
+.continent-placeholder:last-child {
+ margin-right: 0;
+}
+
+.separator {
+ width: 1px;
+ background-color: #ccc;
+ margin: 0 10rpx;
+ align-self: center;
+ height: 80%; /* 分隔线高度为父容器的80% */
+}
+
+.nearby {
+ flex-direction: column;
+ font-size: 30rpx;
+}
</style>
<style scoped lang="scss">
--
Gitblit v1.9.3