// pages/live/components/kuaishou/kuaishou.js const app = getApp(); Component({ /** * 组件的属性列表 */ properties: { title:{ type: String, value: "" }, season:{ type: Number, value: 1 } }, /** * 组件的初始数据 */ data: { error: "", detail: "", diglogTitle: "", headData: {}, lineList: [], region: [], series: [], oriList: [] }, 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: "kuaishou", season: this.data.season }, success: function (res) { wx.hideLoading() if (res.statusCode !== 200) return wx.showToast({ title: '请重启小程序', icon: "error" }) let oriData = res.data || {}; console.log(oriData) let region = []; let trend = oriData.detail || {}; let RealTimeWatch = { title: "实时流量", subTitle: "", id: 'id' + 10, canvasId: 'canvasId' + 10, type: "line", yType: "value", xType: "time", peopleList: [] }; let AddUpBsc = { title: "弹幕数", subTitle: "", id: 'id' + 12, canvasId: 'canvasId' + 12, type: "line", yType: "value", xType: "time", peopleList: [] }; let LikeTheBsuc = { title: "发弹幕人数", subTitle: "", id: 'id' + 13, canvasId: 'canvasId' + 13, type: "line", yType: "value", xType: "time", peopleList: [] }; // 趋势图数据 console.log(trend.watch) for (let i = 0; i < (trend.watch || []).length; i++) { const v = (trend.watch || [])[i]; let time = new Date(v.x || 0); let formatTime = "" time.getHours() > 9 ? formatTime += time.getHours() + ":": formatTime += '0' + time.getHours() + ":"; time.getMinutes() + 1 > 9 ? formatTime += (time.getMinutes() + 1) + ":": formatTime += '0' + (time.getMinutes() + 1) + ":"; time.getSeconds() > 9 ? formatTime += time.getSeconds(): formatTime += '0' + time.getSeconds(); RealTimeWatch.peopleList.push({ value: v.watch || 0, time:formatTime }); AddUpBsc.peopleList.push({ value: v.bsc || 0, time:formatTime }); LikeTheBsuc.peopleList.push({ value: v.bsuc || 0, time:formatTime }); } // 基础数据 let base = { live_time: (oriData.detail ? oriData.detail.time || "" : "") } // 来源城市 let city = oriData.fans ? oriData.fans.area ? oriData.fans.area['全部'] || [] : [] : []; for (let i = 0; i < city.length; i++) { const element = city[i] || {}; region.push({ name: element.Name || "", value: element.Ratio }) } // 性别比 let gender = []; let oriGender = oriData.fans ? oriData.fans.gender || [] : []; for (let i = 0; i < oriGender.length; i++) { const v = oriGender[i]; let value = v.rate.split("%")[0] * 100; gender.push({ name: v.gender, value }) } // 年龄 let age = []; let oriAge = oriData.fans ? oriData.fans.age || [] : []; for (let i = 0; i < oriAge.length; i++) { const v = oriAge[i]; let value = v.count; age.push({ name: v.item + "岁", value }) } let p = { headData: base, region: [], series: [], lineList: [], oriList: [] } region.length && p.region.push(region); if (age.length) p.oriList = [ { type: 'pie', label: { show: false }, data: age } ] 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)' } } } ]; AddUpBsc.peopleList.length && p.lineList.push(AddUpBsc); LikeTheBsuc.peopleList.length && p.lineList.push(LikeTheBsuc); RealTimeWatch.peopleList.length && p.lineList.push(RealTimeWatch); _this.setData(p) }, fail: function (err) { wx.hideLoading() wx.showToast({ title: '请重启小程序', icon: "error" }) }, }) } } })