xz_dingjie/pages/index/index.js

274 lines
6.5 KiB
JavaScript
Raw Normal View History

2020-06-26 11:52:30 +08:00
var app = getApp();
2020-06-23 19:14:44 +08:00
Page({
/**
* 页面的初始数据
*/
data: {
2020-08-27 09:57:24 +08:00
randomName: true,
2020-07-16 16:29:47 +08:00
showPhone: true,
gotCode: false,
restTime: 120,
2020-07-16 16:29:47 +08:00
timer: '',
2020-06-23 19:14:44 +08:00
indicatorDots: true,
autoplay: true,
token: '',
2020-06-26 11:52:30 +08:00
news: {
newsUrl: app.newsUrl,
2020-07-13 16:10:31 +08:00
bannerList: [],
2020-06-26 11:52:30 +08:00
newsList: []
},
venue: {
2020-06-26 19:32:52 +08:00
venueUrl: app.venueUrl,
venueList: []
2020-06-26 11:52:30 +08:00
},
activity: {
2020-06-26 19:32:52 +08:00
activityUrl: app.activityUrl,
activityList: []
2020-06-26 19:32:52 +08:00
},
live: {
liveUrl: app.liveUrl,
liveList: []
2020-07-16 16:29:47 +08:00
},
usercenterUrl: app.usercenterUrl,
isConfirm: false
2020-06-26 11:52:30 +08:00
},
doLogin: function () {
2020-06-23 19:14:44 +08:00
var self = this;
wx.login({
success(res) {
2020-06-26 11:52:30 +08:00
if (res.code) {
app.restAjax.post(app.restAjax.path('{url}/wxminiapp/auth/login', [app.loginUrl]), {
jsCode: res.code
}, null, function (code, data) {
var tokenArray = data.data.split('_');
var token = tokenArray[0];
var isRandomUsername = tokenArray[1];
self.setData({
token: token
})
wx.setStorageSync('token', token);
wx.setStorageSync('isRandomUsername', isRandomUsername)
}, function (code, data) {
app.dialog.msg(data.msg);
});
} else {
2020-06-26 12:33:13 +08:00
app.dialog.msg('登录失败!'+ res.errMsg);
2020-06-23 19:14:44 +08:00
}
}
})
},
2020-07-13 16:10:31 +08:00
doGetBanner: function() {
2020-06-26 11:52:30 +08:00
var self = this;
2020-07-13 16:10:31 +08:00
app.restAjax.get(app.restAjax.path('{newsUrl}/app/newscontent/listpagenewscontentrelease', [self.data.news.newsUrl]), {
newsDirectoriesId: 'eab0ca3c-d35d-4c02-9397-ace2bdd10fc1',
2020-06-26 11:52:30 +08:00
page: 1,
rows: 5
}, null, function(code, data) {
self.setData({
2020-07-13 16:10:31 +08:00
'news.bannerList': data.rows
})
}, function(code, data) {
2020-06-26 11:52:30 +08:00
app.dialog.msg(data.msg);
});
},
2020-06-26 19:32:52 +08:00
doGetVenueList: function() {
var self = this;
app.restAjax.get(app.restAjax.path('{venueUrl}/app/venuesinfo/listpagevenuesinforelease', [self.data.venue.venueUrl]), {
page: 1,
rows: 3
2020-06-26 11:52:30 +08:00
}, null, function(code, data) {
2020-07-15 14:45:24 +08:00
for(var i = 0, item; item = data.rows[i++];) {
item.venuePanoramaArray = item.venuePanorama.split(',');
}
2020-06-26 19:32:52 +08:00
self.setData({
'venue.venueList': data.rows
});
2020-06-26 11:52:30 +08:00
}, function(code, data) {
app.dialog.msg(data.msg);
});
},
2020-06-26 19:32:52 +08:00
doGetActivityList: function() {
var self = this;
app.restAjax.get(app.restAjax.path('{activityUrl}/app/activitylibrary/listpageactivitylibraryrelease', [self.data.activity.activityUrl]), {
page: 1,
rows: 3
}, null, function(code, data) {
2020-07-15 14:45:24 +08:00
for(var i = 0, item; item = data.rows[i++];) {
item.activityImageArray = item.activityImage.split(',');
}
2020-06-26 19:32:52 +08:00
self.setData({
'activity.activityList': data.rows
});
}, function(code, data) {
app.dialog.msg(data.msg);
});
2020-06-26 11:52:30 +08:00
},
doGetNewsList: function() {
var self = this;
app.restAjax.get(app.restAjax.path('{newsUrl}/app/newscontent/listpagenewscontentrelease', [self.data.news.newsUrl]), {
2020-07-13 16:10:31 +08:00
newsDirectoriesParentId: 'f497904b-7727-4832-891c-604c36ae4167',
2020-06-26 11:52:30 +08:00
page: 1,
rows: 5
}, null, function(code, data) {
self.setData({
'news.newsList': data.rows
})
}, function(code, data) {
app.dialog.msg(data.msg);
});
},
2020-06-26 19:32:52 +08:00
doGetLiveList: function() {
var self = this;
app.restAjax.get(app.restAjax.path('{liveUrl}/app/liveplan/listpageliveplanrelease', [self.data.live.liveUrl]), {
page: 1,
rows: 4
}, null, function(code, data) {
self.setData({
'live.liveList': data.rows
})
}, function(code, data) {
app.dialog.msg(data.msg);
});
},
2020-06-30 19:38:22 +08:00
goNewsDetail: function (event) {
2020-06-23 19:14:44 +08:00
wx.navigateTo({
2020-06-30 19:38:22 +08:00
url: '../newsDetail/newsDetail?templateRecordUrl='+ event.currentTarget.dataset.templateRecordUrl,
2020-06-23 19:14:44 +08:00
})
},
2020-07-15 14:07:26 +08:00
goNewsList: function(event) {
2020-06-26 12:33:13 +08:00
wx.navigateTo({
2020-07-15 14:07:26 +08:00
url: '../newsList/newsList?type='+ event.currentTarget.dataset.type,
2020-06-26 12:33:13 +08:00
})
},
2020-06-23 19:14:44 +08:00
goVolunteer: function () {
wx.navigateTo({
url: '../volunteer/volunteer',
})
},
goBroadcast: function () {
wx.navigateTo({
url: '../broadcast/broadcast',
})
},
goVenue: function () {
wx.switchTab({
url: '../venue/venue',
})
},
2020-07-15 14:45:24 +08:00
goVenueDetail: function(event) {
wx.navigateTo({
url: '../venueDetail/venueDetail?venuesInfoId=' + event.currentTarget.dataset.venuesInfoId,
})
},
2020-06-28 20:16:24 +08:00
goBroadcastDetail: function (event) {
2020-06-23 19:14:44 +08:00
wx.navigateTo({
2020-06-28 20:16:24 +08:00
url: '../broadcastDetail/broadcastDetail?livePlanId='+ event.currentTarget.dataset.livePlanId,
2020-06-23 19:14:44 +08:00
})
},
goActivity: function () {
wx.switchTab({
url: '../activity/activity',
})
},
2020-07-15 14:45:24 +08:00
goActivityDetail: function(event) {
wx.navigateTo({
url: '../activityDetail/activityDetail?id=' + event.currentTarget.dataset.activityLibraryId
})
},
2020-06-23 19:14:44 +08:00
goHeritage: function () {
wx.switchTab({
url: '../heritage/heritage',
})
},
2020-07-11 20:20:55 +08:00
goCultureDetail: function(event) {
wx.navigateTo({
url: '../cultureDetail/cultureDetail?libraryId='+ event.currentTarget.dataset.libraryId,
})
},
2020-09-29 17:05:43 +08:00
// 获取用户信息
getUserInfo: function () {
2020-07-16 16:29:47 +08:00
var self = this
2020-09-29 17:05:43 +08:00
app.restAjax.get(app.restAjax.path('{usercenterUrl}/app/user/getappuser', [app.usercenterUrl]), {}, {
2020-07-16 16:29:47 +08:00
headers: {
token: self.data.token
}
}, function (code, data) {
self.setData({
2020-09-29 17:05:43 +08:00
userInfo: data
2020-07-16 16:29:47 +08:00
})
}, function (code, data) {
app.dialog.msg(data.msg);
2020-07-16 16:29:47 +08:00
})
},
2020-09-29 17:05:43 +08:00
goTrain: function () {
wx.navigateTo({
url: '../train/train',
2020-07-16 16:29:47 +08:00
})
},
2020-09-29 17:05:43 +08:00
goTravel: function () {
wx.navigateTo({
url: '../travel/travel',
2020-07-16 16:29:47 +08:00
})
},
2020-06-23 19:14:44 +08:00
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var self = this;
self.doLogin();
2020-07-13 16:10:31 +08:00
self.doGetBanner();
2020-06-26 11:52:30 +08:00
self.doGetNewsList();
2020-08-27 09:57:24 +08:00
self.doGetLiveList();
2020-06-26 19:32:52 +08:00
self.doGetVenueList();
self.doGetActivityList();
2020-06-23 19:14:44 +08:00
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
2020-06-26 11:52:30 +08:00
2020-06-23 19:14:44 +08:00
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
2020-06-26 11:52:30 +08:00
2020-06-23 19:14:44 +08:00
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
2020-06-26 11:52:30 +08:00
2020-06-23 19:14:44 +08:00
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
2020-06-26 11:52:30 +08:00
2020-06-23 19:14:44 +08:00
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
2020-06-26 11:52:30 +08:00
2020-06-23 19:14:44 +08:00
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
2020-06-26 11:52:30 +08:00
2020-06-23 19:14:44 +08:00
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
2020-06-26 11:52:30 +08:00
2020-06-23 19:14:44 +08:00
}
})