main.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // pages/main/main.js
  2. import request from '../../utils/request'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. newNoticeTitle:'' //滚动显示的公告标题
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad:async function(options) {
  14. let result = await request('/front/notificationFront') //获取公告列表
  15. // console.log(result);
  16. // 对公告列表按id降序排序(即按发布时间由近到远排序)
  17. if(result.length == 0){
  18. this.setData({
  19. newNoticeTitle:'暂无公告内容'
  20. })
  21. }else if(result.length == 1 && result[0].status == 1){
  22. this.setData({
  23. newNoticeTitle:result[0].title
  24. })
  25. }else if(result.length == 1 && result[0].status == 0){
  26. this.setData({
  27. newNoticeTitle:'暂无公告内容'
  28. })
  29. }
  30. else{
  31. for(let i = 0;i < result.length-1;i++){
  32. for(let j = 0;j < result.length-1-i;j++){
  33. if(result[j].id < result[j+1].id){
  34. let temp = result[j]
  35. result[j] = result[j+1]
  36. result[j+1] = temp
  37. }
  38. }
  39. }
  40. // console.log(result);
  41. // 遍历重新排序后的列表,取出第一个状态为1的标题
  42. for(let i = 0;i < result.length;i++){
  43. if(result[i].status == 1){
  44. this.setData({
  45. newNoticeTitle:result[0].title
  46. })
  47. }
  48. break;
  49. }
  50. }
  51. },
  52. // 跳转到纳溪介绍页面
  53. toMainIntro() {
  54. wx.navigateTo({
  55. url: '/pages/mainIntro/mainIntro',
  56. })
  57. },
  58. //跳转到马村介绍
  59. toSecondIntro() {
  60. wx.navigateTo({
  61. url: '/pages/secondIntro/secondIntro',
  62. })
  63. },
  64. //跳转到景区列表
  65. toScenicList() {
  66. wx.navigateTo({
  67. url: '/pages/scenicList/scenicList',
  68. })
  69. },
  70. //跳转到公告页面
  71. toNotice(){
  72. wx.navigateTo({
  73. url: '/pages/notice/notice',
  74. })
  75. },
  76. // 跳转到推荐美食
  77. toRecommendFood(){
  78. wx.navigateTo({
  79. url: '/pages/recommendFood/recommendFood',
  80. })
  81. },
  82. /**
  83. * 生命周期函数--监听页面初次渲染完成
  84. */
  85. onReady() {
  86. },
  87. /**
  88. * 生命周期函数--监听页面显示
  89. */
  90. onShow() {
  91. },
  92. /**
  93. * 生命周期函数--监听页面隐藏
  94. */
  95. onHide() {
  96. },
  97. /**
  98. * 生命周期函数--监听页面卸载
  99. */
  100. onUnload() {
  101. },
  102. /**
  103. * 页面相关事件处理函数--监听用户下拉动作
  104. */
  105. onPullDownRefresh() {
  106. },
  107. /**
  108. * 页面上拉触底事件的处理函数
  109. */
  110. onReachBottom() {
  111. },
  112. /**
  113. * 用户点击右上角分享
  114. */
  115. onShareAppMessage() {
  116. }
  117. })