// pages/sonTopic/sonTopic.js const app = getApp(); Page({ /** * 页面的初始数据 */ data: { detail: "", diglogTitle: "", select: 1, userSort: [], sonTitle: "", imgURL: "", pTitle: "", pId: "", type: "", tabList: [], error: "", headData: {}, contrast: [], all: [], douyin: [], kuaishou: [], yangshi: [], wordList: [], weiboori: [], weiboread: [], weibome: [], selectread: "30d", selectme: "30d", selectori: "30d", weiboBtnListread: [], weiboBtnListme: [], weiboBtnListori: [], height: 0, isShow: false, loading: true, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let sonlist = options.sonList ? JSON.parse(decodeURIComponent(options.sonList)) : []; let title = options.title ? decodeURIComponent(options.title) : ""; let second_name = sonlist[0] ? sonlist[0].name : ""; let imgURL = sonlist[0] ? sonlist[0].worldImgURL : ""; let type = sonlist[0] ? sonlist[0].type : ""; this.setData({ pTitle: title, pId: options.type, tabList: sonlist, imgURL, type, sonTitle: second_name, select: app.select - 0 }) this.getData({ topic_name: second_name || title, season: app.select - 0 + 1 }); this.getPing({ topic_name: second_name || title, season: app.select - 0 + 1 }); this.getAccount({ topic_name: second_name || title, platform: "ALL", type: "all", season: app.select - 0 + 1 }); this.getAccount({ topic_name: second_name || title, platform: "douyin", type: "douyin", season: app.select - 0 + 1 }); this.getAccount({ topic_name: second_name || title, platform: "kuaishou", type: "kuaishou", season: app.select - 0 + 1 }); this.getAccount({ topic_name: second_name || title, platform: "yangshi", type: "yangshi", season: app.select - 0 + 1 }); // this.getWorld({ season: app.select - 0 + 1 }); this.getWeibo({ topic_name: second_name || title, time: "30d", type: "yangshi", season: app.select - 0 + 1 }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.setData({ isShow: true }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { this.setData({ isShow: false }) }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, lineChengeread: function (val) { this.setData({ selectread: val.detail }) this.getWeibo({ topic_name: this.data.sonTitle, time: val.detail, type: "weiboread", season: app.select - 0 + 1 }, "read") }, lineChengeme: function (val) { this.setData({ selectme: val.detail }) this.getWeibo({ topic_name: this.data.sonTitle, time: val.detail, type: "weibome", season: app.select - 0 + 1 }, "me") }, lineChengeori: function (val) { this.setData({ selectori: val.detail }) this.getWeibo({ topic_name: this.data.sonTitle, time: val.detail, type: "weiboori", season: app.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) { _this.setData({ 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 = { 'digg_count': { name: '点赞', type: 'digg_count' }, 'pv': { name: '浏览', type: 'pv' }, '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.userSort = userSort; setD[data.type] = list; _this.setData(setD) } else wx.showToast({ title: '请重启小程序', icon: "error" }) }, data, fail: function (err) { wx.showToast({ title: '请重启小程序', icon: "error" }) }, complete: function (res) { } }) }, getWorld: function (data) { const _this = this; 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 : {}; 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"] = []; p.weiboori = server[_this.data['selectori']].ori || []; p.weiboread = server[_this.data['selectori']].read || []; p.weibome = server[_this.data['selectori']].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 }) }, changeBar: function (type) { let detail = type.detail || {}; let second_name = detail.title || this.data.pTitle; this.setData({ type: detail.type, selectread: "30d", selectme: "30d", selectori: "30d", sonTitle: second_name }) this.getData({ topic_name: second_name, season: app.select - 0 + 1 }); this.getPing({ topic_name: second_name, season: app.select - 0 + 1 }); this.getAccount({ topic_name: second_name, platform: "ALL", type: "all", season: app.select - 0 + 1 }); this.getAccount({ topic_name: second_name, platform: "douyin", type: "douyin", season: app.select - 0 + 1 }); this.getAccount({ topic_name: second_name, platform: "kuaishou", type: "kuaishou", season: app.select - 0 + 1 }); this.getAccount({ topic_name: second_name, platform: "yangshi", type: "yangshi", season: app.select - 0 + 1 }); // this.getWorld({ season: app.select - 0 + 1 }); this.getWeibo({ topic_name: second_name, time: "30d", type: "yangshi", season: app.select - 0 + 1 }); }, showDetail: function (e) { let introduce = e.currentTarget.dataset.introduce || ""; let detail = app.introduce[introduce] || {} console.log(introduce, detail) this.setData({ detail: detail.value || "", diglogTitle: detail.content_desc || "" }) } })