|
|
@ -2,10 +2,13 @@ |
|
|
|
import dayjs from '../../utils/dayjs/index.js' |
|
|
|
import relativeTime from '../../utils/dayjs/relativeTime.js' |
|
|
|
dayjs.extend(relativeTime); |
|
|
|
import { HomeModel} from '../../models/home.js' |
|
|
|
import { HomeModel } from '../../models/home.js' |
|
|
|
let homeModel = new HomeModel() |
|
|
|
Page({ |
|
|
|
data: { |
|
|
|
currPage: 1, |
|
|
|
banners: [], |
|
|
|
hots: [], |
|
|
|
list: [ |
|
|
|
{ |
|
|
|
id: '1', |
|
|
@ -31,30 +34,121 @@ Page({ |
|
|
|
console.log(dayjs().toNow()) |
|
|
|
console.log(dayjs().from(dayjs('1990'))) |
|
|
|
this.fetchHomeList() |
|
|
|
this.fetchHomeBanner() |
|
|
|
this.fetchHomeHot() |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 页面相关事件处理函数--监听用户下拉动作 |
|
|
|
*/ |
|
|
|
onPullDownRefresh: function () { |
|
|
|
this.setData({ |
|
|
|
currPage: 1, |
|
|
|
}) |
|
|
|
this.fetchHomeList() |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 页面上拉触底事件的处理函数 |
|
|
|
*/ |
|
|
|
onReachBottom: function () { |
|
|
|
const page = this.data.currPage + 1 |
|
|
|
this.setData({ |
|
|
|
currPage: page |
|
|
|
}) |
|
|
|
this.fetchHomeList() |
|
|
|
}, |
|
|
|
// 获取首页列表
|
|
|
|
fetchHomeList () { |
|
|
|
homeModel.getHomeList(res => { |
|
|
|
fetchHomeList() { |
|
|
|
let page = this.data.currPage |
|
|
|
homeModel.getHomeList(page, res => { |
|
|
|
console.log('啦啦啦') |
|
|
|
const datas = res.result.records |
|
|
|
let tempDatas = [] |
|
|
|
datas.forEach(item => { |
|
|
|
tempDatas.push({ |
|
|
|
id: item.id, |
|
|
|
title: item.title, |
|
|
|
showTop: item.isTop == 1 ? true : false, |
|
|
|
time: dayjs(item.createTime).toNow(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
if (page == 1) { |
|
|
|
this.setData({ |
|
|
|
list: tempDatas |
|
|
|
}) |
|
|
|
} else { |
|
|
|
if (tempDatas.length > 0) { |
|
|
|
const list = [...this.data.list, ...tempDatas] |
|
|
|
this.setData({ |
|
|
|
list: list |
|
|
|
}) |
|
|
|
} else { |
|
|
|
const page = this.data.currPage - 1 |
|
|
|
this.setData({ |
|
|
|
currPage: page |
|
|
|
}) |
|
|
|
wx.showToast({ |
|
|
|
title: '已加载全部', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
console.log(res) |
|
|
|
wx.stopPullDownRefresh() |
|
|
|
}) |
|
|
|
}, |
|
|
|
fetchHomeBanner() { |
|
|
|
homeModel.getHomeBanner(res => { |
|
|
|
console.log('Banner') |
|
|
|
console.log(res) |
|
|
|
const datas = res.result.records |
|
|
|
let tempBanners = [] |
|
|
|
datas.forEach(item => { |
|
|
|
console.log(item) |
|
|
|
tempBanners.push({ |
|
|
|
id: item.id, |
|
|
|
image: 'http://m.360buyimg.com/mobilecms/s700x280_jfs/t1/45210/40/7669/143615/5d53b19dEc9559d0a/cd9eade239533517.jpg!cr_1125x445_0_171!q70.jpg.dpg' |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
banners: tempBanners |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
fetchHomeHot() { |
|
|
|
homeModel.getHomeHot(res => { |
|
|
|
console.log('Hot') |
|
|
|
console.log(res) |
|
|
|
const datas = res.result.records |
|
|
|
let tempHots = [] |
|
|
|
datas.forEach(item => { |
|
|
|
tempHots.push({ |
|
|
|
id: item.id, |
|
|
|
title: item.title |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
hots: tempHots |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
tapSwiperItem (e) { |
|
|
|
// Banner/Hot/List事件
|
|
|
|
tapSwiperItem(e) { |
|
|
|
console.log(e.detail) |
|
|
|
this.gotoArticePage(e.detail.id) |
|
|
|
}, |
|
|
|
tapFocusItem (e) { |
|
|
|
tapFocusItem(e) { |
|
|
|
console.log(e.detail) |
|
|
|
this.gotoArticePage(e.detail.id) |
|
|
|
}, |
|
|
|
clickListItem (e) { |
|
|
|
clickListItem(e) { |
|
|
|
console.log(e.detail) |
|
|
|
this.gotoArticePage(e.detail.id) |
|
|
|
// wx.redirectTo({
|
|
|
|
// url: '/pages/register/index',
|
|
|
|
// })
|
|
|
|
}, |
|
|
|
gotoArticePage (id) { |
|
|
|
gotoArticePage(id) { |
|
|
|
wx.navigateTo({ |
|
|
|
url: `/pages/article/index?id=${id}`, |
|
|
|
}) |
|
|
|