index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // miniprogram/pages/home/index.js
  2. import {
  3. httpOrther
  4. } from "../../utils/httpFunc";
  5. const {
  6. globalData
  7. } = getApp();
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. iconList: [],
  14. headTitle: ""
  15. },
  16. activity: "",
  17. clickFunc(data) {
  18. const index = data.currentTarget.dataset.index;
  19. const item = this.data.iconList[index];
  20. let url = ""
  21. if (!item.type) return;
  22. const parames = `?title=${item.text}&activity=${this.activity}`
  23. switch (item.type) {
  24. case 'live':
  25. url = '/pages/livelist/index' + parames + "&mediaType=" + item.type;
  26. break;
  27. case 'image':
  28. case 'video':
  29. url = '/pages/mediaController/index' + parames + "&mediaType=" + item.type;
  30. break;
  31. case "schedule":
  32. url = '/pages/schedule/index' + parames + '&noToday=1';
  33. break;
  34. case "article_china":
  35. case "article_media":
  36. url = '/pages/articleList/index' + parames + '&type=' + item.type;
  37. break;
  38. default:
  39. url = '/pages/detail/detail' + parames + "&id=" + item.id;
  40. break;
  41. }
  42. wx.navigateTo({
  43. url
  44. })
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */
  49. onLoad: function (options) {
  50. if (options.title) {
  51. this.activity = decodeURIComponent(options.title)
  52. wx.setNavigationBarTitle({
  53. title: this.activity
  54. });
  55. }
  56. const _this = this;
  57. httpOrther({
  58. url: `/Applets/shengshizhongguo/json/${(options.url || 'shengshi') + globalData.miniProgram.envVersion}.json?${Date.now()}`,
  59. call(res) {
  60. _this.setData({
  61. iconList: res.list || [],
  62. headTitle: res.headTitle || '',
  63. headImage: res.headImage || ''
  64. })
  65. }
  66. })
  67. },
  68. /**
  69. * 生命周期函数--监听页面初次渲染完成
  70. */
  71. onReady: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面显示
  75. */
  76. onShow: function () {
  77. wx.hideHomeButton()
  78. },
  79. /**
  80. * 生命周期函数--监听页面隐藏
  81. */
  82. onHide: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面卸载
  86. */
  87. onUnload: function () {
  88. },
  89. /**
  90. * 页面相关事件处理函数--监听用户下拉动作
  91. */
  92. onPullDownRefresh: function () {
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. */
  97. onReachBottom: function () {
  98. },
  99. /**
  100. * 用户点击右上角分享
  101. */
  102. onShareAppMessage: function () {
  103. return {
  104. title: "", // 分享名称
  105. path: 'pages/home/index', // 点击分享后的链接要来到的页面的路径已经对应需要的参数
  106. }
  107. }
  108. })