home.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // pages/home/home.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. activityList: ["第一季", "第二季"],
  9. select: "1",
  10. pageName: "话题",
  11. tableHead: [],
  12. tabList: [],
  13. tablelist: [],
  14. type: 0,
  15. title: "",
  16. jsonURL: "",
  17. imgURL: "",
  18. indexNum: 0,
  19. isShow: false,
  20. isUpdata: false
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. },
  27. /**
  28. * 生命周期函数--监听页面初次渲染完成
  29. */
  30. onReady: function () {
  31. this.getData();
  32. wx.setStorageSync('nextTime', 0)
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow: function () {
  38. this.setData({
  39. isShow: true
  40. })
  41. },
  42. /**
  43. * 生命周期函数--监听页面隐藏
  44. */
  45. onHide: function () {
  46. this.setData({
  47. isShow: false
  48. })
  49. },
  50. /**
  51. * 生命周期函数--监听页面卸载
  52. */
  53. // onUnload: function () {
  54. // // 返回时触发
  55. // },
  56. /**
  57. * 页面相关事件处理函数--监听用户下拉动作
  58. */
  59. onPullDownRefresh: function () {
  60. },
  61. /**
  62. * 页面上拉触底事件的处理函数
  63. */
  64. onReachBottom: function () {
  65. },
  66. /**
  67. * 用户点击右上角分享
  68. */
  69. onShareAppMessage: function () { },
  70. getData: function (data) {
  71. const _this = this;
  72. wx.request({
  73. url: app.baseUrl + '/overview',
  74. success: function (res) {
  75. if (res.statusCode === 200) {
  76. const tablelist = (res.data || [])
  77. const tab = tablelist.map((v, i) => {
  78. v.child_list = (v.child_list || []).map((val, o) => {
  79. return {
  80. name: val,
  81. type: o,
  82. // worldURL: app.baseUrl + '/data/' + jsonName + ".json",
  83. // worldImgURL: app.baseUrl + '/data/' + img + ".png"
  84. worldImgURL: v.word_cloud_url
  85. }
  86. })
  87. return {
  88. childList: v.child_list,
  89. name: v.topic_name,
  90. type: v.topic_id,
  91. isUpdate: v.is_update,
  92. // worldURL: app.baseUrl + '/data/' + jsonName + ".json",
  93. // worldImgURL: v.word_cloud_url ? v.word_cloud_url : img ? app.baseUrl + '/data/' + img + ".png" : ""
  94. worldImgURL: v.word_cloud_url
  95. }
  96. })
  97. if (_this.data.select === "0")
  98. tab.unshift({
  99. name: "话题对比",
  100. type: -1
  101. })
  102. const setD = {
  103. tabList: tab,
  104. tablelist
  105. }
  106. !_this.data.type && (setD.type = tab[0].type);
  107. !_this.data.title && (setD.title = tab[0].name);
  108. _this.setData(setD)
  109. } else _this.setData({
  110. error: '请重启后查看'
  111. })
  112. },
  113. data,
  114. fail: function (err) {
  115. this.setData({
  116. error: '数据错误'
  117. })
  118. },
  119. complete: function (res) {
  120. }
  121. })
  122. },
  123. changeBar: function (type) {
  124. if (type.detail.title === this.data.title) return;
  125. this.setData({
  126. type: type.detail.type,
  127. title: type.detail.title,
  128. jsonURL: type.detail.worldURL || "",
  129. imgURL: type.detail.worldImgURL || "",
  130. indexNum: type.detail.index || 0,
  131. isUpdata: type.detail.isUpdata
  132. })
  133. },
  134. bindPickerChange(r) {
  135. console.log(r.detail.value)
  136. this.setData({
  137. select: r.detail.value
  138. }, () => {
  139. this.getData()
  140. })
  141. }
  142. })