douyin.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. id: 'id' + 10,
  69. canvasId: 'canvasId' + 10,
  70. type: "line",
  71. yType: "value",
  72. xType: "time",
  73. peopleList: []
  74. };
  75. let RealTimePersonTime = {
  76. title: "观看人次",
  77. id: 'id' + 11,
  78. canvasId: 'canvasId' + 11,
  79. type: "line",
  80. yType: "value",
  81. xType: "time",
  82. peopleList: []
  83. };
  84. let AddUpFans = {
  85. title: "累计粉丝量",
  86. id: 'id' + 12,
  87. canvasId: 'canvasId' + 12,
  88. type: "line",
  89. yType: "value",
  90. xType: "time",
  91. peopleList: []
  92. };
  93. let LikeTheTrend = {
  94. title: "点赞走势",
  95. id: 'id' + 13,
  96. canvasId: 'canvasId' + 13,
  97. type: "line",
  98. yType: "value",
  99. xType: "time",
  100. peopleList: []
  101. };
  102. // 趋势图数据
  103. for (let i = 0; i < (trend.webcastTrendList || []).length; i++) {
  104. const v = (trend.webcastTrendList || [])[i];
  105. let time = v.crawl_date.split(" ")[1] || "";
  106. v.user_count !== undefined && RealTimeTraffic.peopleList.push({
  107. value: v.user_count || 0,
  108. time: time
  109. });
  110. v.stats_total_user !== undefined && RealTimePersonTime.peopleList.push({
  111. value: v.stats_total_user || 0,
  112. time: time
  113. });
  114. v.club_info_total_fans_count !== undefined && AddUpFans.peopleList.push({
  115. value: v.club_info_total_fans_count || 0,
  116. time: time
  117. });
  118. v.like_count !== undefined && LikeTheTrend.peopleList.push({
  119. value: v.like_count || 0,
  120. time: time
  121. });
  122. }
  123. // 基础数据
  124. let core_date = oriData.core_data || {};
  125. let base = {
  126. msg_count: (oriData.webcastMessageList ? oriData.webcastMessageList.count || 0 : 0),
  127. like_count: core_date.like_count || 0,
  128. total_fans_count: core_date.add_fans_count || 0,
  129. peopel_time: (trend.user || {}).stats_total_user || 0,
  130. avg_user_count: core_date.avg_user_count || 0,
  131. max_user_count: core_date.max_user_count || 0,
  132. turn_rate: (core_date.turn_rate || 0)*100
  133. }
  134. // 来源城市
  135. let city = oriData.city || []
  136. for (let i = 0; i < city.length; i++) {
  137. const element = city[i] || {};
  138. region.push({
  139. name: element.key || "",
  140. value: ((element.rate || 0) * 100).toFixed(2) - 0
  141. })
  142. }
  143. // 性别比
  144. let gender = [];
  145. let oriGender = oriData.gender || [];
  146. for (let i = 0; i < oriGender.length; i++) {
  147. const v = oriGender[i];
  148. gender.push({
  149. name: v.key == "1" ? "男" : "女",
  150. value: v.count
  151. })
  152. }
  153. let p = {
  154. headData: base,
  155. region: [],
  156. series: [],
  157. lineList: []
  158. }
  159. region.length && p.region.push(region);
  160. if (gender.length)
  161. p.series = [
  162. {
  163. type: 'pie',
  164. radius: ['0%', '50%'],
  165. label: {
  166. position: "outside",
  167. formatter: '{b}\n{d}% ',
  168. },
  169. data: gender,
  170. emphasis: {
  171. itemStyle: {
  172. shadowBlur: 10,
  173. shadowOffsetX: 0,
  174. shadowColor: 'rgba(0, 0, 0, 0.5)'
  175. }
  176. }
  177. }
  178. ];
  179. AddUpFans.peopleList.length && p.lineList.push(AddUpFans);
  180. LikeTheTrend.peopleList.length && p.lineList.push(LikeTheTrend);
  181. RealTimeTraffic.peopleList.length && p.lineList.push(RealTimeTraffic);
  182. RealTimePersonTime.peopleList.length && p.lineList.push(RealTimePersonTime);
  183. _this.setData(p)
  184. },
  185. fail: function (err) {
  186. wx.hideLoading()
  187. wx.showToast({
  188. title: '请重启小程序',
  189. icon: "error"
  190. })
  191. },
  192. })
  193. }
  194. }
  195. })