douyin.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // pages/live/components/douyin/douyin.js
  2. const app = getApp();
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. title: {
  9. type: String,
  10. value: ""
  11. },
  12. season:{
  13. type: Number,
  14. value: 1
  15. }
  16. },
  17. /**
  18. * 组件的初始数据
  19. */
  20. data: {
  21. error: "",
  22. detail: "",
  23. diglogTitle: "",
  24. headData: {},
  25. lineList: [],
  26. region: [],
  27. series: []
  28. },
  29. ready() {
  30. this.getData()
  31. },
  32. /**
  33. * 组件的方法列表
  34. */
  35. methods: {
  36. formatNumber: function (val) {
  37. let out = val;
  38. if (val >= 1000 && val < 10000) {
  39. out = (val / 1000).toFixed(2) - 0 + "千"
  40. } else if (val >= 10000 && val < 100000000) {
  41. out = (val / 10000).toFixed(0) - 0 + "万"
  42. } else if (val >= 100000000) {
  43. out = (val / 100000000).toFixed(2) - 0 + "亿"
  44. }
  45. return out
  46. },
  47. getData: function () {
  48. let _this = this;
  49. wx.showLoading();
  50. wx.request({
  51. url: app.baseUrl + '/live-result',
  52. data: {
  53. topic: this.data.title,
  54. platform: "douyin",
  55. season: this.data.season
  56. },
  57. success: function (res) {
  58. wx.hideLoading()
  59. if (res.statusCode !== 200) return wx.showToast({
  60. title: '请重启小程序',
  61. icon: "error"
  62. })
  63. let oriData = res.data || {};
  64. let region = [];
  65. let trend = oriData.trend || {};
  66. let RealTimeTraffic = {
  67. title: "实时流量",
  68. subTitle: "",
  69. id: 'id' + 10,
  70. canvasId: 'canvasId' + 10,
  71. type: "line",
  72. yType: "value",
  73. xType: "time",
  74. peopleList: []
  75. };
  76. let RealTimePersonTime = {
  77. title: "观看人次",
  78. subTitle: "",
  79. id: 'id' + 11,
  80. canvasId: 'canvasId' + 11,
  81. type: "line",
  82. yType: "value",
  83. xType: "time",
  84. peopleList: []
  85. };
  86. let AddUpFans = {
  87. title: "累计粉丝量",
  88. subTitle: "",
  89. id: 'id' + 12,
  90. canvasId: 'canvasId' + 12,
  91. type: "line",
  92. yType: "value",
  93. xType: "time",
  94. peopleList: []
  95. };
  96. let LikeTheTrend = {
  97. title: "点赞走势",
  98. subTitle: "",
  99. id: 'id' + 13,
  100. canvasId: 'canvasId' + 13,
  101. type: "line",
  102. yType: "value",
  103. xType: "time",
  104. peopleList: []
  105. };
  106. // 实时流量
  107. RealTimeTraffic.subTitle = "在线人数峰值:" + _this.formatNumber((trend.user || {}).user_count || 0) + " 出现时间:" + _this.formatNumber((trend.user || {}).crawl_date || "") + " 平均人数:" + _this.formatNumber((trend.user || {}).avg_user_count || 0);
  108. // 观看人次
  109. 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) + "人来自视频推荐";
  110. // 累计粉丝量
  111. AddUpFans.subTitle = "粉丝峰值:" + _this.formatNumber((trend.fans || {}).club_info_total_fans_count || 0) + " 出现在:" + _this.formatNumber((trend.fans || {}).crawl_date || "");
  112. // 点赞走势
  113. LikeTheTrend.subTitle = "点赞峰值:" + _this.formatNumber((trend.like || {}).add_like_count || 0) + " 出现在:" + _this.formatNumber((trend.like || {}).crawl_date || "");
  114. // 趋势图数据
  115. for (let i = 0; i < (trend.webcastTrendList || []).length; i++) {
  116. const v = (trend.webcastTrendList || [])[i];
  117. let time = v.crawl_date.split(" ")[1] || "";
  118. RealTimeTraffic.peopleList.push({
  119. value: _this.formatNumber(v.user_count || 0),
  120. time: time
  121. });
  122. RealTimePersonTime.peopleList.push({
  123. value: _this.formatNumber(v.stats_total_user || 0),
  124. time: time
  125. });
  126. AddUpFans.peopleList.push({
  127. value: _this.formatNumber(v.club_info_total_fans_count || 0),
  128. time: time
  129. });
  130. LikeTheTrend.peopleList.push({
  131. value: _this.formatNumber(v.like_count || 0),
  132. time: time
  133. });
  134. }
  135. // 基础数据
  136. let base = {
  137. msg_count: (oriData.webcastMessageList ? oriData.webcastMessageList.count || 0 : 0),
  138. like_count: (trend.like || {}).add_like_count || 0,
  139. total_fans_count: (trend.fans || {}).club_info_total_fans_count || 0,
  140. peopel_time: (trend.user || {}).stats_total_user || 0
  141. }
  142. // 来源城市
  143. let city = oriData.city || []
  144. for (let i = 0; i < city.length; i++) {
  145. const element = city[i] || {};
  146. region.push({
  147. name: element.key || "",
  148. value: element.count || 0
  149. })
  150. }
  151. // 性别比
  152. let gender = [];
  153. let oriGender = oriData.gender || [];
  154. for (let i = 0; i < oriGender.length; i++) {
  155. const v = oriGender[i];
  156. gender.push({
  157. name: v.key == "1" ? "男" : "女",
  158. value: v.count
  159. })
  160. }
  161. let p = {
  162. headData: base,
  163. region: [],
  164. series: [],
  165. lineList: []
  166. }
  167. region.length && p.region.push(region);
  168. if (gender.length)
  169. p.series = [
  170. {
  171. type: 'pie',
  172. label: {
  173. position: 'inner',
  174. fontSize: 14,
  175. },
  176. data: gender,
  177. emphasis: {
  178. itemStyle: {
  179. shadowBlur: 10,
  180. shadowOffsetX: 0,
  181. shadowColor: 'rgba(0, 0, 0, 0.5)'
  182. }
  183. }
  184. }
  185. ];
  186. AddUpFans.peopleList.length && p.lineList.push(AddUpFans);
  187. LikeTheTrend.peopleList.length && p.lineList.push(LikeTheTrend);
  188. RealTimeTraffic.peopleList.length && p.lineList.push(RealTimeTraffic);
  189. RealTimePersonTime.peopleList.length && p.lineList.push(RealTimePersonTime);
  190. _this.setData(p)
  191. },
  192. fail: function (err) {
  193. wx.hideLoading()
  194. wx.showToast({
  195. title: '请重启小程序',
  196. icon: "error"
  197. })
  198. },
  199. })
  200. }
  201. }
  202. })