添加轮播图
This commit is contained in:
@@ -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
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user