topic.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. // pages/home/components/contrast/contrast.js
  2. const app = getApp();
  3. let toUrl = true;
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. isUp: undefined,
  9. properties: {
  10. imgURL: {
  11. type: String,
  12. value: ""
  13. },
  14. sonList: {
  15. type: Array,
  16. value: []
  17. },
  18. isShow: {
  19. type: Boolean,
  20. value: false,
  21. },
  22. isUpdata: {
  23. type: Boolean,
  24. value: false,
  25. observer: function (newUp) {
  26. if (!newUp) return;
  27. let n = this.data.title;
  28. this.isUp && clearInterval(this.isUp);
  29. this.isUp = setInterval(() => {
  30. // this.getData({ topic_name: n, season: this.data.select - 0 + 1 });
  31. this.getPing({ topic_name: n, season: this.data.select - 0 + 1 });
  32. this.getAccount({ topic_name: n, platform: "ALL", type: "all", season: this.data.select - 0 + 1 });
  33. }, 3000);
  34. }
  35. },
  36. select: {
  37. type: String,
  38. value: ""
  39. },
  40. title: {
  41. type: String,
  42. value: "",
  43. observer: function (newShow) {
  44. !this.data.isUpdata && this.isUp && clearInterval(this.isUp);
  45. let n = newShow;
  46. this.setData({
  47. selectread: "30d",
  48. selectme: "30d",
  49. selectori: "30d",
  50. })
  51. this.getData({ topic_name: n, season: this.data.select - 0 + 1 });
  52. this.getPing({ topic_name: n, season: this.data.select - 0 + 1 });
  53. this.getAccount({ topic_name: n, platform: "ALL", type: "all", season: this.data.select - 0 + 1 });
  54. this.getAccount({ topic_name: n, platform: "douyin", type: "douyin", season: this.data.select - 0 + 1 });
  55. this.getAccount({ topic_name: n, platform: "kuaishou", type: "kuaishou", season: this.data.select - 0 + 1 });
  56. this.getAccount({ topic_name: n, platform: "yangshi", type: "yangshi", season: this.data.select - 0 + 1 });
  57. // this.getWorld({ season: this.data.select - 0 + 1 });
  58. this.getWeibo({ topic_name: n, time: "30d", season: this.data.select - 0 + 1 })
  59. }
  60. },
  61. type: {
  62. type: String,
  63. value: ""
  64. },
  65. jsonURL: {
  66. type: String,
  67. value: ""
  68. },
  69. },
  70. /**
  71. * 组件的初始数据
  72. */
  73. data: {
  74. error: "",
  75. detail: "",
  76. nameTitle:"",
  77. diglogTitle: "",
  78. headData: {},
  79. contrast: [],
  80. all: [],
  81. douyin: [],
  82. kuaishou: [],
  83. yangshi: [],
  84. wordList: [],
  85. weiboori: [],
  86. weiboread: [],
  87. weibome: [],
  88. selectread: "30d",
  89. selectme: "30d",
  90. selectori: "30d",
  91. weiboBtnListread: [],
  92. weiboBtnListme: [],
  93. weiboBtnListori: [],
  94. height: 0
  95. },
  96. detached: function () {
  97. this.isUp && clearInterval(this.isUp);
  98. },
  99. /**
  100. * 组件的方法列表
  101. */
  102. methods: {
  103. lineChengeread: function (val) {
  104. this.setData({
  105. selectread: val.detail
  106. })
  107. this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "read")
  108. },
  109. lineChengeme: function (val) {
  110. this.setData({
  111. selectme: val.detail
  112. })
  113. this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "me")
  114. },
  115. lineChengeori: function (val) {
  116. this.setData({
  117. selectori: val.detail
  118. })
  119. this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "ori")
  120. },
  121. getData: function (data) {
  122. const _this = this;
  123. wx.request({
  124. url: app.baseUrl + '/overview',
  125. success: function (res) {
  126. if (res.statusCode === 200) {
  127. _this.setData({
  128. headData: res.data || {}
  129. })
  130. } else wx.showToast({
  131. title: '请重启小程序',
  132. icon: "error"
  133. })
  134. },
  135. data,
  136. fail: function (err) {
  137. wx.showToast({
  138. title: '请重启小程序',
  139. icon: "error"
  140. })
  141. },
  142. complete: function (res) { }
  143. })
  144. },
  145. getPing: function (data) {
  146. const _this = this;
  147. /**
  148. * @description
  149. * data
  150. * topic_name: 聚劲延安
  151. */
  152. wx.request({
  153. url: app.baseUrl + '/platform',
  154. success: function (res) {
  155. if (res.statusCode === 200) {
  156. let contrast = res.data && res.data.length ? [res.data] : [];
  157. let oldContrast = JSON.stringify(_this.data.contrast);
  158. let newContrast = JSON.stringify(contrast);
  159. if (oldContrast != newContrast)
  160. _this.setData({
  161. contrast
  162. })
  163. } else wx.showToast({
  164. title: '请重启小程序',
  165. icon: "error"
  166. })
  167. },
  168. data,
  169. fail: function (err) {
  170. _this.setData({
  171. error: '数据错误'
  172. })
  173. },
  174. complete: function (res) { }
  175. })
  176. },
  177. getAccount: function (data) {
  178. const _this = this;
  179. /**
  180. * @description
  181. * data
  182. * topic_name: 聚劲延安
  183. */
  184. wx.request({
  185. url: app.baseUrl + '/name',
  186. success: function (res) {
  187. if (res.statusCode === 200) {
  188. let list = res.data && res.data.length ? [res.data] : [];
  189. const setD = {};
  190. let isIntUser = {};
  191. let user = {
  192. 'pv': { name: '浏览', type: 'pv' },
  193. 'digg_count': { name: '点赞', type: 'digg_count' },
  194. 'comment_count': { name: '评论', type: 'comment_count' },
  195. 'forward_count': { name: '转发', type: 'forward_count' }
  196. };
  197. let userSort = [];
  198. (res.data || []).map(v => {
  199. !isIntUser.pv && v.pv && userSort.push(user.pv) && (isIntUser.pv = true);
  200. !isIntUser.digg_count && v.digg_count && userSort.push(user.digg_count) && (isIntUser.digg_count = true);
  201. !isIntUser.comment_count && v.comment_count && userSort.push(user.comment_count) && (isIntUser.comment_count = true);
  202. !isIntUser.forward_count && v.forward_count && userSort.push(user.forward_count) && (isIntUser.forward_count = true);
  203. })
  204. if (userSort.length) {
  205. setD[data.type] = list;
  206. setD.userSort = userSort;
  207. } else {
  208. setD[data.type] = [];
  209. setD.userSort = [];
  210. }
  211. let oldType = JSON.stringify(_this.data[data.type]);
  212. let newType = JSON.stringify(list);
  213. if (oldType != newType)
  214. _this.setData(setD)
  215. } else wx.showToast({
  216. title: '请重启小程序',
  217. icon: "error"
  218. })
  219. },
  220. data,
  221. fail: function (err) {
  222. _this.setData({
  223. error: '数据错误'
  224. })
  225. },
  226. complete: function (res) { }
  227. })
  228. },
  229. getWorld: function (data) {
  230. const _this = this;
  231. /**
  232. * @description
  233. * data
  234. * topic_name: 聚劲延安
  235. */
  236. wx.request({
  237. url: this.data.jsonURL,
  238. success: function (res) {
  239. if (res.statusCode === 200) {
  240. _this.setData({
  241. wordList: res.data || []
  242. })
  243. } else wx.showToast({
  244. title: '请重启小程序',
  245. icon: "error"
  246. })
  247. },
  248. data,
  249. fail: function (err) {
  250. _this.setData({
  251. error: '数据错误'
  252. })
  253. },
  254. complete: function (res) { }
  255. })
  256. },
  257. getWeibo: function (data, type) {
  258. const _this = this;
  259. /**
  260. * @description
  261. * data
  262. * topic_name: 聚劲延安
  263. */
  264. wx.request({
  265. url: app.baseUrl + '/time/v2',
  266. success: function (res) {
  267. if (res.statusCode === 200) {
  268. let server = res && res.data ? res.data : {};
  269. let p = {};
  270. let weiboBtn = {
  271. '6m': { name: '1小时', type: '6m' },
  272. '24h': { name: '24小时', type: '24h' },
  273. '7d': { name: '7天', type: '7d' },
  274. '30d': { name: '30天', type: '30d' },
  275. }
  276. if (type) {
  277. p["weibo" + type] = server[_this.data['select' + type]][type] || [];
  278. p["weiboBtnList" + type] = [];
  279. } else {
  280. p["weiboBtnListread"] = [];
  281. p["weiboBtnListme"] = [];
  282. p["weiboBtnListori"] = [];
  283. let pOri = server[_this.data['selectori']] || {};
  284. p.weiboori = pOri.ori || [];
  285. p.weiboread = pOri.read || [];
  286. p.weibome = pOri.me || [];
  287. }
  288. for (const key in weiboBtn) {
  289. if (weiboBtn.hasOwnProperty(key)) {
  290. const element = weiboBtn[key];
  291. if (type) {
  292. server[key] && server[key][type] && p["weiboBtnList" + type].push(element);
  293. } else {
  294. server[key] && server[key].read && p.weiboBtnListread.push(element);
  295. server[key] && server[key].me && p.weiboBtnListme.push(element);
  296. server[key] && server[key].ori && p.weiboBtnListori.push(element);
  297. }
  298. }
  299. }
  300. _this.setData(p)
  301. } else wx.showToast({
  302. title: '请重启小程序',
  303. icon: "error"
  304. })
  305. },
  306. data,
  307. fail: function (err) {
  308. _this.setData({
  309. error: '数据错误'
  310. })
  311. },
  312. complete: function (res) { }
  313. })
  314. },
  315. imgLoad: function (e) {
  316. var img_ratio = e.detail.height / e.detail.width;
  317. var rWidth = wx.getSystemInfoSync().windowWidth;
  318. rWidth > 441 && (rWidth = 441)
  319. this.setData({
  320. height: (rWidth * img_ratio).toFixed(0) - 0
  321. })
  322. },
  323. toSecond: function () {
  324. if (!toUrl) return;
  325. toUrl = false;
  326. let asciiList = encodeURIComponent(JSON.stringify(this.data.sonList));
  327. let title = encodeURIComponent(this.data.title);
  328. wx.navigateTo({
  329. url: "/pages/sonTopic/sonTopic?sonList=" + asciiList + "&title=" + title + "&type=" + this.data.type,
  330. complete: function (res) {
  331. toUrl = true;
  332. }
  333. })
  334. },
  335. showDetail: function (e) {
  336. let introduce = e.currentTarget.dataset.introduce || "";
  337. let detail = app.introduce[this.data.title + "_" + introduce] || {}
  338. console.log(introduce,this)
  339. this.setData({
  340. detail: (detail.value || ""),
  341. diglogTitle: (detail.content_desc || "")
  342. })
  343. }
  344. }
  345. })
  346. /**
  347. * 总浏览量:抖音,快手等平台浏览数总和。
  348. * 总点赞数:抖音,快手等平台点赞数总和。
  349. * 总转发量:抖音,快手等平台转发数总和。
  350. * 直播点赞数:抖音,快手等平台直播场次点赞总和。
  351. * 原创量:抖音,快手等平台原创数总和。
  352. * 总评论数:抖音,快手等平台评论数总和。
  353. * 直播观看人数:抖音,快手等平台直播场次观看人数总和。
  354. * 直播评论数:抖音,快手等平台直播场次直播评论数总和。
  355. */