123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- // pages/live/components/douyin/douyin.js
- const app = getApp();
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- title: {
- type: String,
- value: ""
- },
- season:{
- type: Number,
- value: 1
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- error: "",
- detail: "",
- diglogTitle: "",
- headData: {},
- lineList: [],
- region: [],
- series: []
- },
- ready() {
- this.getData()
- },
- /**
- * 组件的方法列表
- */
- methods: {
- formatNumber: function (val) {
- let out = val;
- if (val >= 1000 && val < 10000) {
- out = (val / 1000).toFixed(2) - 0 + "千"
- } else if (val >= 10000 && val < 100000000) {
- out = (val / 10000).toFixed(0) - 0 + "万"
- } else if (val >= 100000000) {
- out = (val / 100000000).toFixed(2) - 0 + "亿"
- }
- return out
- },
- getData: function () {
- let _this = this;
- wx.showLoading();
- wx.request({
- url: app.baseUrl + '/live-result',
- data: {
- topic: this.data.title,
- platform: "douyin",
- season: this.data.season
- },
- success: function (res) {
- wx.hideLoading()
- if (res.statusCode !== 200) return wx.showToast({
- title: '请重启小程序',
- icon: "error"
- })
- let oriData = res.data || {};
- let region = [];
- let trend = oriData.trend || {};
- let RealTimeTraffic = {
- title: "实时流量",
- subTitle: "",
- id: 'id' + 10,
- canvasId: 'canvasId' + 10,
- type: "line",
- yType: "value",
- xType: "time",
- peopleList: []
- };
- let RealTimePersonTime = {
- title: "观看人次",
- subTitle: "",
- id: 'id' + 11,
- canvasId: 'canvasId' + 11,
- type: "line",
- yType: "value",
- xType: "time",
- peopleList: []
- };
- let AddUpFans = {
- title: "累计粉丝量",
- subTitle: "",
- id: 'id' + 12,
- canvasId: 'canvasId' + 12,
- type: "line",
- yType: "value",
- xType: "time",
- peopleList: []
- };
- let LikeTheTrend = {
- title: "点赞走势",
- subTitle: "",
- id: 'id' + 13,
- canvasId: 'canvasId' + 13,
- type: "line",
- yType: "value",
- xType: "time",
- peopleList: []
- };
- // 实时流量
- RealTimeTraffic.subTitle = "在线人数峰值:" + _this.formatNumber((trend.user || {}).user_count || 0) + " 出现时间:" + _this.formatNumber((trend.user || {}).crawl_date || "") + " 平均人数:" + _this.formatNumber((trend.user || {}).avg_user_count || 0);
- // 观看人次
- 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) + "人来自视频推荐";
- // 累计粉丝量
- AddUpFans.subTitle = "粉丝峰值:" + _this.formatNumber((trend.fans || {}).club_info_total_fans_count || 0) + " 出现在:" + _this.formatNumber((trend.fans || {}).crawl_date || "");
- // 点赞走势
- LikeTheTrend.subTitle = "点赞峰值:" + _this.formatNumber((trend.like || {}).add_like_count || 0) + " 出现在:" + _this.formatNumber((trend.like || {}).crawl_date || "");
- // 趋势图数据
- for (let i = 0; i < (trend.webcastTrendList || []).length; i++) {
- const v = (trend.webcastTrendList || [])[i];
- let time = v.crawl_date.split(" ")[1] || "";
- RealTimeTraffic.peopleList.push({
- value: _this.formatNumber(v.user_count || 0),
- time: time
- });
- RealTimePersonTime.peopleList.push({
- value: _this.formatNumber(v.stats_total_user || 0),
- time: time
- });
- AddUpFans.peopleList.push({
- value: _this.formatNumber(v.club_info_total_fans_count || 0),
- time: time
- });
- LikeTheTrend.peopleList.push({
- value: _this.formatNumber(v.like_count || 0),
- time: time
- });
- }
- // 基础数据
- let base = {
- msg_count: (oriData.webcastMessageList ? oriData.webcastMessageList.count || 0 : 0),
- like_count: (trend.like || {}).add_like_count || 0,
- total_fans_count: (trend.fans || {}).club_info_total_fans_count || 0,
- peopel_time: (trend.user || {}).stats_total_user || 0
- }
- // 来源城市
- let city = oriData.city || []
- for (let i = 0; i < city.length; i++) {
- const element = city[i] || {};
- region.push({
- name: element.key || "",
- value: element.count || 0
- })
- }
- // 性别比
- let gender = [];
- let oriGender = oriData.gender || [];
- for (let i = 0; i < oriGender.length; i++) {
- const v = oriGender[i];
- gender.push({
- name: v.key == "1" ? "男" : "女",
- value: v.count
- })
- }
- let p = {
- headData: base,
- region: [],
- series: [],
- lineList: []
- }
- region.length && p.region.push(region);
- if (gender.length)
- p.series = [
- {
- type: 'pie',
- label: {
- position: 'inner',
- fontSize: 14,
- },
- data: gender,
- emphasis: {
- itemStyle: {
- shadowBlur: 10,
- shadowOffsetX: 0,
- shadowColor: 'rgba(0, 0, 0, 0.5)'
- }
- }
- }
- ];
- AddUpFans.peopleList.length && p.lineList.push(AddUpFans);
- LikeTheTrend.peopleList.length && p.lineList.push(LikeTheTrend);
- RealTimeTraffic.peopleList.length && p.lineList.push(RealTimeTraffic);
- RealTimePersonTime.peopleList.length && p.lineList.push(RealTimePersonTime);
- _this.setData(p)
- },
- fail: function (err) {
- wx.hideLoading()
- wx.showToast({
- title: '请重启小程序',
- icon: "error"
- })
- },
- })
- }
- }
- })
|