mainIntro.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // pages/index/index.js
  2. import request from '../../utils/request'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. bannersList:[], //后台获取的轮播图列表
  9. intro:'' //后台获取的介绍详情
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad:async function(options) {
  15. // 进入页面时,提示“数据加载中”
  16. wx.showLoading({
  17. title: '数据加载中',
  18. mask:true
  19. })
  20. //获取轮播图
  21. let result = await request('/front/introduce/files/1').catch(err=>{
  22. wx.hideLoading()
  23. wx.showModal({
  24. title: '数据加载失败',
  25. content: '当前网络不佳,请稍后再试',
  26. complete: (res) => {
  27. if (res.cancel) {
  28. wx.navigateBack()
  29. }
  30. if (res.confirm) {
  31. wx.navigateBack()
  32. }
  33. }
  34. })
  35. })
  36. //获取简介信息
  37. let introduce = await request('/front/introduce/1')
  38. this.setData({
  39. bannersList:result,
  40. intro:introduce
  41. })
  42. // 关闭“数据加载中”的提示
  43. if(this.data.bannersList.length != 0 || this.data.intro != ''){
  44. wx.hideLoading()
  45. }else{
  46. setTimeout(function () {
  47. wx.hideLoading()
  48. }, 2000)
  49. }
  50. },
  51. /**
  52. * 生命周期函数--监听页面初次渲染完成
  53. */
  54. onReady() {
  55. },
  56. /**
  57. * 生命周期函数--监听页面显示
  58. */
  59. onShow() {
  60. },
  61. /**
  62. * 生命周期函数--监听页面隐藏
  63. */
  64. onHide() {
  65. },
  66. /**
  67. * 生命周期函数--监听页面卸载
  68. */
  69. onUnload() {
  70. },
  71. /**
  72. * 页面相关事件处理函数--监听用户下拉动作
  73. */
  74. onPullDownRefresh() {
  75. },
  76. /**
  77. * 页面上拉触底事件的处理函数
  78. */
  79. onReachBottom() {
  80. },
  81. /**
  82. * 用户点击右上角分享
  83. */
  84. onShareAppMessage() {
  85. }
  86. })