市北人才赋能平台 --小程序端
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.

215 lines
4.6 KiB

6 years ago
//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'
6 years ago
let homeModel = new HomeModel()
6 years ago
Page({
data: {
loading: true,
currPage: 1,
banners: [],
hots: [],
4 years ago
list: [],
show:false,
4 years ago
// url:"../../images/ad.jpg",
4 years ago
web:'https://wx.vzan.com/live/TpForm?zbid=860533452&oId=213742&type=0&v=1623841891714'
// web:'http://www.rencaibeichu.cn'
6 years ago
},
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()
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
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('啦啦啦')
6 years ago
const datas = res.list
let tempDatas = []
datas.forEach(item => {
tempDatas.push({
id: item.id,
title: item.title,
6 years ago
image: item.titlePic,
showTop: item.isTop == 1 ? true : false,
time: dayjs(item.createTime).toNow(),
4 years ago
type:item.type,
6 years ago
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)
6 years ago
const datas = res.list
let tempBanners = []
datas.forEach(item => {
tempBanners.push({
id: item.id,
6 years ago
image: item.titlePic,
title: item.title
})
})
this.setData({
banners: tempBanners
})
})
},
fetchHomeHot () {
this.setData({
hots: []
})
homeModel.getHomeHot(res => {
//console.log('Hot')
console.log(res)
6 years ago
const datas = res.list
let tempHots = []
datas.forEach(item => {
tempHots.push({
id: item.id,
title: item.title
})
})
this.setData({
hots: tempHots
})
6 years ago
})
6 years ago
},
// Banner/Hot/List事件
tapSwiperItem (e) {
//console.log(e.detail)
4 years ago
if(e.detail.id == '987a8433d925f36d3690fab91fe9e137'){
this.jump()
}else{
this.gotoArticePage(e.detail.id)
}
6 years ago
},
tapFocusItem (e) {
//console.log(e.detail)
6 years ago
this.gotoArticePage(e.detail.id)
},
//点击列表cell获取id,进入页面
clickListItem (e) {
//console.log(e.detail)
4 years ago
console.log('点击---',e)
const {id, index,type} = e.detail
this.setData({
[`list[${index}].readed`]: true
})
4 years ago
//type 文章/活动标识0-文章,1-活动
if(type==0){
6 years ago
this.gotoArticePage(id)
4 years ago
}
else{
this.gotoActivityPage(id)
}
6 years ago
},
4 years ago
//文章 0
gotoArticePage (id) {
6 years ago
wx.navigateTo({
url: `/pages/article/index?id=${id}`,
})
4 years ago
},
4 years ago
//活动 1
gotoActivityPage (id) {
wx.navigateTo({
url: `/pages/topics/activity/activityDetail/index?activityId=${id}`,
})
},
4 years ago
onClose(){
this.setData({
show:false
})
},
jump:function(){
this.setData({
show:false
})
wx.navigateTo({
url: '/pages/resource/navigate/index?url=' + encodeURIComponent(this.data.web)
})
6 years ago
}
6 years ago
})