// pages/home/components/contrast/contrast.js const app = getApp(); let toUrl = true; Component({ /** * 组件的属性列表 */ isUp: undefined, properties: { imgURL: { type: String, value: "" }, sonList: { type: Array, value: [] }, isShow: { type: Boolean, value: false, }, isUpdata: { type: Boolean, value: false, observer: function (newUp) { if (!newUp) return; let n = this.data.title; this.isUp && clearInterval(this.isUp); this.isUp = setInterval(() => { // this.getData({ topic_name: n, season: this.data.select - 0 + 1 }); this.getPing({ topic_name: n, season: this.data.select - 0 + 1 }); this.getAccount({ topic_name: n, platform: "ALL", type: "all", season: this.data.select - 0 + 1 }); }, 3000); } }, select: { type: String, value: "" }, title: { type: String, value: "", observer: function (newShow) { !this.data.isUpdata && this.isUp && clearInterval(this.isUp); let n = newShow; this.setData({ selectread: "30d", selectme: "30d", selectori: "30d", }) this.getData({ topic_name: n, season: this.data.select - 0 + 1 }); this.getPing({ topic_name: n, season: this.data.select - 0 + 1 }); this.getAccount({ topic_name: n, platform: "ALL", type: "all", season: this.data.select - 0 + 1 }); this.getAccount({ topic_name: n, platform: "douyin", type: "douyin", season: this.data.select - 0 + 1 }); this.getAccount({ topic_name: n, platform: "kuaishou", type: "kuaishou", season: this.data.select - 0 + 1 }); this.getAccount({ topic_name: n, platform: "yangshi", type: "yangshi", season: this.data.select - 0 + 1 }); // this.getWorld({ season: this.data.select - 0 + 1 }); this.getWeibo({ topic_name: n, time: "30d", season: this.data.select - 0 + 1 }) } }, type: { type: String, value: "" }, jsonURL: { type: String, value: "" }, }, /** * 组件的初始数据 */ data: { error: "", detail: "", nameTitle: "", diglogTitle: "", headData: {}, contrast: [], all: [], douyin: [], kuaishou: [], yangshi: [], wordList: [], weiboori: [], weiboread: [], weibome: [], selectread: "30d", selectme: "30d", selectori: "30d", weiboBtnListread: [], weiboBtnListme: [], weiboBtnListori: [], height: 0 }, detached: function () { this.isUp && clearInterval(this.isUp); }, /** * 组件的方法列表 */ methods: { lineChengeread: function (val) { this.setData({ selectread: val.detail }) this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "read") }, lineChengeme: function (val) { this.setData({ selectme: val.detail }) this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "me") }, lineChengeori: function (val) { this.setData({ selectori: val.detail }) this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "ori") }, getData: function (data) { const _this = this; wx.request({ url: app.baseUrl + '/overview', success: function (res) { if (res.statusCode === 200) { _this.setData({ headData: res.data || {} }) } else wx.showToast({ title: '请重启小程序', icon: "error" }) }, data, fail: function (err) { wx.showToast({ title: '请重启小程序', icon: "error" }) }, complete: function (res) { } }) }, getPing: function (data) { const _this = this; /** * @description * data * topic_name: 聚劲延安 */ wx.request({ url: app.baseUrl + '/platform', success: function (res) { if (res.statusCode === 200) { let list = []; for (let i = 0; i < (res.data || []).length; i++) { const v = (res.data || [])[i]; list.push({ value: v.total_pv, name: v.platform }) } let contrast = [ { type: 'pie', radius: ['0%', '50%'], label: { position: "outside", formatter: '{b}\n{d}% ', }, data: list, emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ]; _this.setData({ contrast }) } else wx.showToast({ title: '请重启小程序', icon: "error" }) }, data, fail: function (err) { _this.setData({ error: '数据错误' }) }, complete: function (res) { } }) }, getAccount: function (data) { const _this = this; /** * @description * data * topic_name: 聚劲延安 */ wx.request({ url: app.baseUrl + '/name', success: function (res) { if (res.statusCode === 200) { let list = res.data && res.data.length ? [res.data] : []; const setD = {}; let isIntUser = {}; let user = { 'pv': { name: '浏览', type: 'pv' }, 'digg_count': { name: '点赞', type: 'digg_count' }, 'comment_count': { name: '评论', type: 'comment_count' }, 'forward_count': { name: '转发', type: 'forward_count' } }; let userSort = []; (res.data || []).map(v => { !isIntUser.pv && v.pv && userSort.push(user.pv) && (isIntUser.pv = true); !isIntUser.digg_count && v.digg_count && userSort.push(user.digg_count) && (isIntUser.digg_count = true); !isIntUser.comment_count && v.comment_count && userSort.push(user.comment_count) && (isIntUser.comment_count = true); !isIntUser.forward_count && v.forward_count && userSort.push(user.forward_count) && (isIntUser.forward_count = true); }) if (userSort.length) { setD[data.type] = list; setD.userSort = userSort; } else { setD[data.type] = []; setD.userSort = []; } let oldType = JSON.stringify(_this.data[data.type]); let newType = JSON.stringify(list); if (oldType != newType) _this.setData(setD) } else wx.showToast({ title: '请重启小程序', icon: "error" }) }, data, fail: function (err) { _this.setData({ error: '数据错误' }) }, complete: function (res) { } }) }, getWorld: function (data) { const _this = this; /** * @description * data * topic_name: 聚劲延安 */ wx.request({ url: this.data.jsonURL, success: function (res) { if (res.statusCode === 200) { _this.setData({ wordList: res.data || [] }) } else wx.showToast({ title: '请重启小程序', icon: "error" }) }, data, fail: function (err) { _this.setData({ error: '数据错误' }) }, complete: function (res) { } }) }, getWeibo: function (data, type) { const _this = this; /** * @description * data * topic_name: 聚劲延安 */ wx.request({ url: app.baseUrl + '/time/v2', success: function (res) { if (res.statusCode === 200) { let server = res && res.data ? res.data : {}; let p = {}; let weiboBtn = { '6m': { name: '1小时', type: '6m' }, '24h': { name: '24小时', type: '24h' }, '7d': { name: '7天', type: '7d' }, '30d': { name: '30天', type: '30d' }, } if (type) { p["weibo" + type] = server[_this.data['select' + type]][type] || []; p["weiboBtnList" + type] = []; } else { p["weiboBtnListread"] = []; p["weiboBtnListme"] = []; p["weiboBtnListori"] = []; let pOri = server[_this.data['selectori']] || {}; p.weiboori = pOri.ori || []; p.weiboread = pOri.read || []; p.weibome = pOri.me || []; } for (const key in weiboBtn) { if (weiboBtn.hasOwnProperty(key)) { const element = weiboBtn[key]; if (type) { server[key] && server[key][type] && p["weiboBtnList" + type].push(element); } else { server[key] && server[key].read && p.weiboBtnListread.push(element); server[key] && server[key].me && p.weiboBtnListme.push(element); server[key] && server[key].ori && p.weiboBtnListori.push(element); } } } _this.setData(p) } else wx.showToast({ title: '请重启小程序', icon: "error" }) }, data, fail: function (err) { _this.setData({ error: '数据错误' }) }, complete: function (res) { } }) }, imgLoad: function (e) { var img_ratio = e.detail.height / e.detail.width; var rWidth = wx.getSystemInfoSync().windowWidth; rWidth > 441 && (rWidth = 441) this.setData({ height: (rWidth * img_ratio).toFixed(0) - 0 }) }, toSecond: function () { if (!toUrl) return; toUrl = false; let asciiList = encodeURIComponent(JSON.stringify(this.data.sonList)); let title = encodeURIComponent(this.data.title); wx.navigateTo({ url: "/pages/sonTopic/sonTopic?sonList=" + asciiList + "&title=" + title + "&type=" + this.data.type, complete: function (res) { toUrl = true; } }) }, toLive: function (e) { if (!toUrl) return; toUrl = false; let title = this.data.title; let url = "/pages/live/live?title=" + title + "&season=" + (this.data.select - 0 + 1) + "&isdou=" + this.data.headData.has_live_douyin_data + "&iskuai=" + this.data.headData.has_live_kuaishou_data; wx.navigateTo({ url, complete: function (res) { toUrl = true; } }) }, showDetail: function (e) { let introduce = e.currentTarget.dataset.introduce || ""; let detail = app.introduce[this.data.title + "_" + introduce] || {} this.setData({ detail: (detail.value || ""), diglogTitle: (detail.content_desc || "") }) } } })