topic.js 11 KB

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