|
@@ -0,0 +1,349 @@
|
|
|
+// 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 });
|
|
|
+ this.getPing({ topic_name: n });
|
|
|
+ this.getAccount({ topic_name: n, platform: "ALL", type: "all" });
|
|
|
+ }, 3000);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 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 });
|
|
|
+ this.getPing({ topic_name: n });
|
|
|
+ this.getAccount({ topic_name: n, platform: "ALL", type: "all" });
|
|
|
+ this.getAccount({ topic_name: n, platform: "douyin", type: "douyin" });
|
|
|
+ this.getAccount({ topic_name: n, platform: "kuaishou", type: "kuaishou" });
|
|
|
+ this.getAccount({ topic_name: n, platform: "yangshi", type: "yangshi" });
|
|
|
+ // this.getWorld();
|
|
|
+ this.getWeibo({ topic_name: n, time: "30d" })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ type: {
|
|
|
+ type: String,
|
|
|
+ value: ""
|
|
|
+ },
|
|
|
+ jsonURL: {
|
|
|
+ type: String,
|
|
|
+ value: ""
|
|
|
+ },
|
|
|
+ },
|
|
|
+ // created(){
|
|
|
+ // console.log("实例刚刚被创建时执行")
|
|
|
+ // },
|
|
|
+ // attached(){
|
|
|
+ // console.log("实例进入页面节点树时执行")
|
|
|
+ // },
|
|
|
+ // ready() {
|
|
|
+ // console.log("组件布局完成后执行", this.data.title)
|
|
|
+ // },
|
|
|
+ // moved(){
|
|
|
+ // console.log("组件实例被移动到节点树另一个位置时执行")
|
|
|
+ // },
|
|
|
+ // detached(){
|
|
|
+ // console.log("组件实例被从页面节点树移除时执行")
|
|
|
+ // },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组件的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ error: "",
|
|
|
+ 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 }, "read")
|
|
|
+ },
|
|
|
+ lineChengeme: function (val) {
|
|
|
+ this.setData({
|
|
|
+ selectme: val.detail
|
|
|
+ })
|
|
|
+ this.getWeibo({ topic_name: this.data.title, time: val.detail }, "me")
|
|
|
+ },
|
|
|
+ lineChengeori: function (val) {
|
|
|
+ this.setData({
|
|
|
+ selectori: val.detail
|
|
|
+ })
|
|
|
+ this.getWeibo({ topic_name: this.data.title, time: val.detail }, "ori")
|
|
|
+ },
|
|
|
+ getData: function (data) {
|
|
|
+ const _this = this;
|
|
|
+ /**
|
|
|
+ * @description
|
|
|
+ * data
|
|
|
+ * topic_name: 聚劲延安
|
|
|
+ */
|
|
|
+ wx.request({
|
|
|
+ url: app.baseUrl + '/overview',
|
|
|
+ success: function (res) {
|
|
|
+ if (res.statusCode === 200) {
|
|
|
+ let oldHead = JSON.stringify(_this.data.headData);
|
|
|
+ let newHead = JSON.stringify(res.data || {});
|
|
|
+ if (oldHead != newHead)
|
|
|
+ _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] : [];
|
|
|
+ let oldContrast = JSON.stringify(_this.data.contrast);
|
|
|
+ let newContrast = JSON.stringify(contrast);
|
|
|
+ if (oldContrast != newContrast)
|
|
|
+ _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 = {
|
|
|
+ '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 _this.setData({
|
|
|
+ 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 _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 ? 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 _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
|
|
|
+ })
|
|
|
+ },
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|