123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- // 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 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 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 = encodeURIComponent(this.data.title);
- let platform = e.currentTarget.dataset.platform || '';
- let url = "/pages/liveData/liveData?title=" +title + "&platform=" + platform;
- if(platform === "kuaishou") url = "/pages/liveData_kuaishou/index?title=" +title + "&platform=" + platform;
- 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 || "")
- })
- }
- }
- })
|