添加轮播图

This commit is contained in:
Dev
2026-10-15 16:25:51 +08:00
parent 3bc5ea70fe
commit 373ac94411
9 changed files with 154 additions and 41 deletions
@@ -4,8 +4,8 @@
<t-swiper wx:if="{{details.images.length > 0}}" height="750rpx" current="{{current}}" autoplay="{{autoplay}}" duration="{{duration}}" interval="{{interval}}" navigation="{{navigation}}" list="{{details.images}}"></t-swiper>
</view>
<view class="goods-info">
<view class="goods-number">
<view class="goods-price">
<view class="goods-number" wx:if="{{!caseView || soldNum > 0}}">
<view class="goods-price" wx:if="{{!caseView}}">
<price wr-class="class-goods-price" symbol-class="class-goods-symbol" price="{{minSalePrice}}" type="lighter" />
<view class="goods-price-up">起</view>
<price wr-class="class-goods-del" price="{{maxLinePrice}}" type="delthrough" />
+48 -16
View File
@@ -1,4 +1,4 @@
import { fetchHome, fetchConfig } from '../../services/home/home';
import { fetchConfig, fetchHomeBanners } from '../../services/home/home';
import { fetchPerson } from '../../services/usercenter/fetchPerson';
import { withPromoter, promoterQuery } from '../../utils/promoter';
@@ -25,7 +25,16 @@ Page({
img1: '',
img2: '',
img3: '',
tabList: [],
bannerList: [], // 首页轮播,项含 value/title/subtitle
bannerCurrent: 0, // 当前轮播下标
currentBanner: {}, // 当前轮播的标题数据
bannerNavigation: {
type: 'dots',
minShowNum: 2,
},
bannerImageProps: {
mode: 'aspectFill',
},
},
demandListPagination: {
@@ -81,23 +90,35 @@ Page({
});
},
loadHomePage() {
wx.stopPullDownRefresh();
async loadHomePage() {
this.setData({
pageLoading: true
pageLoading: true,
});
fetchConfig().then(
(res) => {
console.log(res);
if (res.code == 1) {
let resData = res.data;
this.setData({
pageLoading: false,
tabList: resData.developTypes
});
}
try {
const [configRes, bannerRes] = await Promise.all([fetchConfig(), fetchHomeBanners()]);
const next = { pageLoading: false };
if (configRes.code === 1) {
next.tabList = configRes.data.developTypes || [];
}
);
if (bannerRes.code === 1) {
const bannerList = (bannerRes.data || []).map((item) => ({
value: item.image || '',
ariaLabel: item.name || '',
title: item.name || '',
subtitle: item.description || '',
}));
next.bannerList = bannerList;
next.bannerCurrent = 0;
next.currentBanner = bannerList[0] || {};
}
this.setData(next);
} catch (err) {
console.error('loadHomePage failed:', err);
this.setData({ pageLoading: false });
wx.showToast({ title: '网络异常,请重试', icon: 'none' });
} finally {
wx.stopPullDownRefresh();
}
},
toSubscribe() {
@@ -134,6 +155,17 @@ Page({
});
},
onBannerChange(e) {
const current = Number((e.detail && e.detail.current) || 0);
if (current === this.data.bannerCurrent) {
return;
}
this.setData({
bannerCurrent: current,
currentBanner: this.data.bannerList[current] || {},
});
},
navToActivityDetail({
detail
}) {
-2
View File
@@ -15,8 +15,6 @@
"t-tab-panel": "tdesign-miniprogram/tab-panel/tab-panel",
"goods-list": "/components/goods-list/index",
"load-more": "/components/load-more/index",
"t-grid": "tdesign-miniprogram/grid/grid",
"t-grid-item": "tdesign-miniprogram/grid-item/grid-item",
"t-cell": "tdesign-miniprogram/cell/cell",
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group",
"t-button": "tdesign-miniprogram/button/button",
+18 -11
View File
@@ -12,17 +12,24 @@
<t-tab-panel wx:for="{{tabList}}" wx:for-index="index" wx:if="{{item.key != -1}}" wx:key="index" label="{{item.text}}" value="{{item.key}}" />
</t-tabs>
</view>
<view class="home-card entry-card">
<t-grid class="block" column="{{4}}" theme="card" border="{{false}}">
<t-grid-item text="Python" image="/assets/image/Python.png" />
<t-grid-item text="C" image="/assets/image/C.png" />
<t-grid-item text="C++" image="/assets/image/C__.png" />
<t-grid-item text="C#" image="/assets/image/C_.png" />
<t-grid-item text="Java" image="/assets/image/Java.png" />
<t-grid-item text="JavaScript" image="/assets/image/JavaScript.png" />
<t-grid-item text="PHP" image="/assets/image/PHP.png" />
<t-grid-item text="Go" image="/assets/image/Go.png" />
</t-grid>
<view class="home-card entry-card" wx:if="{{bannerList.length > 0}}">
<view class="entry-swiper">
<t-swiper
autoplay="{{true}}"
duration="{{500}}"
interval="{{5000}}"
navigation="{{bannerNavigation}}"
paginationPosition="top-right"
imageProps="{{bannerImageProps}}"
list="{{bannerList}}"
height="416rpx"
bind:change="onBannerChange"
/>
<view class="entry-swiper__caption" wx:if="{{currentBanner.title || currentBanner.subtitle}}">
<view class="entry-swiper__title" wx:if="{{currentBanner.title}}">{{currentBanner.title}}</view>
<view class="entry-swiper__subtitle" wx:if="{{currentBanner.subtitle}}">{{currentBanner.subtitle}}</view>
</view>
</view>
</view>
<view class="home-card guarantee-card">
<t-cell title="平台保障" bind:click="toSubscribe" description="3分钟客服响应 平台监管售后" align="top" image="/assets/image/baozhang.png" hover bordered="{{false}}" />
+45 -2
View File
@@ -97,9 +97,52 @@ page {
margin-bottom: 24rpx;
}
/* 语言入口宫格 */
/* 首页轮播:高度对齐原两行编程语言宫格(单项 192rpx × 2 + 卡片上下内边距 32rpx) */
.entry-card {
padding: 16rpx 8rpx;
padding: 0;
}
.entry-swiper {
position: relative;
height: 416rpx;
--td-swiper-radius: var(--radius-lg);
--td-swiper-nav-dot-color: rgba(255, 255, 255, 0.55);
--td-swiper-nav-dot-active-color: #ffffff;
}
.entry-swiper__caption {
position: absolute;
left: 0;
right: 0;
bottom: 0;
z-index: 2;
padding: 48rpx 24rpx 24rpx;
background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.62) 100%);
pointer-events: none;
}
.entry-swiper__title {
font-size: 32rpx;
font-weight: 600;
line-height: 44rpx;
color: #ffffff;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.entry-swiper__title + .entry-swiper__subtitle {
margin-top: 12rpx;
}
.entry-swiper__subtitle {
font-size: 24rpx;
line-height: 34rpx;
color: rgba(255, 255, 255, 0.9);
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
/* 平台保障 */
+5
View File
@@ -57,6 +57,11 @@ export function fetchConfig() {
return wx.$util.request(wx.$api.CommonGetMiniConfig, {}, 'GET');
}
/** 获取首页轮播(分类类型 banner) */
export function fetchHomeBanners() {
return wx.$util.request(wx.$api.CatalogList, { type: 'banner' }, 'GET');
}
// 与后端 site.platform_commission_ratio 默认值一致,接口失败时兜底
const DEFAULT_COMMISSION_RATIO = 0.1;
let commissionRatioCache = null;