const act = { template: /*language=HTML*/ `
暂无图片
{{getStatusText(activity)}}

{{ activity.name}}

{{ formatActivityDate(activity.startDate) }} 至 {{ formatActivityDate(activity.endDate) }}

暂无近期活动

敬请关注后续通知

`, data() { return { actList: [], swiper: null } }, methods: { updateNavigationPosition() { const swiperElement = this.$refs.activitySwiper const cover = swiperElement && swiperElement.querySelector('.img-box') if (!cover) return // 按实际封面高度定位,避免标题换行或响应式列数变化导致箭头偏移。 const container = swiperElement.parentElement const top = cover.getBoundingClientRect().top - container.getBoundingClientRect().top + cover.offsetHeight / 2 ;[this.$refs.prevButton, this.$refs.nextButton].forEach(button => { if (button) button.style.top = top + 'px' }) }, formatActivityDate(value) { return value ? this.$moment(value).format('YYYY-MM-DD') : '待定' }, browseNext() { if (!this.swiper) return this.swiper.isEnd ? this.swiper.slideTo(0) : this.swiper.slideNext() }, /*查询活动*/ listAct() { this.$axios.post("/platform/home/listHomeActivity").then((res) => { if (res.code === 0) { // for (let i = 0; i < 10; i++) { // this.actList = this.actList.concat(res.data) // } this.actList = res.data // 数据加载完成后初始化Swiper this.$nextTick(() => { this.initSwiper() }) } }) }, /*初始化Swiper*/ initSwiper() { if (this.swiper) { this.swiper.destroy(true, true) this.swiper = null } const swiperElement = this.$refs.activitySwiper if (!swiperElement) { return } // 仅操作当前组件的轮播节点,避免页面其他轮播或尺寸观察器影响卡片宽度。 this.swiper = new Swiper(swiperElement, { slidesPerView: 1, spaceBetween: 18, centeredSlides: false, loop: false, watchOverflow: true, // 双栏中的活动按容器宽度排布,避免用整个窗口宽度挤出过多卡片。 breakpointsBase: 'container', observer: false, observeParents: false, // 页面内容加载后可能出现滚动条,需重新计算列宽,避免末张封面及圆角被裁切。 resizeObserver: true, roundLengths: true, on: { init: () => this.$nextTick(() => this.updateNavigationPosition()), resize: () => this.$nextTick(() => this.updateNavigationPosition()), slidesUpdated: () => this.$nextTick(() => this.updateNavigationPosition()), }, // 鼠标停留在活动区域时可横向浏览,到首尾后释放页面滚动。 mousewheel: { enabled: true, forceToAxis: true, releaseOnEdges: true, sensitivity: 0.8, }, navigation: { nextEl: this.$refs.nextButton, prevEl: this.$refs.prevButton, }, pagination: { el: this.$refs.pagination, type: 'progressbar', }, breakpoints: { 480: { slidesPerView: 2, }, 740: { slidesPerView: 3, } } }) }, // 活动状态 getStatusText(item) { if (this.$moment().unix() > this.$moment(item.endDate).unix()) { return "已结束" } else if (this.$moment().unix() < this.$moment(item.startDate).unix()) { return "未开始" } else { return "进行中" } }, go(act) { if (!act.url) { this.$message.warning("管理员未配置活动链接") return } if (act.url === "/platform/activity/apply" && !this.$auth.hasRoleOr(["SYSADMIN", "SCHOOL_UNION_ADMIN", "BRANCH_UNION_CHAIRMAN", "BRANCH_UNION_WENTI_SPORTS"])) { return this.$message.warning("PC端暂未开放报名,请前往移动端报名!") } window.open(act.url) } }, mounted() { this.listAct() }, beforeDestroy() { if (this.swiper) { this.swiper.destroy(true, true) this.swiper = null } }, style: /*language=CSS*/ ` .activity-section-wrapper { width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; overflow: hidden; } .section-act { width: 100%; min-width: 0; max-width: 100%; } .section-act .section-act-title span { font-size: 30px; color: #000000; display: block; font-weight: bold; position: relative; text-align: center; padding: 40px 0; } /*.section-act .section-act-title span:hover { color: var(--color-primary); cursor: pointer; }*/ /deep/ .section-act .section-act-title span::before { content: ''; width: 24px; height: 11px; background: url(https://www.ncu.edu.cn/images/titl.svg) no-repeat center; background-size: 24px 11px; display: inline-block; margin-right: 0; vertical-align: middle; } /deep/ .section-act .section-act-title span::after { content: ''; width: 24px; height: 11px; background: url(https://www.ncu.edu.cn/images/titr.svg) no-repeat center; background-size: 24px 11px; display: inline-block; margin-left: 0; vertical-align: middle; } /* Swiper容器样式 */ .activity-swiper-container { position: relative; width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; padding: 9px 54px 12px; /*margin-top: 30px;*/ overflow: hidden; } .activity-swiper { width: 100%; min-width: 0; /*padding: 0 50px 20px 50px;*/ overflow: hidden; } .activity-swiper .swiper-slide { height: auto; min-width: 0; } /* 导航按钮样式 */ .activity-swiper-container .swiper-button-next, .activity-swiper-container .swiper-button-prev { color: var(--color-primary); background: white; width: 40px; height: 40px; top: 72px; margin-top: 0; border-radius: 50%; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); transition: all 0.3s ease; } .activity-swiper-container .swiper-button-next:hover, .activity-swiper-container .swiper-button-prev:hover { background: var(--color-primary); color: white; transform: scale(1.1); } /deep/ .activity-swiper-container .swiper-button-next::after, /deep/ .activity-swiper-container .swiper-button-prev::after { font-size: 16px; font-weight: bold; } /* 进度条不展示,活动通过左右箭头或区域内滚轮浏览。 */ .activity-swiper-container .swiper-pagination { display: none; } .activity-swiper-container .swiper-pagination-progressbar { background: #e0e0e0; border-radius: 2px; } .activity-swiper-container .swiper-pagination-progressbar-fill { background: var(--color-primary); border-radius: 2px; } .activity-swiper .swiper-slide .item { height: auto; position: relative; cursor: pointer; min-width: 0; overflow: hidden; } .activity-swiper .swiper-slide .item .img-box { width: 100%; height: 128px; border-radius: 8px; overflow: hidden; position: relative; } .activity-swiper .swiper-slide .item .img-box .status { position: absolute; left: 0; top: 0; background: #c11623; padding: 4px 2px; min-width: 42px; color: #ffffff; border-radius: 0 0 50% 0; font-size: 12px; line-height: 1.2; } .activity-swiper .swiper-slide .item .img-box img { display: block; width: 100% !important; height: 100% !important; max-width: 100% !important; max-height: 128px !important; object-fit: fill !important; transition: transform 0.3s ease; } .activity-swiper .swiper-slide .item:hover .img-box img { transform: scale(1.1); } .activity-swiper .swiper-slide .item h4 { font-size: 15px; margin: 8px 0 0; height: 42px; color: #333; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; text-align: left; transition: color 0.3s ease; } .activity-swiper .swiper-slide .item:hover h4 { color: var(--color-primary); } .activity-swiper .swiper-slide .item .time { /*margin-top: 8px;*/ } .activity-swiper .swiper-slide .item .time p { font-size: 12px; margin: 0; line-height: 1.4; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .activity-swiper .swiper-slide .item .time i { margin-right: 4px; color: var(--color-primary); } /* 无活动占位提示 */ .no-activity-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 20px; color: #94a3b8; text-align: center; } .no-activity-placeholder .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.6; } .no-activity-placeholder p { margin: 4px 0 0; font-size: 16px; font-weight: 500; } .no-activity-placeholder .subtext { font-size: 13px; opacity: 0.8; } ` };