123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- // pages/liveData/liveData.js
- const app = getApp();
- let peopleList = [{ "time": "13:00", "value": 9944 }, { "time": "14:00", "value": 8920 }, { "time": "15:00", "value": 14656 }, { "time": "16:00", "value": 13084 }];
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- error: "",
- detail: "",
- diglogTitle: "",
- title: "",
- headData: {},
- lineList: [],
- region: [],
- series: [],
- oriList: [
- {
- type: 'pie',
- label: {
- show: false
- },
- data: [{ value: 1048, name: '百度' }, { value: 735, name: '谷歌' }, { value: 735, name: '360' }, { value: 735, name: '搜狗' }, { value: 735, name: '其他' }]
- },
- ]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- title: decodeURIComponent(options.title),
- platform: options.platform
- }, () => {
- this.getData()
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- 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: this.data.platform
- },
- 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 || "");
- console.log(oriData);
- // 点赞走势
- 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
- });
- }
- console.log(oriData);
- // 基础数据
- 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
- }
- console.log(base)
- // 来源城市
- 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 && p.lineList.push(AddUpFans);
- LikeTheTrend && p.lineList.push(LikeTheTrend);
- RealTimeTraffic && p.lineList.push(RealTimeTraffic);
- RealTimePersonTime && p.lineList.push(RealTimePersonTime);
- _this.setData(p)
- },
- fail: function (err) {
- wx.hideLoading()
- wx.showToast({
- title: '请重启小程序',
- icon: "error"
- })
- },
- })
- }
- })
|