// 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: "实时流量", id: 'id' + 10, canvasId: 'canvasId' + 10, type: "line", yType: "value", xType: "time", peopleList: [] }; let RealTimePersonTime = { title: "观看人次", id: 'id' + 11, canvasId: 'canvasId' + 11, type: "line", yType: "value", xType: "time", peopleList: [] }; let AddUpFans = { title: "累计粉丝量", id: 'id' + 12, canvasId: 'canvasId' + 12, type: "line", yType: "value", xType: "time", peopleList: [] }; let LikeTheTrend = { title: "点赞走势", id: 'id' + 13, canvasId: 'canvasId' + 13, type: "line", yType: "value", xType: "time", peopleList: [] }; // 趋势图数据 for (let i = 0; i < (trend.webcastTrendList || []).length; i++) { const v = (trend.webcastTrendList || [])[i]; let time = v.crawl_date.split(" ")[1] || ""; v.user_count !== undefined && RealTimeTraffic.peopleList.push({ value: v.user_count || 0, time: time }); v.stats_total_user !== undefined && RealTimePersonTime.peopleList.push({ value: v.stats_total_user || 0, time: time }); v.club_info_total_fans_count !== undefined && AddUpFans.peopleList.push({ value: v.club_info_total_fans_count || 0, time: time }); v.like_count !== undefined && LikeTheTrend.peopleList.push({ value: v.like_count || 0, time: time }); } // 基础数据 let core_date = oriData.core_data || {}; let base = { msg_count: (oriData.webcastMessageList ? oriData.webcastMessageList.count || 0 : 0), like_count: core_date.like_count || 0, total_fans_count: core_date.add_fans_count || 0, peopel_time: (trend.user || {}).stats_total_user || 0, avg_user_count: core_date.avg_user_count || 0, max_user_count: core_date.max_user_count || 0, turn_rate: (core_date.turn_rate || 0)*100 } // 来源城市 let city = oriData.city || [] for (let i = 0; i < city.length; i++) { const element = city[i] || {}; region.push({ name: element.key || "", value: ((element.rate || 0) * 100).toFixed(2) - 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', radius: ['0%', '50%'], label: { position: "outside", formatter: '{b}\n{d}% ', }, 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" }) }, }) } } })