topic.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 list = [];
  157. for (let i = 0; i < (res.data || []).length; i++) {
  158. const v = (res.data || [])[i];
  159. list.push({
  160. value: v.total_pv,
  161. name: v.platform
  162. })
  163. }
  164. let contrast = [
  165. {
  166. type: 'pie',
  167. radius: ['0%', '50%'],
  168. label: {
  169. position: "outside",
  170. formatter: '{b}\n{d}% ',
  171. },
  172. data: list,
  173. emphasis: {
  174. itemStyle: {
  175. shadowBlur: 10,
  176. shadowOffsetX: 0,
  177. shadowColor: 'rgba(0, 0, 0, 0.5)'
  178. }
  179. }
  180. }
  181. ];
  182. _this.setData({
  183. contrast
  184. })
  185. } else wx.showToast({
  186. title: '请重启小程序',
  187. icon: "error"
  188. })
  189. },
  190. data,
  191. fail: function (err) {
  192. _this.setData({
  193. error: '数据错误'
  194. })
  195. },
  196. complete: function (res) { }
  197. })
  198. },
  199. getAccount: function (data) {
  200. const _this = this;
  201. /**
  202. * @description
  203. * data
  204. * topic_name: 聚劲延安
  205. */
  206. wx.request({
  207. url: app.baseUrl + '/name',
  208. success: function (res) {
  209. if (res.statusCode === 200) {
  210. let list = res.data && res.data.length ? [res.data] : [];
  211. const setD = {};
  212. let isIntUser = {};
  213. let user = {
  214. 'pv': { name: '浏览', type: 'pv' },
  215. 'digg_count': { name: '点赞', type: 'digg_count' },
  216. 'comment_count': { name: '评论', type: 'comment_count' },
  217. 'forward_count': { name: '转发', type: 'forward_count' }
  218. };
  219. let userSort = [];
  220. (res.data || []).map(v => {
  221. !isIntUser.pv && v.pv && userSort.push(user.pv) && (isIntUser.pv = true);
  222. !isIntUser.digg_count && v.digg_count && userSort.push(user.digg_count) && (isIntUser.digg_count = true);
  223. !isIntUser.comment_count && v.comment_count && userSort.push(user.comment_count) && (isIntUser.comment_count = true);
  224. !isIntUser.forward_count && v.forward_count && userSort.push(user.forward_count) && (isIntUser.forward_count = true);
  225. })
  226. if (userSort.length) {
  227. setD[data.type] = list;
  228. setD.userSort = userSort;
  229. } else {
  230. setD[data.type] = [];
  231. setD.userSort = [];
  232. }
  233. let oldType = JSON.stringify(_this.data[data.type]);
  234. let newType = JSON.stringify(list);
  235. if (oldType != newType)
  236. _this.setData(setD)
  237. } else wx.showToast({
  238. title: '请重启小程序',
  239. icon: "error"
  240. })
  241. },
  242. data,
  243. fail: function (err) {
  244. _this.setData({
  245. error: '数据错误'
  246. })
  247. },
  248. complete: function (res) { }
  249. })
  250. },
  251. getWorld: function (data) {
  252. const _this = this;
  253. /**
  254. * @description
  255. * data
  256. * topic_name: 聚劲延安
  257. */
  258. wx.request({
  259. url: this.data.jsonURL,
  260. success: function (res) {
  261. if (res.statusCode === 200) {
  262. _this.setData({
  263. wordList: res.data || []
  264. })
  265. } else wx.showToast({
  266. title: '请重启小程序',
  267. icon: "error"
  268. })
  269. },
  270. data,
  271. fail: function (err) {
  272. _this.setData({
  273. error: '数据错误'
  274. })
  275. },
  276. complete: function (res) { }
  277. })
  278. },
  279. getWeibo: function (data, type) {
  280. const _this = this;
  281. /**
  282. * @description
  283. * data
  284. * topic_name: 聚劲延安
  285. */
  286. wx.request({
  287. url: app.baseUrl + '/time/v2',
  288. success: function (res) {
  289. if (res.statusCode === 200) {
  290. let server = res && res.data ? res.data : {};
  291. let p = {};
  292. let weiboBtn = {
  293. '6m': { name: '1小时', type: '6m' },
  294. '24h': { name: '24小时', type: '24h' },
  295. '7d': { name: '7天', type: '7d' },
  296. '30d': { name: '30天', type: '30d' },
  297. }
  298. if (type) {
  299. p["weibo" + type] = server[_this.data['select' + type]][type] || [];
  300. p["weiboBtnList" + type] = [];
  301. } else {
  302. p["weiboBtnListread"] = [];
  303. p["weiboBtnListme"] = [];
  304. p["weiboBtnListori"] = [];
  305. let pOri = server[_this.data['selectori']] || {};
  306. p.weiboori = pOri.ori || [];
  307. p.weiboread = pOri.read || [];
  308. p.weibome = pOri.me || [];
  309. }
  310. for (const key in weiboBtn) {
  311. if (weiboBtn.hasOwnProperty(key)) {
  312. const element = weiboBtn[key];
  313. if (type) {
  314. server[key] && server[key][type] && p["weiboBtnList" + type].push(element);
  315. } else {
  316. server[key] && server[key].read && p.weiboBtnListread.push(element);
  317. server[key] && server[key].me && p.weiboBtnListme.push(element);
  318. server[key] && server[key].ori && p.weiboBtnListori.push(element);
  319. }
  320. }
  321. }
  322. _this.setData(p)
  323. } else wx.showToast({
  324. title: '请重启小程序',
  325. icon: "error"
  326. })
  327. },
  328. data,
  329. fail: function (err) {
  330. _this.setData({
  331. error: '数据错误'
  332. })
  333. },
  334. complete: function (res) { }
  335. })
  336. },
  337. imgLoad: function (e) {
  338. var img_ratio = e.detail.height / e.detail.width;
  339. var rWidth = wx.getSystemInfoSync().windowWidth;
  340. rWidth > 441 && (rWidth = 441)
  341. this.setData({
  342. height: (rWidth * img_ratio).toFixed(0) - 0
  343. })
  344. },
  345. toSecond: function () {
  346. if (!toUrl) return;
  347. toUrl = false;
  348. let asciiList = encodeURIComponent(JSON.stringify(this.data.sonList));
  349. let title = encodeURIComponent(this.data.title);
  350. wx.navigateTo({
  351. url: "/pages/sonTopic/sonTopic?sonList=" + asciiList + "&title=" + title + "&type=" + this.data.type,
  352. complete: function (res) {
  353. toUrl = true;
  354. }
  355. })
  356. },
  357. toLive: function (e) {
  358. if (!toUrl) return;
  359. toUrl = false;
  360. let title = this.data.title;
  361. let url = "/pages/live/live?title=" + title + "&season=" + (this.data.select - 0 + 1) + "&isdou=" + this.data.headData.has_live_douyin_data + "&iskuai=" + this.data.headData.has_live_kuaishou_data;
  362. wx.navigateTo({
  363. url,
  364. complete: function (res) {
  365. toUrl = true;
  366. }
  367. })
  368. },
  369. showDetail: function (e) {
  370. let introduce = e.currentTarget.dataset.introduce || "";
  371. let detail = app.introduce[this.data.title + "_" + introduce] || {}
  372. this.setData({
  373. detail: (detail.value || ""),
  374. diglogTitle: (detail.content_desc || "")
  375. })
  376. }
  377. }
  378. })