206 lines
4.3 KiB
JavaScript
206 lines
4.3 KiB
JavaScript
|
// pages/home/home.js
|
||
|
const app = getApp()
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
indicatorDots: true,
|
||
|
autoplay: true,
|
||
|
venueList: [],
|
||
|
userInfo: {},
|
||
|
hasUserInfo: false,
|
||
|
token: '',
|
||
|
requestIp: '',
|
||
|
swiperList: []
|
||
|
},
|
||
|
getSwiper: function () {
|
||
|
var self = this
|
||
|
wx.request({
|
||
|
url: self.data.requestIp + 'wxminiapp/article/listpagearticlebycategoryrelease',
|
||
|
data: {
|
||
|
articleCategoryId: '64342ca0-bef8-495e-8a2f-89dd54c50086'
|
||
|
},
|
||
|
header: {
|
||
|
"token": self.data.token
|
||
|
},
|
||
|
success: function (res) {
|
||
|
var images = ''
|
||
|
for (var i = 0; i < res.data.rows.length; i++) {
|
||
|
if (i == 0) {
|
||
|
images = images + res.data.rows[i].images
|
||
|
} else {
|
||
|
images = images + ',' + res.data.rows[i].images
|
||
|
}
|
||
|
}
|
||
|
var result = images.split(',')
|
||
|
self.setData({
|
||
|
swiperList: result
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
goDetail: function (event) {
|
||
|
wx.navigateTo({
|
||
|
url: '../detail/detail?venuesInfoId=' + event.currentTarget.dataset.id,
|
||
|
})
|
||
|
},
|
||
|
goBook: function () {
|
||
|
wx.navigateTo({
|
||
|
url: '../index/index',
|
||
|
})
|
||
|
},
|
||
|
goMatch: function () {
|
||
|
wx.navigateTo({
|
||
|
url: '../activity/activity',
|
||
|
})
|
||
|
},
|
||
|
goExercise: function () {
|
||
|
wx.navigateTo({
|
||
|
url: '../exerciseNews/exerciseNews',
|
||
|
})
|
||
|
},
|
||
|
goNews: function () {
|
||
|
wx.navigateTo({
|
||
|
url: '../sportNews/sportNews',
|
||
|
})
|
||
|
},
|
||
|
getList: function () {
|
||
|
var self = this
|
||
|
wx.request({
|
||
|
url: self.data.requestIp + 'app/wechatprogram/listvenuesbykeywords',
|
||
|
header: {
|
||
|
"token": self.data.token
|
||
|
},
|
||
|
success: function (res) {
|
||
|
self.setData({
|
||
|
venueList: res.data.data
|
||
|
})
|
||
|
wx.hideNavigationBarLoading()
|
||
|
wx.stopPullDownRefresh()
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
getUserInfo: function (e) {
|
||
|
app.globalData.userInfo = e.detail.userInfo
|
||
|
this.setData({
|
||
|
userInfo: e.detail.userInfo,
|
||
|
hasUserInfo: true
|
||
|
})
|
||
|
},
|
||
|
doLogin: function(){
|
||
|
var self = this
|
||
|
wx.login({
|
||
|
success(res) {
|
||
|
if (res.code) {
|
||
|
//发起网络请求
|
||
|
wx.request({
|
||
|
url: self.data.requestIp + 'wxminiapp/auth/login',
|
||
|
method: 'post',
|
||
|
data: {
|
||
|
jsCode: res.code
|
||
|
},
|
||
|
success: function (res) {
|
||
|
self.setData({
|
||
|
token: res.data.data
|
||
|
})
|
||
|
wx.setStorage({
|
||
|
key: 'token',
|
||
|
data: res.data.data
|
||
|
})
|
||
|
self.getList()
|
||
|
self.getSwiper()
|
||
|
}
|
||
|
})
|
||
|
} else {
|
||
|
console.log('登录失败!' + res.errMsg)
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
onPullDownRefresh: function () {
|
||
|
wx.showNavigationBarLoading()
|
||
|
this.setData({
|
||
|
venueList: []
|
||
|
})
|
||
|
this.onLoad()
|
||
|
},
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function (options) {
|
||
|
this.setData({
|
||
|
requestIp: app.globalData.requestIp
|
||
|
})
|
||
|
this.doLogin()
|
||
|
if (app.globalData.userInfo) {
|
||
|
this.setData({
|
||
|
userInfo: app.globalData.userInfo,
|
||
|
hasUserInfo: true
|
||
|
})
|
||
|
} else if (this.data.canIUse) {
|
||
|
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
||
|
// 所以此处加入 callback 以防止这种情况
|
||
|
app.userInfoReadyCallback = res => {
|
||
|
this.setData({
|
||
|
userInfo: res.userInfo,
|
||
|
hasUserInfo: true
|
||
|
})
|
||
|
}
|
||
|
} else {
|
||
|
// 在没有 open-type=getUserInfo 版本的兼容处理
|
||
|
wx.getUserInfo({
|
||
|
success: res => {
|
||
|
app.globalData.userInfo = res.userInfo
|
||
|
this.setData({
|
||
|
userInfo: res.userInfo,
|
||
|
hasUserInfo: true
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面初次渲染完成
|
||
|
*/
|
||
|
onReady: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面显示
|
||
|
*/
|
||
|
onShow: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面隐藏
|
||
|
*/
|
||
|
onHide: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面卸载
|
||
|
*/
|
||
|
onUnload: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 用户点击右上角分享
|
||
|
*/
|
||
|
onShareAppMessage: function () {
|
||
|
|
||
|
}
|
||
|
})
|