You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
249 lines
5.2 KiB
249 lines
5.2 KiB
//index.js
|
|
import dayjs from '../../utils/dayjs/index.js'
|
|
import relativeTime from '../../utils/dayjs/relativeTime.js'
|
|
dayjs.extend(relativeTime);
|
|
import {
|
|
HomeModel
|
|
} from '../../models/home.js'
|
|
let homeModel = new HomeModel()
|
|
Page({
|
|
data: {
|
|
loading: true,
|
|
currPage: 1,
|
|
banners: [],
|
|
hots: [],
|
|
list: [],
|
|
show: false,
|
|
// url:"../../images/ad.jpg",
|
|
web: 'https://wx.vzan.com/live/TpForm?zbid=860533452&oId=213742&type=0&v=1623841891714'
|
|
// web:'http://www.rencaibeichu.cn'
|
|
},
|
|
onLoad: function () {
|
|
// const ad = wx.getStorageSync('ad')
|
|
// if(!ad){
|
|
// // wx.redirectTo({
|
|
// // url: '/pages/ad/ad',
|
|
// // })
|
|
// this.setData({
|
|
// show:true
|
|
// })
|
|
// wx.setStorageSync('ad', 1)
|
|
// }
|
|
homeModel.fetchAuthToken(res => {
|
|
//console.log('Home获取token成功后再请求数据')
|
|
this.fetchHomeList()
|
|
this.fetchHomeBanner()
|
|
this.fetchHomeHot()
|
|
})
|
|
|
|
wx.showShareMenu({
|
|
withShareTicket: true,
|
|
menus: ['shareAppMessage']
|
|
});
|
|
},
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
this.setData({
|
|
currPage: 1,
|
|
list: []
|
|
})
|
|
this.fetchHomeList()
|
|
this.fetchHomeBanner()
|
|
this.fetchHomeHot()
|
|
wx.vibrateShort({
|
|
success() {
|
|
//console.log('震动')
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
const page = this.data.currPage + 1
|
|
this.setData({
|
|
currPage: page
|
|
})
|
|
this.fetchHomeList()
|
|
},
|
|
|
|
|
|
|
|
// 获取首页列表
|
|
fetchHomeList() {
|
|
let page = this.data.currPage
|
|
homeModel.getHomeList(page, res => {
|
|
this.setData({
|
|
loading: false
|
|
})
|
|
//console.log('啦啦啦')
|
|
const datas = res.list
|
|
let tempDatas = []
|
|
datas.forEach(item => {
|
|
tempDatas.push({
|
|
id: item.id,
|
|
title: item.title,
|
|
image: item.titlePic,
|
|
showTop: item.isTop == 1 ? true : false,
|
|
time: dayjs(item.createTime).toNow(),
|
|
type: item.type,
|
|
readed: item.isRead == 0 ? false : true
|
|
})
|
|
})
|
|
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() {
|
|
this.setData({
|
|
banners: []
|
|
})
|
|
homeModel.getHomeBanner(res => {
|
|
//console.log('Banner')
|
|
console.log(res)
|
|
const datas = res.list
|
|
let tempBanners = []
|
|
datas.forEach(item => {
|
|
tempBanners.push({
|
|
id: item.id,
|
|
image: item.titlePic,
|
|
title: item.title,
|
|
type: item.type
|
|
})
|
|
})
|
|
this.setData({
|
|
banners: tempBanners
|
|
})
|
|
})
|
|
},
|
|
fetchHomeHot() {
|
|
this.setData({
|
|
hots: []
|
|
})
|
|
homeModel.getHomeHot(res => {
|
|
//console.log('Hot')
|
|
console.log(res)
|
|
const datas = res.list
|
|
let tempHots = []
|
|
datas.forEach(item => {
|
|
tempHots.push({
|
|
id: item.id,
|
|
title: item.title,
|
|
type: item.type
|
|
})
|
|
})
|
|
this.setData({
|
|
hots: tempHots
|
|
})
|
|
})
|
|
},
|
|
// Banner/Hot/List事件
|
|
tapSwiperItem(e) {
|
|
console.log(e)
|
|
const {
|
|
id,
|
|
type
|
|
} = e.detail
|
|
if (e.detail.id == '987a8433d925f36d3690fab91fe9e137') {
|
|
this.jump()
|
|
} else {
|
|
// this.gotoArticePage(e.detail.id)
|
|
if (type == 0) {
|
|
this.gotoArticePage(id)
|
|
} else {
|
|
this.gotoActivityPage(id)
|
|
}
|
|
}
|
|
|
|
},
|
|
tapFocusItem(e) {
|
|
// console.log(e)
|
|
const {
|
|
id,
|
|
title,
|
|
type
|
|
} = e.detail
|
|
//console.log(e.detail)
|
|
// this.gotoArticePage(e.detail.id)
|
|
//type 文章/活动标识0-文章,1-活动
|
|
if (type == 0) {
|
|
this.gotoArticePage(id)
|
|
} else {
|
|
this.gotoActivityPage(id)
|
|
}
|
|
},
|
|
|
|
|
|
//点击列表cell获取id,进入页面
|
|
clickListItem(e) {
|
|
//console.log(e.detail)
|
|
console.log('点击---', e)
|
|
const {
|
|
id,
|
|
index,
|
|
type
|
|
} = e.detail
|
|
this.setData({
|
|
[`list[${index}].readed`]: true
|
|
})
|
|
//type 文章/活动标识0-文章,1-活动
|
|
if (type == 0) {
|
|
this.gotoArticePage(id)
|
|
} else {
|
|
this.gotoActivityPage(id)
|
|
}
|
|
},
|
|
//文章 0
|
|
gotoArticePage(id) {
|
|
wx.navigateTo({
|
|
url: `/pages/article/index?id=${id}`,
|
|
})
|
|
},
|
|
//活动 1
|
|
gotoActivityPage(id) {
|
|
wx.navigateTo({
|
|
url: `/pages/topics/activity/activityDetail/index?activityId=${id}`,
|
|
})
|
|
},
|
|
onClose() {
|
|
this.setData({
|
|
show: false
|
|
})
|
|
},
|
|
jump: function () {
|
|
this.setData({
|
|
show: false
|
|
})
|
|
wx.navigateTo({
|
|
url: '/pages/resource/navigate/index?url=' + encodeURIComponent(this.data.web)
|
|
})
|
|
},
|
|
|
|
|
|
})
|