liveData.js 7.1 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. }, () => {
  34. this.getData()
  35. })
  36. },
  37. /**
  38. * 生命周期函数--监听页面初次渲染完成
  39. */
  40. onReady: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面显示
  44. */
  45. onShow: function () {
  46. },
  47. /**
  48. * 生命周期函数--监听页面隐藏
  49. */
  50. onHide: function () {
  51. },
  52. /**
  53. * 生命周期函数--监听页面卸载
  54. */
  55. onUnload: function () {
  56. this.isUp && clearInterval(this.isUp);
  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. },
  92. success: function (res) {
  93. wx.hideLoading()
  94. if (res.statusCode !== 200) return wx.showToast({
  95. title: '请重启小程序',
  96. icon: "error"
  97. })
  98. let oriData = res.data || {};
  99. let region = [];
  100. let trend = oriData.trend || {};
  101. let RealTimeTraffic = {
  102. title: "实时流量",
  103. subTitle: "",
  104. id: 'id' + 10,
  105. canvasId: 'canvasId' + 10,
  106. type: "line",
  107. yType: "value",
  108. xType: "time",
  109. peopleList: []
  110. };
  111. let RealTimePersonTime = {
  112. title: "观看人次",
  113. subTitle: "",
  114. id: 'id' + 11,
  115. canvasId: 'canvasId' + 11,
  116. type: "line",
  117. yType: "value",
  118. xType: "time",
  119. peopleList: []
  120. };
  121. let AddUpFans = {
  122. title: "累计粉丝量",
  123. subTitle: "",
  124. id: 'id' + 12,
  125. canvasId: 'canvasId' + 12,
  126. type: "line",
  127. yType: "value",
  128. xType: "time",
  129. peopleList: []
  130. };
  131. let LikeTheTrend = {
  132. title: "点赞走势",
  133. subTitle: "",
  134. id: 'id' + 13,
  135. canvasId: 'canvasId' + 13,
  136. type: "line",
  137. yType: "value",
  138. xType: "time",
  139. peopleList: []
  140. };
  141. // 实时流量
  142. RealTimeTraffic.subTitle = "在线人数峰值:" + _this.formatNumber((trend.user || {}).user_count || 0) + " 出现时间:" + _this.formatNumber((trend.user || {}).crawl_date || "") + " 平均人数:" + _this.formatNumber((trend.user || {}).avg_user_count || 0);
  143. // 观看人次
  144. 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) + "人来自视频推荐";
  145. // 累计粉丝量
  146. AddUpFans.subTitle = "粉丝峰值:" + _this.formatNumber((trend.fans || {}).club_info_total_fans_count || 0) + " 出现在:" + _this.formatNumber((trend.fans || {}).crawl_date || "");
  147. console.log(oriData);
  148. // 点赞走势
  149. LikeTheTrend.subTitle = "点赞峰值:" + _this.formatNumber((trend.like || {}).add_like_count || 0) + " 出现在:" + _this.formatNumber((trend.like || {}).crawl_date || "");
  150. // 趋势图数据
  151. for (let i = 0; i < (trend.webcastTrendList || []).length; i++) {
  152. const v = (trend.webcastTrendList || [])[i];
  153. let time = v.crawl_date.split(" ")[1] || "";
  154. RealTimeTraffic.peopleList.push({
  155. value: _this.formatNumber(v.user_count || 0),
  156. time: time
  157. });
  158. RealTimePersonTime.peopleList.push({
  159. value: _this.formatNumber(v.stats_total_user || 0),
  160. time: time
  161. });
  162. AddUpFans.peopleList.push({
  163. value: _this.formatNumber(v.club_info_total_fans_count || 0),
  164. time: time
  165. });
  166. LikeTheTrend.peopleList.push({
  167. value: _this.formatNumber(v.like_count || 0),
  168. time: time
  169. });
  170. }
  171. console.log(oriData);
  172. // 基础数据
  173. let last = (trend.webcastTrendList || []);
  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. _this.setData({
  201. headData: base,
  202. region: [region],
  203. series: [
  204. {
  205. type: 'pie',
  206. label: {
  207. position: 'inner',
  208. fontSize: 14,
  209. },
  210. data: gender,
  211. emphasis: {
  212. itemStyle: {
  213. shadowBlur: 10,
  214. shadowOffsetX: 0,
  215. shadowColor: 'rgba(0, 0, 0, 0.5)'
  216. }
  217. }
  218. }
  219. ],
  220. lineList:[
  221. RealTimeTraffic,
  222. RealTimePersonTime,
  223. AddUpFans,
  224. LikeTheTrend
  225. ]
  226. })
  227. },
  228. fail: function (err) {
  229. wx.hideLoading()
  230. wx.showToast({
  231. title: '请重启小程序',
  232. icon: "error"
  233. })
  234. },
  235. })
  236. }
  237. })