| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- <template>
- <div class="activity-container">
- <!-- 返回按钮 -->
- <div class="back-button" @click="goBackToIndex">
- <img src="@/assets/indexPage/icon_back.png" alt="" />
- </div>
- <!-- 标题 -->
- <div class="section-title">社教活动</div>
- <!-- 活动列表 -->
- <div v-if="loading && activeList.length === 0" class="loading-container">
- <div class="loading-text">加载中...</div>
- </div>
- <div v-else class="content-section">
- <div class="collection-list">
- <div
- class="collection-item"
- v-for="(item, index) in activeList"
- :key="item.id || item.activityId || index"
- >
- <div class="item-image-container" @click="viewActivity(item)">
- <img
- :src="getFieldValue(item, 'infoImg')"
- :alt="getFieldValue(item, 'title') || '活动图片'"
- class="item-image"
- />
- <div class="view-button">
- <span>查看</span
- ><el-icon>
- <Right />
- </el-icon>
- </div>
- <div class="item-info">
- <div class="item-title">{{ getFieldValue(item, 'title') || '暂无标题' }}</div>
- <div class="item-description">{{ getFieldValue(item, 'remark') || '暂无描述' }}</div>
- </div>
- </div>
- </div>
- </div>
- <!-- 空状态 -->
- <div v-if="activeList.length === 0" class="empty-state">
- <div class="empty-text">暂无活动数据</div>
- </div>
- <!-- 加载更多指示器 -->
- <div v-if="activeList.length > 0 && isLoadingMore" class="loading-more">
- <div class="loading-more-text">加载中...</div>
- </div>
- <!-- 没有更多数据提示 -->
- <div v-if="activeList.length > 0 && !activeHasMore && !isLoadingMore" class="no-more">
- <div class="no-more-text">没有更多数据了</div>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: 'ActivityPage',
- }
- </script>
- <script setup>
- import { onMounted, computed, nextTick, onUnmounted } from 'vue'
- import { useRouter, useRoute } from 'vue-router'
- import { useIndexPageApi } from '@/setup/useIndexPageApi'
- const router = useRouter()
- const route = useRoute()
- // 检查是否为预览模式
- const isPreviewMode = computed(() => {
- return route.query.preview === '1'
- })
- // 获取字段值的通用方法,优先获取带B后缀的字段
- const getFieldValue = (item, fieldName) => {
- if (isPreviewMode.value) {
- return item[fieldName + 'B'] || item[fieldName]
- }
- return item[fieldName]
- }
- // 使用组合式函数获取API方法和响应式数据
- const { activeList, getActiveList, loading, activeHasMore, loadMoreActivities } = useIndexPageApi()
- // 滚动加载相关
- const isLoadingMore = computed(() => loading.value && activeList.value.length > 0)
- // 滚动事件处理
- const handleScroll = async () => {
- const container = document.querySelector('.activity-container')
- if (!container) return
- const { scrollTop, scrollHeight, clientHeight } = container
- const threshold = 100 // 距离底部100px时触发加载
- if (
- scrollTop + clientHeight >= scrollHeight - threshold &&
- !isLoadingMore.value &&
- activeHasMore.value
- ) {
- await loadMore()
- }
- }
- // 加载更多数据
- const loadMore = async () => {
- try {
- const params = {}
- // 如果是预览模式,设置status为-1
- if (isPreviewMode.value) {
- params.status = -1
- }
- await loadMoreActivities(params)
- } catch (error) {
- console.error('加载更多活动数据失败:', error)
- }
- }
- // 页面初始化时获取活动数据
- onMounted(async () => {
- try {
- const params = { pageNum: 1, pageSize: 10 }
- // 如果是预览模式,设置status为-1
- if (isPreviewMode.value) {
- params.status = -1
- }
- await getActiveList(params)
- // 添加滚动事件监听
- await nextTick()
- const container = document.querySelector('.activity-container')
- if (container) {
- container.addEventListener('scroll', handleScroll)
- }
- } catch (error) {
- console.error('获取活动数据失败:', error)
- }
- })
- // 组件卸载时移除滚动事件监听
- onUnmounted(() => {
- const container = document.querySelector('.activity-container')
- if (container) {
- container.removeEventListener('scroll', handleScroll)
- }
- })
- // 返回首页函数
- const goBackToIndex = () => {
- if (isPreviewMode.value) {
- router.replace({
- path: '/indexPage',
- query: { preview: '1' },
- })
- } else {
- router.replace('/indexPage')
- }
- }
- // 查看活动详情
- const viewActivity = (item) => {
- console.log('查看活动详情:', item)
- // 跳转到详情页,传递活动ID和类型参数
- router.push({
- path: '/allDetailsShow',
- query: {
- id: item.id || item.activityId,
- type: 'activity', // 标识这是活动详情
- isFromPage: 'indexPage/activity',
- },
- })
- }
- </script>
- <style lang="scss" scoped>
- .activity-container {
- position: relative;
- height: 100vh;
- min-width: 375px;
- padding: 20px;
- background: url('@/assets/indexPage/bg.png') no-repeat;
- background-size: cover;
- overflow-y: auto;
- }
- .back-button {
- position: absolute;
- top: 20px;
- left: 20px;
- width: 40px;
- height: 40px;
- border-radius: 50%;
- img {
- width: 40px;
- height: 40px;
- }
- }
- .section-title {
- font-size: 20px;
- font-weight: bold;
- color: #584735;
- margin: 54px 0 20px 0;
- position: relative;
- padding-bottom: 10px;
- &::after {
- content: '';
- position: absolute;
- bottom: 0;
- left: 0;
- width: 100%;
- height: 2px;
- background: linear-gradient(90deg, rgba(91, 71, 46, 0.5) 0%, rgba(91, 71, 46, 0) 100%);
- }
- }
- .collection-list {
- display: flex;
- flex-direction: column;
- gap: 15px;
- }
- .collection-item {
- background-color: #fff;
- border-radius: 8px;
- overflow: hidden;
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
- }
- .item-image-container {
- position: relative;
- height: 218px;
- overflow: hidden;
- cursor: pointer;
- .item-image {
- width: 100%;
- height: 100%;
- object-fit: cover;
- }
- .view-button {
- position: absolute;
- display: flex;
- align-items: center;
- justify-content: center;
- width: 80px;
- height: 36px;
- top: 12px;
- right: 12px;
- background-color: rgba(0, 0, 0, 0.2);
- color: #fff;
- padding: 4px 8px;
- border-radius: 50px;
- font-size: 12px;
- border: 1px solid #fff;
- span {
- font-size: 14px;
- margin-right: 6px;
- }
- }
- }
- .item-info {
- position: absolute;
- width: 90%;
- bottom: 16px;
- left: 24px;
- .item-category {
- font-size: 14px;
- color: #fff;
- }
- .item-title {
- font-size: 20px;
- font-weight: bold;
- color: #fff;
- font-family: 'heavy';
- }
- .item-description {
- font-size: 12px;
- color: #fff;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- }
- // 加载状态样式
- .loading-container {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 200px;
- .loading-text {
- font-size: 18px;
- color: #584735;
- opacity: 0.8;
- }
- }
- // 空状态样式
- .empty-state {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 200px;
- margin-top: 50px;
- .empty-text {
- font-size: 18px;
- color: #584735;
- opacity: 0.6;
- }
- }
- // 加载更多样式
- .loading-more {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 60px;
- margin-top: 20px;
- .loading-more-text {
- font-size: 16px;
- color: #584735;
- opacity: 0.8;
- }
- }
- // 没有更多数据样式
- .no-more {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 60px;
- margin-top: 20px;
- .no-more-text {
- font-size: 16px;
- color: #584735;
- opacity: 0.6;
- }
- }
- </style>
|