import { getbannerList } from '~/services/home/getbannerList'; import { getNoticeList } from '~/services/home/getNoticeList'; import { getSearchRecList } from '~/services/home/getSearchRecList'; import { getHotEmotionCategoryList, getEmoticonDataList, } from '~/services/emoticon/index'; import Toast from 'tdesign-miniprogram/toast/index'; Page({ data: { imgSrcs: [], tabList: [{ text: "精选推荐", key: 0, categoryGuid: 1, }], hotCategoryList: [], lastUpdatedList: [], noticeList: [], popularWords: [], pageLoading: false, current: 0, autoplay: true, duration: '500', interval: 5000, navigation: { type: 'dots', }, swiperImageProps: { mode: 'scaleToFill', }, categoryGuid: 0, loadMoreStatus: 0 }, page: { size: 20, num: 1, }, privateData: { tabIndex: 0, }, onShow() { this.getTabBar().init(); }, onLoad() { this.init(); }, // 划到底部触发 onReachBottom() { this.getEmocticonLastData() }, onPullDownRefresh() { this.init(); }, init() { this.loadHomePage(); }, loadHomePage() { wx.stopPullDownRefresh(); this.setData({ pageLoading: true, }); this.getBanner() this.getRec() // this.getNotice() this.getHot() this.getEmocticonLastData() }, getBanner() { // 获取轮播图列表 getbannerList().then((res) => { if (res.code == 200) { this.setData({ imgSrcs: res.data.map((v) => v.bannerImg), }); } }); }, getRec() { // 获取搜索推荐 getSearchRecList().then((res) => { if (res.code == 200) { this.setData({ popularWords: res.data, pageLoading: false }); } else {} }); }, getHot() { // 获取热门表情包分类列表 getHotEmotionCategoryList().then((res) => { if (res.code == 200) { this.setData({ hotCategoryList: res.data, }); } else {} }); }, getEmocticonLastData() { const params = { pageSize: this.page.size, pageNum: this.page.num, isLastUpdate: true }; this.setData({ loadMoreStatus: 1, }); // 获取最近更新表情包列表 getEmoticonDataList(params).then((res) => { if (res.code == 200) { this.page.num++; this.setData({ lastUpdatedList: this.data.lastUpdatedList.concat(res.data.result), loadMoreStatus: 0 }); } else {} }); }, getNotice() { // 获取公告列表 getNoticeList().then((res) => { if (res.code == 200) { const _noticeData = res.data.map((v) => { return { ...v, visible: true }; }); this.setData({ noticeList: _noticeData, pageLoading: false }); } }); }, navToSearchPage() { wx.navigateTo({ url: '/pages/home/search/index', }); }, // 点击搜索推荐 handleRecTap(e) { const { dataset } = e.currentTarget; const _searchValue = dataset?.value; if (_searchValue) { wx.navigateTo({ url: `/pages/emoticon/result/index?searchValue=${_searchValue}`, }); } }, // 点击热门分类 handleClickHotCategory(e) { const { dataset } = e.currentTarget; const _searchValue = dataset?.value; if (_searchValue) { wx.navigateTo({ url: `/pages/emoticon/result/index?searchValue=${_searchValue}`, }); } }, //点击全部 handleClickAll() { wx.navigateTo({ url: `/pages/emoticon/result/index`, }); }, });