xz_dingjie/pages/index/index.js

296 lines
7.1 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) {
2022-11-10 10:22:40 +08:00
app.restAjax.post(app.restAjax.path('{url}/wechat-miniapp/sign/default', [app.loginUrl]), {
2020-06-26 11:52:30 +08:00
jsCode: res.code
}, null, function (code, data) {
2022-11-10 10:22:40 +08:00
console.log(data)
2020-06-26 11:52:30 +08:00
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 {
2022-11-10 10:22:40 +08:00
console.log(res)
2022-11-16 14:44:04 +08:00
app.dialog.msg('登录失败!' + res.errMsg);
2020-06-23 19:14:44 +08:00
}
}
})
},
2022-11-16 14:44:04 +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
2022-11-16 14:44:04 +08:00
}, null, function (code, data) {
2020-06-26 11:52:30 +08:00
self.setData({
2020-07-13 16:10:31 +08:00
'news.bannerList': data.rows
})
2022-11-16 14:44:04 +08:00
}, function (code, data) {
2020-06-26 11:52:30 +08:00
app.dialog.msg(data.msg);
});
},
2022-11-16 14:44:04 +08:00
doGetVenueList: function () {
2020-06-26 19:32:52 +08:00
var self = this;
app.restAjax.get(app.restAjax.path('{venueUrl}/app/venuesinfo/listpagevenuesinforelease', [self.data.venue.venueUrl]), {
page: 1,
2022-11-16 14:44:04 +08:00
rows: 3,
latitude:app.globalData.curLat,
longitude:app.globalData.curLng,
orderKey:"",
}, null, function (code, data) {
for (var i = 0, item; item = data.rows[i++];) {
2020-07-15 14:45:24 +08:00
item.venuePanoramaArray = item.venuePanorama.split(',');
}
2020-06-26 19:32:52 +08:00
self.setData({
'venue.venueList': data.rows
});
2022-11-16 14:44:04 +08:00
}, function (code, data) {
2020-06-26 11:52:30 +08:00
app.dialog.msg(data.msg);
});
},
2022-11-16 14:44:04 +08:00
doGetActivityList: function () {
2020-06-26 19:32:52 +08:00
var self = this;
app.restAjax.get(app.restAjax.path('{activityUrl}/app/activitylibrary/listpageactivitylibraryrelease', [self.data.activity.activityUrl]), {
page: 1,
rows: 3
2022-11-16 14:44:04 +08:00
}, null, function (code, data) {
2022-11-10 10:22:40 +08:00
console.log(data);
2022-11-16 14:44:04 +08:00
for (var i = 0, item; item = data.rows[i++];) {
2020-07-15 14:45:24 +08:00
item.activityImageArray = item.activityImage.split(',');
}
2020-06-26 19:32:52 +08:00
self.setData({
'activity.activityList': data.rows
});
2022-11-16 14:44:04 +08:00
}, function (code, data) {
2020-06-26 19:32:52 +08:00
app.dialog.msg(data.msg);
});
2020-06-26 11:52:30 +08:00
},
2022-11-16 14:44:04 +08:00
doGetNewsList: function () {
2020-06-26 11:52:30 +08:00
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
2022-11-16 14:44:04 +08:00
}, null, function (code, data) {
2020-06-26 11:52:30 +08:00
self.setData({
'news.newsList': data.rows
})
2022-11-16 14:44:04 +08:00
}, function (code, data) {
2020-06-26 11:52:30 +08:00
app.dialog.msg(data.msg);
});
},
2022-11-16 14:44:04 +08:00
doGetLiveList: function () {
2020-06-26 19:32:52 +08:00
var self = this;
app.restAjax.get(app.restAjax.path('{liveUrl}/app/liveplan/listpageliveplanrelease', [self.data.live.liveUrl]), {
page: 1,
rows: 4
2022-11-16 14:44:04 +08:00
}, null, function (code, data) {
2020-06-26 19:32:52 +08:00
self.setData({
'live.liveList': data.rows
})
2022-11-16 14:44:04 +08:00
}, function (code, data) {
2020-06-26 19:32:52 +08:00
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({
2022-11-16 14:44:04 +08:00
url: '../newsDetail/newsDetail?templateRecordUrl=' + event.currentTarget.dataset.templateRecordUrl,
2020-06-23 19:14:44 +08:00
})
},
2022-11-16 14:44:04 +08:00
goNewsList: function (event) {
2020-06-26 12:33:13 +08:00
wx.navigateTo({
2022-11-16 14:44:04 +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',
})
},
2022-11-16 14:44:04 +08:00
goVenueDetail: function (event) {
2020-07-15 14:45:24 +08:00
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({
2022-11-16 14:44:04 +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',
})
},
2022-11-16 14:44:04 +08:00
goActivityDetail: function (event) {
2020-07-15 14:45:24 +08:00
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',
})
},
2022-11-16 14:44:04 +08:00
goCultureDetail: function (event) {
2020-07-11 20:20:55 +08:00
wx.navigateTo({
2022-11-16 14:44:04 +08:00
url: '../cultureDetail/cultureDetail?libraryId=' + event.currentTarget.dataset.libraryId,
2020-07-11 20:20:55 +08:00
})
},
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-10-09 16:57:41 +08:00
goResource: function () {
wx.navigateTo({
url: '../resource/resource',
})
},
2020-06-23 19:14:44 +08:00
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var self = this;
2022-11-16 14:44:04 +08:00
wx.getLocation({
type: 'gcj02',
success(res) {
// const latitude = res.latitude
// const longitude = res.longitude
// const speed = res.speed
// const accuracy = res.accuracy
app.globalData.curLng=res.longitude
app.globalData.curLat=res.latitude
}
})
2020-06-23 19:14:44 +08:00
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
}
})