liveData.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // pages/liveData/liveData.js
  2. const app = getApp();
  3. let peopleList = [{ "time": "13:00", "value": 9944 }, { "time": "14:00", "value": 8920 }, { "time": "15:00", "value": 14656 }, { "time": "16:00", "value": 13084 }];
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. error: "",
  10. detail: "",
  11. diglogTitle: "",
  12. title: "",
  13. headData: {},
  14. lineList: [],
  15. region: [],
  16. series: [],
  17. oriList: [
  18. {
  19. type: 'pie',
  20. label: {
  21. show: false
  22. },
  23. data: [{ value: 1048, name: '百度' }, { value: 735, name: '谷歌' }, { value: 735, name: '360' }, { value: 735, name: '搜狗' }, { value: 735, name: '其他' }]
  24. },
  25. ]
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. this.setData({
  32. title: decodeURIComponent(options.title),
  33. platform: options.platform
  34. }, () => {
  35. this.getData()
  36. })
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload: function () {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh: function () {
  62. },
  63. /**
  64. * 页面上拉触底事件的处理函数
  65. */
  66. onReachBottom: function () {
  67. },
  68. /**
  69. * 用户点击右上角分享
  70. */
  71. onShareAppMessage: function () {
  72. },
  73. formatNumber: function (val) {
  74. let out = val;
  75. if (val >= 1000 && val < 10000) {
  76. out = (val / 1000).toFixed(2) - 0 + "千"
  77. } else if (val >= 10000 && val < 100000000) {
  78. out = (val / 10000).toFixed(0) - 0 + "万"
  79. } else if (val >= 100000000) {
  80. out = (val / 100000000).toFixed(2) - 0 + "亿"
  81. }
  82. return out
  83. },
  84. getData: function () {
  85. let _this = this;
  86. wx.showLoading();
  87. wx.request({
  88. url: app.baseUrl + '/live-result',
  89. data: {
  90. topic: this.data.title,
  91. platform: this.data.platform
  92. },
  93. success: function (res) {
  94. wx.hideLoading()
  95. if (res.statusCode !== 200) return wx.showToast({
  96. title: '请重启小程序',
  97. icon: "error"
  98. })
  99. let oriData = res.data || {};
  100. let region = [];
  101. let trend = oriData.trend || {};
  102. let RealTimeTraffic = {
  103. title: "实时流量",
  104. subTitle: "",
  105. id: 'id' + 10,
  106. canvasId: 'canvasId' + 10,
  107. type: "line",
  108. yType: "value",
  109. xType: "time",
  110. peopleList: []
  111. };
  112. let RealTimePersonTime = {
  113. title: "观看人次",
  114. subTitle: "",
  115. id: 'id' + 11,
  116. canvasId: 'canvasId' + 11,
  117. type: "line",
  118. yType: "value",
  119. xType: "time",
  120. peopleList: []
  121. };
  122. let AddUpFans = {
  123. title: "累计粉丝量",
  124. subTitle: "",
  125. id: 'id' + 12,
  126. canvasId: 'canvasId' + 12,
  127. type: "line",
  128. yType: "value",
  129. xType: "time",
  130. peopleList: []
  131. };
  132. let LikeTheTrend = {
  133. title: "点赞走势",
  134. subTitle: "",
  135. id: 'id' + 13,
  136. canvasId: 'canvasId' + 13,
  137. type: "line",
  138. yType: "value",
  139. xType: "time",
  140. peopleList: []
  141. };
  142. // 实时流量
  143. RealTimeTraffic.subTitle = "在线人数峰值:" + _this.formatNumber((trend.user || {}).user_count || 0) + " 出现时间:" + _this.formatNumber((trend.user || {}).crawl_date || "") + " 平均人数:" + _this.formatNumber((trend.user || {}).avg_user_count || 0);
  144. // 观看人次
  145. RealTimePersonTime.subTitle = _this.formatNumber((trend.user || {}).stats_user_composition_from_my_follow_count || 0) + "人来自关注页面 " + _this.formatNumber((trend.user || {}).stats_user_composition_from_video_detail_count || 0) + "人来自视频推荐";
  146. // 累计粉丝量
  147. AddUpFans.subTitle = "粉丝峰值:" + _this.formatNumber((trend.fans || {}).club_info_total_fans_count || 0) + " 出现在:" + _this.formatNumber((trend.fans || {}).crawl_date || "");
  148. console.log(oriData);
  149. // 点赞走势
  150. LikeTheTrend.subTitle = "点赞峰值:" + _this.formatNumber((trend.like || {}).add_like_count || 0) + " 出现在:" + _this.formatNumber((trend.like || {}).crawl_date || "");
  151. // 趋势图数据
  152. for (let i = 0; i < (trend.webcastTrendList || []).length; i++) {
  153. const v = (trend.webcastTrendList || [])[i];
  154. let time = v.crawl_date.split(" ")[1] || "";
  155. RealTimeTraffic.peopleList.push({
  156. value: _this.formatNumber(v.user_count || 0),
  157. time: time
  158. });
  159. RealTimePersonTime.peopleList.push({
  160. value: _this.formatNumber(v.stats_total_user || 0),
  161. time: time
  162. });
  163. AddUpFans.peopleList.push({
  164. value: _this.formatNumber(v.club_info_total_fans_count || 0),
  165. time: time
  166. });
  167. LikeTheTrend.peopleList.push({
  168. value: _this.formatNumber(v.like_count || 0),
  169. time: time
  170. });
  171. }
  172. console.log(oriData);
  173. // 基础数据
  174. let base = {
  175. msg_count: (oriData.webcastMessageList ? oriData.webcastMessageList.count || 0 : 0),
  176. like_count: (trend.like || {}).add_like_count || 0,
  177. total_fans_count: (trend.fans || {}).club_info_total_fans_count || 0,
  178. peopel_time: (trend.user || {}).stats_total_user || 0
  179. }
  180. console.log(base)
  181. // 来源城市
  182. let city = oriData.city || []
  183. for (let i = 0; i < city.length; i++) {
  184. const element = city[i] || {};
  185. region.push({
  186. name: element.key || "",
  187. value: element.count || 0
  188. })
  189. }
  190. // 性别比
  191. let gender = [];
  192. let oriGender = oriData.gender || [];
  193. for (let i = 0; i < oriGender.length; i++) {
  194. const v = oriGender[i];
  195. gender.push({
  196. name: v.key == "1" ? "男" : "女",
  197. value: v.count
  198. })
  199. }
  200. let p = {
  201. headData: base,
  202. region: [],
  203. series: [],
  204. lineList: []
  205. }
  206. region.length && p.region.push(region);
  207. if (gender.length)
  208. p.series = [
  209. {
  210. type: 'pie',
  211. label: {
  212. position: 'inner',
  213. fontSize: 14,
  214. },
  215. data: gender,
  216. emphasis: {
  217. itemStyle: {
  218. shadowBlur: 10,
  219. shadowOffsetX: 0,
  220. shadowColor: 'rgba(0, 0, 0, 0.5)'
  221. }
  222. }
  223. }
  224. ];
  225. AddUpFans && p.lineList.push(AddUpFans);
  226. LikeTheTrend && p.lineList.push(LikeTheTrend);
  227. RealTimeTraffic && p.lineList.push(RealTimeTraffic);
  228. RealTimePersonTime && p.lineList.push(RealTimePersonTime);
  229. _this.setData(p)
  230. },
  231. fail: function (err) {
  232. wx.hideLoading()
  233. wx.showToast({
  234. title: '请重启小程序',
  235. icon: "error"
  236. })
  237. },
  238. })
  239. }
  240. })