123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- // pages/sonTopic/sonTopic.js
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- 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
- })
- this.getData({ topic_name: second_name || title });
- this.getPing({ topic_name: second_name || title });
- this.getAccount({ topic_name: second_name || title, platform: "ALL", type: "all" });
- this.getAccount({ topic_name: second_name || title, platform: "douyin", type: "douyin" });
- this.getAccount({ topic_name: second_name || title, platform: "kuaishou", type: "kuaishou" });
- this.getAccount({ topic_name: second_name || title, platform: "yangshi", type: "yangshi" });
- // this.getWorld();
- this.getWeibo({ topic_name: second_name || title, time: "30d", type: "yangshi" });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- 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" }, "read")
- },
- lineChengeme: function (val) {
- this.setData({
- selectme: val.detail
- })
- this.getWeibo({ topic_name: this.data.sonTitle, time: val.detail, type: "weibome" }, "me")
- },
- lineChengeori: function (val) {
- this.setData({
- selectori: val.detail
- })
- this.getWeibo({ topic_name: this.data.sonTitle, time: val.detail, type: "weiboori" }, "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 _this.setData({
- 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 contrast = res.data && res.data.length ? [res.data] : [];
- _this.setData({
- contrast
- })
- } else _this.setData({
- 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 _this.setData({
- error: '请重启后查看'
- })
- },
- data,
- fail: function (err) {
- _this.setData({
- 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 _this.setData({
- 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) {
- console.log(server, _this.data['select' + type], 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 _this.setData({
- 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 });
- this.getPing({ topic_name: second_name });
- this.getAccount({ topic_name: second_name, platform: "ALL", type: "all" });
- this.getAccount({ topic_name: second_name, platform: "douyin", type: "douyin" });
- this.getAccount({ topic_name: second_name, platform: "kuaishou", type: "kuaishou" });
- this.getAccount({ topic_name: second_name, platform: "yangshi", type: "yangshi" });
- // this.getWorld();
- this.getWeibo({ topic_name: second_name, time: "30d", type: "yangshi" });
- }
- })
|